Linux USB
 help / color / mirror / Atom feed
From: Artem Dinaburg <artem@trailofbits.com>
To: stern@rowland.harvard.edu, gregkh@linuxfoundation.org
Cc: lihaofeng@kylinos.cn, 13266079573@163.com,
	linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net,
	linux-kernel@vger.kernel.org
Subject: [PATCH] usb: storage: shuttle_usbat: reject oversized device-reported read length
Date: Tue,  1 Dec 2026 21:44:41 -0500	[thread overview]
Message-ID: <20261202024441.52639-1-artem@trailofbits.com> (raw)

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


             reply	other threads:[~2026-12-02  2:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  2:44 Artem Dinaburg [this message]
2026-12-02  2:49 ` [PATCH] usb: storage: shuttle_usbat: reject oversized device-reported read length sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202024441.52639-1-artem@trailofbits.com \
    --to=artem@trailofbits.com \
    --cc=13266079573@163.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=lihaofeng@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=usb-storage@lists.one-eyed-alien.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox