Re: [PATCH] usb: xhci: reject bulk transfers beyond mapped scatterlists

From: Artem Dinaburg

Date: Tue Dec 01 2026 - 21:24:55 EST


Michal wrote:
> Which one and how exactly?
>
> That's a driver bug, albeit one which could conceivably
> be triggered by a nonconforming device.

Hi Michal,

The driver is shuttle_usbat. For device-to-host commands other than
READ_10 and READ_CD, usbat_hp8200e_transport() reads the response
length from the device's LBA_ME/LBA_HI registers and passes it to
usbat_read_block() without comparing it to scsi_bufflen(srb). A device
that reports 255 bytes for a 36-byte INQUIRY gets usb_sg_init() called
with a length larger than the scatterlist. We are working on a fix for
that driver.

The URB is still invalid, though, and usb_submit_urb() already rejects
other invalid SG URBs (the maxpacket check in that same branch). An URB
whose length exceeds its scatterlist should be rejected there too. Both
the driver and usb_submit_urb() need fixing, so I was going to send the
core check as v2.

Thanks,
Artem Dinaburg

On Tue, Dec 1, 2026 at 4:45 PM Michal Pecio <michal.pecio@xxxxxxxxx> wrote:
>
> On Tue, 1 Dec 2026 15:24:40 -0500, Artem Dinaburg wrote:
> > A bulk or interrupt URB can request more bytes than its mapped
> > scatterlist covers. count_sg_trbs_needed() counts only the mapped
> > entries, but xhci_queue_bulk_tx() queues TRBs until the requested length
> > is reached. After the final entry it continues from the last DMA address
> > and length, so the controller transfers data outside the mapping.
> >
> > A USB device can cause this mismatch.
>
> Which one and how exactly?
>
> That's a driver bug, albeit one which could conceivably
> be triggered by a nonconforming device.
>
> Regards,
> Michal