In the Linux kernel, the following vulnerability has been resolved:
usb: gadget: f_midi2: fix use-after-free in string attribute show path
f_midi2_opts_str_show() takes the string lock internally, but its
callers dereference the opts->info.<field> pointer before calling it,
outside the lock. This races with f_midi2_opts_str_store(), which
frees the old string under opts->lock when the attribute is written
concurrently, the show path can read a pointer that gets freed
before the lock inside str_show() is even taken.
Change f_midi2_opts_str_show() to take a pointer to the string field,
matching the existing pattern in f_midi2_opts_str_store(), and
dereference it only after the lock is held. Update all three callers
(iface_name, block name, and the EP string option macro) accordingly.
CVSS Vector: CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
CVSS Score: 7.8
AV:L - The UAF is reached by concurrent local read/write of midi2 configfs string attributes (iface_name, ep_name, product_id, block name) under /sys/kernel/config/usb_gadget/<g>/functions/midi2.*; no USB host packets, cable, or UDC bind are required, matching other gadget configfs bugs scored Local rather than Physical.
AC:L - The attacker controls both sides by opening the same attribute on two fds (configfs serializes only per-fd) and racing show against store; store kfree()s the prior kstrndup string under opts->lock while show already holds the stale pointer, and the function need not be bound (store fails only if refcnt != 0).
PR:L - gadgets_make(), function_make(), and the midi2 show/store handlers perform no capable() check; access is gated only by configfs DAC, and Android/embedded USB gadget HALs routinely chown /sys/kernel/config/usb_gadget to non-root system or daemon accounts.
UI:N - The attacker creates the midi2 function instance and performs the concurrent attribute read/write themselves; configfs is typically already mounted at /sys/kernel/config, and no victim mount, cable plug, or other-user action is required.
S:U - The use-after-free of the configfs kstrndup string corrupts kernel heap within the same host kernel security authority; this is not a VM escape, sandbox breakout, or IOMMU/DMA boundary bypass.
C:H - Callers load opts->info.<field> outside the lock, then f_midi2_opts_str_show() scnprintfs that pointer after a concurrent store kfree()d it; reclaiming the kmalloc object lets the attacker control the bytes copied to userspace, a UAF disclosure primitive.
I:H - The same UAF of the kstrndup string, with store spraying attacker-chosen size and content into the same slab, is a classic heap use-after-free that can be converted into overlapping objects, arbitrary write, and control-flow hijack.
A:H - scnprintf() of the freed string after kfree() reliably produces a KASAN slab-use-after-free oops or kernel panic, which the attacker can retrigger with further concurrent show/store loops.
| Attack Vector |
Local |
Scope |
Unchanged |
| Attack Complexity |
Low |
Confidentiality Impact |
High |
| Privileges Required |
Low |
Integrity Impact |
High |
| User Interaction |
None |
Availability Impact |
High |
AV:L - The UAF is reached by concurrent local read/write of midi2 configfs string attributes (iface_name, ep_name, product_id, block name) under /sys/kernel/config/usb_gadget/<g>/functions/midi2.*; no USB host packets, cable, or UDC bind are required, matching other gadget configfs bugs scored Local rather than Physical.
AC:L - The attacker controls both sides by opening the same attribute on two fds (configfs serializes only per-fd) and racing show against store; store kfree()s the prior kstrndup string under opts->lock while show already holds the stale pointer, and the function need not be bound (store fails only if refcnt != 0).
PR:L - gadgets_make(), function_make(), and the midi2 show/store handlers perform no capable() check; access is gated only by configfs DAC, and Android/embedded USB gadget HALs routinely chown /sys/kernel/config/usb_gadget to non-root system or daemon accounts.
UI:N - The attacker creates the midi2 function instance and performs the concurrent attribute read/write themselves; configfs is typically already mounted at /sys/kernel/config, and no victim mount, cable plug, or other-user action is required.
S:U - The use-after-free of the configfs kstrndup string corrupts kernel heap within the same host kernel security authority; this is not a VM escape, sandbox breakout, or IOMMU/DMA boundary bypass.
C:H - Callers load opts->info.<field> outside the lock, then f_midi2_opts_str_show() scnprintfs that pointer after a concurrent store kfree()d it; reclaiming the kmalloc object lets the attacker control the bytes copied to userspace, a UAF disclosure primitive.
I:H - The same UAF of the kstrndup string, with store spraying attacker-chosen size and content into the same slab, is a classic heap use-after-free that can be converted into overlapping objects, arbitrary write, and control-flow hijack.
A:H - scnprintf() of the freed string after kfree() reliably produces a KASAN slab-use-after-free oops or kernel panic, which the attacker can retrigger with further concurrent show/store loops.
CVSS 3.1