Re: [PATCH] usb: core: hcd: cancel giveback work synchronously on stop
From: Alan Stern
Date: Fri Oct 23 2026 - 15:17:12 EST
On Fri, Oct 23, 2026 at 08:40:15PM +0300, Igor Putko wrote:
> When an HCD is stopped/removed (either during module unload, driver
> unbind, or an error path in probe), pending URBs are unlinked and
> completed. However, for root hubs or HCDs with giveback done in BH
> context, the work function usb_giveback_urb_bh() may still be executing
> on another CPU after __usb_hcd_giveback_urb() finishes.
>
> Since the caller may immediately free the struct usb_hcd via usb_put_hcd()
> after usb_stop_hcd() or usb_remove_hcd(), the running worker accesses
> the embedded giveback_urb_bh structure after it has been freed,
> triggering a slab-use-after-free write detected by KASAN.
>
> Ensure all giveback work is fully flushed and cancelled in usb_stop_hcd()
> by calling cancel_work_sync() on both high and low priority BHs.
Sashiko's criticism has a point. If there are any URBs still pending on
either of the BH lists when usb_stop_hcd() returns, something is already
badly wrong -- that's never supposed to happen. Whatever it is, it
needs to be fixed in the driver that submitted the pending URB, not here
in usb_stop_hcd().
Alan Stern