linux/drivers/usb/core
Miguel Peñaranda 0dd68b5d01 usb: usbfs: fix use-after-free of usb_device in usbdev_release()
usbdev_release() drops its reference to the struct usb_device before
draining the list of completed async URBs, but that drain path reads back
through the same object: free_async() calls dec_usb_memory_use_count()
for any URB whose buffer came from the usbfs mmap() region, and its first
statement is bus_to_hcd(ps->dev->bus).

After a disconnect the usbfs reference can be the last one, in which case
usb_put_dev() frees the device and the subsequent loop reads offset 80 of
freed memory and uses the result as a struct usb_hcd *, which
hcd_buffer_free_pages() then dereferences.

This is reachable by an unprivileged process that has read/write access to
a /dev/bus/usb node: mmap() the fd, submit one URB with a buffer inside the
mapping, wait for the device to be unplugged, then munmap() and close().
It reproduces on every attempt rather than being a race, because a live
MAP_SHARED vma holds a reference on the struct file, so usbdev_release()
cannot run until the last vma is gone and the freeing branch of
dec_usb_memory_use_count() is always taken.

  BUG: KASAN: slab-use-after-free in dec_usb_memory_use_count+0x3ae/0x410
  Read of size 8 at addr ffff8880122ee050 by task poc/769
  CPU: 1 UID: 1000 PID: 769 Comm: poc Tainted: G    B    6.12.94 #3

  Call Trace:
   dec_usb_memory_use_count+0x3ae/0x410
   free_async+0x2aa/0x4f0
   usbdev_release+0x375/0x460
   __fput+0x3ea/0xb50
   __x64_sys_close+0x86/0x100

  Allocated by task 11:
   usb_alloc_dev+0x55/0xd90
   hub_event+0x2524/0x43d0

  Freed by task 769:
   kfree+0x121/0x360
   device_release+0xd2/0x280
   usb_put_dev+0x23/0x30
   usbdev_release+0x2d8/0x460

Release the device reference after the drain loop instead. Nothing between
the two points requires it to have been dropped.

Fixes: f7d34b445a ("USB: Add support for usbfs zerocopy.")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5
Signed-off-by: Miguel Peñaranda <mig.penaranda07@gmail.com>
Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://patch.msgid.link/20260810121209.795089-1-mig.penaranda07@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-08-14 10:49:38 +09:00
..
buffer.c
config.c Merge 7.2-rc7 into usb-next 2026-08-14 10:17:11 +09:00
devices.c usb: core: devices: use kmalloc() to allocate dump buffer 2026-07-08 14:10:53 +02:00
devio.c usb: usbfs: fix use-after-free of usb_device in usbdev_release() 2026-08-14 10:49:38 +09:00
driver.c usb: fix UAF when probe runs concurrent to dyn ID removal 2026-07-10 15:16:07 +02:00
endpoint.c
file.c
generic.c
hcd-pci.c
hcd.c
hub.c Merge 7.2-rc7 into usb-next 2026-08-14 10:17:11 +09:00
hub.h
Kconfig
ledtrig-usbport.c
Makefile
message.c
notify.c
of.c
offload.c
otg_productlist.h
phy.c
phy.h
port.c usb: core: port: Deattach Type-C connector on component unbind 2026-07-16 17:11:22 +02:00
quirks.c usb: quirks: Add ShanWan gamepad to quirk list 2026-08-03 17:25:44 +02:00
sysfs.c usb: core: sysfs: add lock to bos_descriptors_read() 2026-07-16 17:11:44 +02:00
trace.c
trace.h
urb.c
usb-acpi.c
usb.c
usb.h