Linux USB
 help / color / mirror / Atom feed
* [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances
@ 2026-12-05 11:08 Vineet Thakran
  2026-12-05 11:08 ` [PATCH v2 1/6] usb: gadget: f_uac2: use per-instance feature unit IDs in control requests Vineet Thakran
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Vineet Thakran @ 2026-12-05 11:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Neill Kapron
  Cc: Ruslan Bilovol, Pavel Hofman, linux-usb, Vineet Thakran

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


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

end of thread, other threads:[~2026-12-05 11:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 11:08 [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances Vineet Thakran
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

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