[PATCH] usb: storage: shuttle_usbat: reject oversized device-reported read length

From: Artem Dinaburg

Date: Tue Dec 01 2026 - 21:44:50 EST


For device-to-host commands other than READ_10 and READ_CD,
usbat_hp8200e_transport() reads the response length from the device's
ATA LBA_ME and LBA_HI registers and passes it to usbat_read_block()
without comparing it to scsi_bufflen(srb). A device that reports more
data than the command buffer holds makes the transfer run past the end
of the buffer.

Fail the command with a transport error in that case instead of reading
the response.

Haofeng Li found this first and posted a patch that clamps the length
instead (see Closes).

Found and fixed with AI assistance.

Reported-by: Haofeng Li <lihaofeng@xxxxxxxxxx>
Closes: https://lore.kernel.org/r/20260822194728.4151923-1-lihaofeng@xxxxxxxxxx
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Artem Dinaburg <artem@xxxxxxxxxxxxxxx>
---
Sent as a new patch with Alan Stern's go-ahead; Haofeng's has had no
replies since August:
https://lore.kernel.org/r/5e690176-2e2c-4166-af06-9a35ff190173@xxxxxxxxxxxxxxxxxxx

Tested on mainline 19cc08c1a6a6 in QEMU (q35, KASAN) with an emulated
HP 8200e: an oversized reported length now fails the command with a
transport error and no oversized bulk-IN is issued; a well-behaved
device still answers INQUIRY, TEST UNIT READY and READ CAPACITY. Built
with W=1 on mainline and usb-next.

drivers/usb/storage/shuttle_usbat.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index 563a2beeeb44..35129e82612c 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -1673,6 +1673,9 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
else
len = *status;

+ /* The device reports the length; don't overrun the buffer */
+ if (len > scsi_bufflen(srb))
+ return USB_STOR_TRANSPORT_ERROR;

result = usbat_read_block(us, scsi_sglist(srb), len,
scsi_sg_count(srb));
--
2.55.0