[PATCH v9 1/3] usb: gadget: f_tcm: zero the CBW buffer the status path sends
From: Yehyeong Lee
Date: Fri Nov 20 2026 - 12:28:56 EST
bot_prepare_reqs() allocates fu->cmd[0].buf with kmalloc(), one endpoint
maxpacket in size, and the only thing ever written into it is the 31-byte
CBW the host sends. The rest is never initialised.
When a command is rejected before its data stage, bot_send_bad_status()
points the status request at that same buffer and queues it to the IN
endpoint for a read, and bot_err_compl() re-queues it until the length the
host declared in the CBW is satisfied. So the host gets the buffer's
contents back, a maxpacket at a time, for as long a transfer as it asked
for, and whatever lies past the CBW it never wrote.
Allocate it with kzalloc().
Fixes: c52661d60f63 ("usb-gadget: Initial merge of target module for UASP + BOT")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Yehyeong Lee <yhlee@xxxxxxxxxxxxxxxxxx>
---
v9: move the credit line and the Link out of the changelog (Greg).
The same change was part of Hui Peng's multi-driver patch of 2026-09-19,
which was asked to be split per driver and was not applied:
https://lore.kernel.org/all/20260919223521.3890508-1-benquike@xxxxxxxxx/
On a dummy_hcd gadget with a 512-byte bulk maxpacket, a rejected IN
command declaring 4096 bytes returns 4096 bytes to the host, of which 72
are non-zero and begin with the previous CBW's "USBC" signature. The part
no CBW ever writes read back as zero there, both before and after this
patch, so what that buffer held beforehand was not observed; what the test
does show is that the host is handed a buffer it only ever wrote 31 bytes
of.
drivers/usb/gadget/function/f_tcm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c
index 3af28419a8bca9..22e57f14e938e7 100644
--- a/drivers/usb/gadget/function/f_tcm.c
+++ b/drivers/usb/gadget/function/f_tcm.c
@@ -330,7 +330,7 @@ static int bot_prepare_reqs(struct f_uas *fu)
fu->bot_status.req->complete = bot_status_complete;
fu->bot_status.csw.Signature = cpu_to_le32(US_BULK_CS_SIGN);
- fu->cmd[0].buf = kmalloc(fu->ep_out->maxpacket, GFP_KERNEL);
+ fu->cmd[0].buf = kzalloc(fu->ep_out->maxpacket, GFP_KERNEL);
if (!fu->cmd[0].buf)
goto err_buf;
--
2.43.0