From: Keisuke Tsukuda <tkdkei@outlook.jp>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Sven Peter <sven@kernel.org>, Janne Grunau <j@jannau.net>,
Neal Gompa <neal@gompa.dev>,
Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
"asahi@lists.linux.dev" <asahi@lists.linux.dev>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 0/2] usb: roles: wait for callbacks during unregister
Date: Tue, 17 Nov 2026 12:59:17 +0000 [thread overview]
Message-ID: <20261117125825.27629-1-tkdkei@outlook.jp> (raw)
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(-)
next reply other threads:[~2026-11-17 12:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 12:59 Keisuke Tsukuda [this message]
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
2026-11-20 13:23 ` Heikki Krogerus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117125825.27629-1-tkdkei@outlook.jp \
--to=tkdkei@outlook.jp \
--cc=Thinh.Nguyen@synopsys.com \
--cc=asahi@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=j@jannau.net \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=neal@gompa.dev \
--cc=sven@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®