Skip to content

Commit 0f18eac

Browse files
Desnes Nunesgregkh
authored andcommitted
usb: storage: Fix memory leak in USB bulk transport
commit 41e99fe upstream. A kernel memory leak was identified by the 'ioctl_sg01' test from Linux Test Project (LTP). The following bytes were mainly observed: 0x53425355. When USB storage devices incorrectly skip the data phase with status data, the code extracts/validates the CSW from the sg buffer, but fails to clear it afterwards. This leaves status protocol data in srb's transfer buffer, such as the US_BULK_CS_SIGN 'USBS' signature observed here. Thus, this can lead to USB protocols leaks to user space through SCSI generic (/dev/sg*) interfaces, such as the one seen here when the LTP test requested 512 KiB. Fix the leak by zeroing the CSW data in srb's transfer buffer immediately after the validation of devices that skip data phase. Note: Differently from CVE-2018-1000204, which fixed a big leak by zero- ing pages at allocation time, this leak occurs after allocation, when USB protocol data is written to already-allocated sg pages. Fixes: a45b599 ("scsi: sg: allocate with __GFP_ZERO in sg_build_indirect()") Cc: stable <stable@kernel.org> Signed-off-by: Desnes Nunes <desnesn@redhat.com> Reviewed-by: Alan Stern <stern@rowland.harvard.edu> Link: https://patch.msgid.link/20251031043436.55929-1-desnesn@redhat.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 26838f1 commit 0f18eac

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

drivers/usb/storage/transport.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,23 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
12041204
US_BULK_CS_WRAP_LEN &&
12051205
bcs->Signature ==
12061206
cpu_to_le32(US_BULK_CS_SIGN)) {
1207+
unsigned char buf[US_BULK_CS_WRAP_LEN];
1208+
12071209
usb_stor_dbg(us, "Device skipped data phase\n");
1210+
1211+
/*
1212+
* Devices skipping data phase might leave CSW data in srb's
1213+
* transfer buffer. Zero it to prevent USB protocol leakage.
1214+
*/
1215+
sg = NULL;
1216+
offset = 0;
1217+
memset(buf, 0, sizeof(buf));
1218+
if (usb_stor_access_xfer_buf(buf,
1219+
US_BULK_CS_WRAP_LEN, srb, &sg,
1220+
&offset, TO_XFER_BUF) !=
1221+
US_BULK_CS_WRAP_LEN)
1222+
usb_stor_dbg(us, "Failed to clear CSW data\n");
1223+
12081224
scsi_set_resid(srb, transfer_length);
12091225
goto skipped_data_phase;
12101226
}

0 commit comments

Comments
 (0)