Linux USB
 help / color / mirror / Atom feed
* [PATCH v2 0/2] usb: roles: wait for callbacks during unregister
@ 2026-11-17 12:59 Keisuke Tsukuda
  2026-11-17 13:00 ` [PATCH v2 1/2] usb: dwc3: apple: unregister role switch before taking lock Keisuke Tsukuda
  2026-11-17 13:00 ` [PATCH v2 2/2] usb: roles: wait for callbacks on unregister Keisuke Tsukuda
  0 siblings, 2 replies; 5+ messages in thread
From: Keisuke Tsukuda @ 2026-11-17 12:59 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Heikki Krogerus, Sven Peter, Janne Grunau, Neal Gompa,
	Thinh Nguyen, asahi@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org

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@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(-)


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-17 13:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 12:59 [PATCH v2 0/2] usb: roles: wait for callbacks during unregister Keisuke Tsukuda
2026-11-17 13:00 ` [PATCH v2 1/2] usb: dwc3: apple: unregister role switch before taking lock Keisuke Tsukuda
2026-11-17 13:12   ` sashiko-bot
2026-11-17 13:00 ` [PATCH v2 2/2] usb: roles: wait for callbacks on unregister Keisuke Tsukuda
2026-11-17 13:19   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox