[PATCH v4 0/3] usb: core: Fix three use-after-free windows in the USB anchor protocol

From: Hongyu Xie

Date: Wed Dec 02 2026 - 19:48:45 EST


This series closes three use-after-free windows in the USB anchor
teardown and URB giveback protocol:

1. Serialize usb_anchor_check_wakeup() and usb_anchor_resume_wakeups()
under anchor->lock so a waiter cannot observe the anchor unused and
free it while a giveback still touches anchor->wait.
2. Atomically re-check urb->anchor, increment anchor->suspend_wakeups,
and unanchor the URB under anchor->lock during URB giveback via
usb_unanchor_urb_and_suspend_wakeups().
3. Protect lockless urb->anchor readers with contention-gated RCU and
replace busy-waiting in kill/poison/scuttle drains with wait_event().

Changes since v3:
- Use guard(spinlock_irqsave), scoped_guard(), and guard(rcu)() in
drivers/usb/core/urb.c.
- Annotate __usb_anchor_check_wakeup(), __usb_anchor_prepare_rcu_gp(),
and __usb_unanchor_urb() with __must_hold(&anchor->lock) and
lockdep_assert_held(&anchor->lock).
- Shorten comments and rewrite all commit messages concisely per review.

v3: https://lore.kernel.org/r/179578612505.44635.14553263875690325600@xxxxxxxxxx
v3 review: https://lore.kernel.org/all/2026112752-comic-stream-65a3@gregkh/

Hongyu Xie (3):
usb: core: Fix use-after-free in anchor wakeup protocol
usb: core: Close anchor capture-to-increment race in URB giveback
usb: core: Close residual anchor read-to-lock window with RCU

Documentation/driver-api/usb/anchors.rst | 14 +-
drivers/usb/core/hcd.c | 5 +-
drivers/usb/core/urb.c | 305 +++++++++++++++++++----
drivers/usb/core/usb.h | 1 +
include/linux/usb.h | 8 +-
5 files changed, 276 insertions(+), 57 deletions(-)


base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.32.0