CVE-2026-142986: usb: gadget: f_midi: fix UAF race during IN request handling
In the Linux kernel, the following vulnerability has been resolved:
usb: gadget: fmidi: fix UAF race during IN request handling
fmididisable() drains and frees pre-allocated IN requests from inreqfifo without holding midi->transmitlock. If fmiditransmit() runs concurrently on the workqueue, fmididotransmit() can peek a request from inreqfifo and write into its buffer while fmididisable() frees it, leading to a use-after-free.
Additionally, when usbepqueue() fails in fmididotransmit() (such as with -ESHUTDOWN when the endpoint is disabled concurrently), it resets req->length = 0 and returns active instead of the error code, causing the do-while loop in fmiditransmit() to keep spinning under midi->transmitlock until the substream is drained.
Fix this by acquiring midi->transmitlock in fmididisable() while releasing IN requests from inreqfifo, and returning the error code from fmididotransmit() when usbepqueue() fails so fmiditransmit() aborts immediately and drops active substreams.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
In f_midi_disable(), acquire midi->transmit_lock while draining and freeing pre-allocated IN requests from in_req_fifo.
- Compensating control
In f_midi_do_transmit(), propagate the error from usb_ep_queue() instead of returning active when queuing fails, so f_midi_transmit() aborts rather than continuing its loop.
Event History
Frequently Asked Questions
What runtime conditions are required to trigger the use-after-free?
f_midi_disable() must run concurrently with f_midi_transmit() executing on the workqueue. The transmit path can obtain an IN request from in_req_fifo and write to its buffer while the disable path drains and frees that request.
What happens if an IN request cannot be queued while the endpoint is being disabled?
A usb_ep_queue() failure, such as -ESHUTDOWN during concurrent endpoint disablement, previously caused the transmit loop to continue spinning while holding midi->transmit_lock until the substream drained. The fix returns the queueing error so transmission aborts immediately and active substreams are dropped.