CVE-2026-99318: ALSA: bcd2000: Fix use-after-free of MIDI URBs on file close
In the Linux kernel, the following vulnerability has been resolved:
ALSA: bcd2000: Fix use-after-free of MIDI URBs on file close
bcd2000disconnect() calls sndcarddisconnect(), which only prevents new opens, and then frees the MIDI URBs. A rawmidi file that was already open can still be closed afterwards, and its close callback, bcd2000midioutputclose(), calls usbkillurb() on midiouturb.
The URB pointers are cleared on disconnect and their accesses are serialized with midilock, but bcd2000midioutputclose() reads midiouturb without that lock. The check can therefore pass just before the pointer is cleared, and usbkillurb() then runs on the URB that has already been freed:
BUG: KASAN: slab-use-after-free in usbkillurb+0x74/0x80 Read of size 8 at addr ffff8880078e7d40 usbkillurb bcd2000midioutputclose closesubstream rawmidireleasepriv sndrawmidirelease
Allocated by: usballocurb <- bcd2000initmidi <- bcd2000probe Freed by: usbfreeurb <- bcd2000midifree <- bcd2000disconnect
Take the lock in bcd2000midioutputclose() and reference the URB with usbgeturb() before releasing it. The URB then stays valid until usbputurb() after usbkillurb() has returned, even if a disconnect frees it in the meantime. usbkillurb() itself cannot run under midilock, as the completion handler takes the same lock.
Affected Software
Event History
Frequently Asked Questions
Who is exposed to this issue?
Systems using the Linux kernel with the ALSA bcd2000 driver are exposed when a BCD2000 MIDI rawmidi device has an open file handle during device disconnect. The vulnerable path involves the MIDI output close callback.
What sequence triggers the use-after-free?
The device must disconnect after snd_card_disconnect() has prevented new opens but while a rawmidi file is already open. If that file is then closed, bcd2000_midi_output_close() can call usb_kill_urb() on a MIDI URB that disconnect handling has already freed.
How does the fix prevent the race?
The fix takes midi_lock while accessing midi_out_urb and obtains a URB reference with usb_get_urb() before releasing the lock. This keeps the URB valid through usb_kill_urb() until usb_put_urb() is called.