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

From: Alan Stern

Date: Tue Dec 01 2026 - 15:43:42 EST


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