linux/drivers/usb
Kai Aizen 68aa70648b usb: gadget: uvc: hold opts->lock across XU walks in uvc_function_bind
uvc_function_bind() walks &opts->extension_units twice without holding
opts->lock:

  - directly, for the iExtension string-descriptor fixup loop;
  - indirectly, four times via uvc_copy_descriptors() (once per speed),
    where the helper iterates uvc->desc.extension_units (which aliases
    &opts->extension_units) to size and emit XU descriptors.

The configfs side (uvcg_extension_make / uvcg_extension_drop, in
drivers/usb/gadget/function/uvc_configfs.c) takes opts->lock around its
list_add_tail / list_del operations.  A privileged userspace process
that holds the configfs subtree open and writes the gadget UDC name
to bind the function while concurrently rmdir()'ing an extensions
subdir can race uvcg_extension_drop() against the bind-time list walks
and dereference a freed struct uvcg_extension.

Hold opts->lock from the start of the XU string-descriptor fixup
through the last uvc_copy_descriptors() call, releasing on the
descriptor-error path via a new error_unlock label that drops the
lock before falling through to the existing error label.  This
matches the locking discipline of the configfs callbacks and removes
the only remaining unsynchronised reader of the XU list during bind.

Reachability: only privileged processes that can mount configfs and
write to gadget UDC files can trigger the race, so this is a
correctness fix rather than a security boundary.

Fixes: 0525210c98 ("usb: gadget: uvc: Allow definition of XUs in configfs")
Cc: stable <stable@kernel.org>
Signed-off-by: Kai Aizen <kai.aizen.dev@gmail.com>
Link: https://patch.msgid.link/20260430175643.67120-1-kai.aizen.dev@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-05-22 10:35:36 +02:00
..
atm Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
c67x00 Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
cdns3 usb: cdns3: gadget: fix request skipping after clearing halt 2026-05-21 16:56:29 +02:00
chipidea usb: chipidea: otg: not wait vbus drop if use role_switch 2026-04-07 13:46:54 +02:00
class usb: usblp: fix uninitialized heap leak via LPGETSTATUS ioctl 2026-04-27 10:00:18 -06:00
common usb: ulpi: fix memory leak on ulpi_register() error paths 2026-04-27 09:49:43 -06:00
core usb: core: Clean up SuperSpeed/eUSB2 descriptor validation logging 2026-05-18 15:16:58 +02:00
dwc2 usb: dwc2: gadget: Fix spin_lock/unlock mismatch in dwc2_hsotg_udc_stop() 2026-03-30 17:05:07 +02:00
dwc3 usb: dwc3: xilinx: fix error handling in zynqmp init error paths 2026-05-21 16:40:50 +02:00
early usb: early: xhci-dbc: Fix early_ioremap leak 2025-07-07 11:04:46 +02:00
fotg210 Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
gadget usb: gadget: uvc: hold opts->lock across XU walks in uvc_function_bind 2026-05-22 10:35:36 +02:00
host drivers/usb/host: Fix spelling error 'seperate' -> 'separate' 2026-04-11 12:02:11 +02:00
image Merge 7.0-rc4 into usb-next 2026-03-16 11:50:48 +01:00
isp1760 Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
misc Linux 7.0-rc7 2026-04-06 09:06:39 +02:00
mon Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
mtu3 Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
musb usb: musb: omap2430: Fix use-after-free in omap2430_probe() 2026-05-22 10:33:43 +02:00
phy Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
renesas_usbhs usb: renesas_usbhs: use kzalloc_flex 2026-03-18 15:51:48 +01:00
roles usb: roles: get usb role switch from parent only for usb-b-connector 2026-03-11 16:22:22 +01:00
serial USB: serial: option: add Telit Cinterion LE910Cx compositions 2026-04-30 10:53:56 +02:00
storage usb: storage: Expand range of matched versions for VL817 quirks entry 2026-04-07 13:47:23 +02:00
typec usb: typec: ucsi: Don't update power_supply on power role change if not connected 2026-05-21 16:57:15 +02:00
usbip usbip: validate number_of_packets in usbip_pack_ret_submit() 2026-04-07 13:48:44 +02:00
Kconfig usb: pci-quirks: handle HAS_IOPORT dependency for AMD quirk 2023-10-02 16:19:12 +02:00
Makefile usb: isp1362-hcd: remove Philips ISP1362 USB OTG controller driver 2026-01-07 16:13:19 +01:00
usb-skeleton.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00