Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: storage: shuttle_usbat: reject oversized device-reported read length
@ 2026-12-02  2:44 Artem Dinaburg
  2026-12-02  2:49 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Artem Dinaburg @ 2026-12-02  2:44 UTC (permalink / raw)
  To: stern, gregkh
  Cc: lihaofeng, 13266079573, linux-usb, usb-storage, linux-kernel

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@kylinos.cn>
Closes: https://lore.kernel.org/r/20260822194728.4151923-1-lihaofeng@kylinos.cn
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Artem Dinaburg <artem@trailofbits.com>
---
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@rowland.harvard.edu

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02  2:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  2:44 [PATCH] usb: storage: shuttle_usbat: reject oversized device-reported read length Artem Dinaburg
2026-12-02  2:49 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox