From: Vineet Thakran <vineet789thakran@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Neill Kapron <nkapron@google.com>
Cc: Ruslan Bilovol <ruslan.bilovol@gmail.com>,
Pavel Hofman <pavel.hofman@ivitera.com>,
linux-usb@vger.kernel.org,
Vineet Thakran <vineet789thakran@gmail.com>
Subject: [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances
Date: Sat, 5 Dec 2026 11:08:25 +0000 [thread overview]
Message-ID: <20261205110831.204588-1-vineet789thakran@gmail.com> (raw)
f_uac1 and f_uac2 keep the dynamically allocated feature unit (and, in
f_uac1, AC header) descriptors in file-scope pointers shared by all
instances. With more than one instance this leaks descriptors on every
bind (reported by syzbot for f_uac2), and once one instance unbinds, a
feature unit control request to any other bound instance dereferences
a NULL pointer. Binds of gadgets on different UDCs are also not
serialized, so they race on these shared descriptors.
Patches 1 and 4 make the control request handlers use the unit IDs
already stored per instance. Patches 2 and 5 serialize bind with a
file-scope mutex, as f_midi2 does. Patches 3 and 6 then free the
descriptors at the end of bind, as usb_assign_descriptors() has copied
them by then; in f_uac1 they also become local variables of
f_audio_bind().
The mutex patches use guard() and scoped_guard(), so older stable trees
will need a manual backport of them.
Testing (next-20261127, arm64 QEMU, usbip-vudc as UDC):
- syzbot's C reproducer (kmemleak on): reports the build_fu_desc leak
before the series; runs for 180 s without any leak after it.
- Two uac2 and two uac1 instances in one config, bound/unbound for
3 cycles: kmemleak reports 10 leaked objects before the series and
none after.
- Two gadgets on two vudc instances, unbinding the first and attaching
the second to vhci-hcd: both drivers oops on the first feature unit
control request before the series. After it, snd-usb-audio enumerates
the device and creates all volume/mute controls.
- Two gadgets on two vudc instances bound and unbound in parallel
loops, 300 iterations each, on 2 CPUs with KASAN and PROVE_LOCKING:
before the series, KASAN reports a double-free in afunc_unbind()
(uac2) and a slab-use-after-free in f_audio_bind() (uac1). With the
series, there are no KASAN or lockdep reports.
Changes in v2:
- Add patches 2 and 5 to serialize bind with a mutex (Sashiko)
- Patch 6: make the f_uac1 AC header and feature unit descriptors local
variables of f_audio_bind() (Sashiko)
- Link to v1: https://lore.kernel.org/linux-usb/20261203193217.465889-1-vineet789thakran@gmail.com/
Vineet Thakran (6):
usb: gadget: f_uac2: use per-instance feature unit IDs in control
requests
usb: gadget: f_uac2: serialize bind with a mutex
usb: gadget: f_uac2: fix feature unit descriptor leak
usb: gadget: f_uac1: use per-instance feature unit IDs in control
requests
usb: gadget: f_uac1: serialize bind with a mutex
usb: gadget: f_uac1: fix feature unit and AC header descriptor leak
drivers/usb/gadget/function/f_uac1.c | 116 +++++++++++++--------------
drivers/usb/gadget/function/f_uac2.c | 89 ++++++++++----------
2 files changed, 103 insertions(+), 102 deletions(-)
base-commit: e5aad2bdbbee783611d32599f89cea3f12f9593d
--
2.43.0
next reply other threads:[~2026-12-05 11:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 11:08 Vineet Thakran [this message]
2026-12-05 11:08 ` [PATCH v2 1/6] usb: gadget: f_uac2: use per-instance feature unit IDs in control requests Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 2/6] usb: gadget: f_uac2: serialize bind with a mutex Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 3/6] usb: gadget: f_uac2: fix feature unit descriptor leak Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 4/6] usb: gadget: f_uac1: use per-instance feature unit IDs in control requests Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 5/6] usb: gadget: f_uac1: serialize bind with a mutex Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 6/6] usb: gadget: f_uac1: fix feature unit and AC header descriptor leak Vineet Thakran
2026-12-05 11:20 ` sashiko-bot
2026-12-05 11:24 ` [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances sashiko-bot
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=20261205110831.204588-1-vineet789thakran@gmail.com \
--to=vineet789thakran@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkapron@google.com \
--cc=pavel.hofman@ivitera.com \
--cc=ruslan.bilovol@gmail.com \
/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