Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Artem Dinaburg" <artem@trailofbits.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: storage: shuttle_usbat: reject oversized device-reported read length
Date: Wed, 02 Dec 2026 02:49:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-244723@kernel.org> (raw)
In-Reply-To: <20261202024441.52639-1-artem@trailofbits.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] usb: storage: wrong READ CD length unpacking in
  usbat_hp8200e_handle_read10() [1]
--

commit 93bfef65f8b31cbe01134b79df0424fc0e66a02f
Author: Artem Dinaburg <artem@trailofbits.com>

usb: storage: shuttle_usbat: reject oversized device-reported read length

This commit rejects device-to-host read transfers in
usbat_hp8200e_transport() when the response length reported by the device's
ATA LBA_ME and LBA_HI registers exceeds scsi_bufflen(srb).

> diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
> index 563a2beeeb44a..35129e82612c9 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));

[Severity: High]
This problem wasn't introduced by this patch, but does
usbat_hp8200e_handle_read10() unpack the wrong CDB bytes when computing the
transfer length in blocks for GPCMD_READ_CD [1]?

When usbat_hp8200e_transport() handles GPCMD_READ_CD with a transfer buffer of
at least 64 KiB, usbat_hp8200e_handle_read10() computes len from data[7..18]
(which holds the 12-byte CDB):

drivers/usb/storage/shuttle_usbat.c:usbat_hp8200e_handle_read10() {
	...
	if (data[7+0] == GPCMD_READ_CD) {
		len = short_pack(data[7+9], data[7+8]);
		len <<= 16;
		len |= data[7+7];
		usb_stor_dbg(us, "GPCMD_READ_CD: len %d\n", len);
		srb->transfersize = len ? scsi_bufflen(srb) / len : 0;
	}
	...
}

For GPCMD_READ_CD, the 24-bit big-endian transfer length in blocks is in CDB
bytes 6..8 (data[7+6..7+8]), while CDB byte 9 (data[7+9]) holds the sector and
header selection flags (such as 0xf8 for 2352-byte raw CDDA frames).  Because
short_pack(LSB, MSB) puts its first argument in the low byte, this expression
evaluates to (srb->cmnd[8] << 24) | (srb->cmnd[9] << 16) | srb->cmnd[7],
ignoring srb->cmnd[6] and shifting in the flags byte.

When srb->cmnd[9] is non-zero, len is inflated so scsi_bufflen(srb) / len
becomes 0, forcing srb->transfersize to the 2048-byte fallback and
miscomputing both the per-chunk byte count and the rewritten CDB sector count.

[1] https://sashiko.dev/#/bug/linux-9aacd68e-51b6-463a-88fe-003733a49838

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202024441.52639-1-artem@trailofbits.com?part=1

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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=sashiko-outbox-244723@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=artem@trailofbits.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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