Re: [PATCH] usb: xhci: reject bulk transfers beyond mapped scatterlists
From: Artem Dinaburg
Date: Tue Dec 01 2026 - 15:54:58 EST
Hi Alan,
Thanks for the quick review!
You're right, usb_submit_urb() is a better place for this check, and
it covers every HCD instead of just xHCI. I'll prepare and test a v2
patch that moves the check there.
Thanks,
Artem Dinaburg
On Tue, Dec 1, 2026 at 3:43 PM Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote:
>
> On Tue, Dec 01, 2026 at 03:24:40PM -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.
> >
> > Reject the mismatch in the existing counting pass, before
> > prepare_transfer() changes the ring. This also rejects an SG URB with no
> > mapped entries.
>
> Why are you trying to fix this by modifying the xhci-hcd driver? In
> theory the same thing could happen to any HCD.
>
> This possible error should be handled in the USB core, in
> usb_submit_urb(). That routine already has a section specifically for
> checking transfers that use scatter-gather; it's the perfect place to
> add your check.
>
> Alan Stern