[PATCH v2 0/2] usb: roles: wait for callbacks during unregister
Keisuke Tsukuda
tkdkei at outlook.jp
Tue Nov 17 04:59:17 PST 2026
A role-switch provider can be unregistered while a set/get callback is
running. The core checks the registered flag before taking the switch lock
and clears it without taking that lock, so unregister can return while the
callback still uses provider-owned memory. A synthetic provider reproduces
use-after-free reports in both callback paths with KASAN.
The core fix makes unregister wait for callbacks on the switch lock. The
Apple DWC3 role callbacks take a private lock under the switch lock, while
its remove path currently holds the private lock around unregister. Patch 1
moves Apple's unregister call ahead of that lock; patch 2 adds the core
synchronization. This order keeps intermediate states free of the new lock
inversion.
On ARM64 QEMU with Linux 7.3.4 and mainline 7.4-rc2 (067c5c24cef2),
KASAN reported use-after-free in set and get callbacks before the change.
After both patches, unregister waited for the callbacks and neither test
reported KASAN. A lockdep test modeling Apple's callback/remove lock order
warned for the original order and not for the new one. Apple DWC3 hardware
was not tested.
Changes in v2:
- Split the Apple lock-order change and the role-switch core fix into two
patches, with the Apple change first, as requested by Heikki Krogerus.
- Add Cc: stable at vger.kernel.org tags to both patch descriptions.
Thanks for the review, Heikki.
v1: https://lore.kernel.org/r/20261112024101.83321-1-tkdkei@outlook.jp
Keisuke Tsukuda (2):
usb: dwc3: apple: unregister role switch before taking lock
usb: roles: wait for callbacks on unregister
---
drivers/usb/dwc3/dwc3-apple.c | 4 ++--
drivers/usb/roles/class.c | 18 ++++++++++++++----
2 files changed, 16 insertions(+), 6 deletions(-)
More information about the linux-arm-kernel
mailing list