usb: early: xhci-dbc: Fix a potential out-of-bound memory access

[ Upstream commit a4a97ab3db ]

If xdbc_bulk_write() fails, the values in 'buf' can be anything. So the
string is not guaranteed to be NULL terminated when xdbc_trace() is called.

Reserve an extra byte, which will be zeroed automatically because 'buf' is
a static variable, in order to avoid troubles, should it happen.

Fixes: aeb9dd1de9 ("usb/early: Add driver for xhci debug capability")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/d6a7562c5e839a195cee85db6dc81817f9372cb1.1675016180.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Christophe JAILLET 2023-01-29 19:23:08 +01:00 committed by Greg Kroah-Hartman
parent c169890b5f
commit 351c8d8650
1 changed files with 2 additions and 1 deletions

View File

@ -874,7 +874,8 @@ static int xdbc_bulk_write(const char *bytes, int size)
static void early_xdbc_write(struct console *con, const char *str, u32 n) static void early_xdbc_write(struct console *con, const char *str, u32 n)
{ {
static char buf[XDBC_MAX_PACKET]; /* static variables are zeroed, so buf is always NULL terminated */
static char buf[XDBC_MAX_PACKET + 1];
int chunk, ret; int chunk, ret;
int use_cr = 0; int use_cr = 0;