CVE-2026-139416: ALSA: rawmidi: Drain input work before freeing the runtime
In the Linux kernel, the following vulnerability has been resolved:
ALSA: rawmidi: Drain input work before freeing the runtime
The input runtime embeds eventwork, so the work must be drained before closesubstream() frees the runtime. The cancellation in sndrawmidiinputtrigger() runs before close clears substream->opened, leaving a window for sndrawmidireceive() to enqueue more work.
With a sequencer subscription to a USB MIDI input port, an in-flight completion can overlap the last subscription's midisynthunsubscribe():
1. sndusbmidiinputdata() observes inputtriggered and is delayed before calling sndrawmidireceive(). 2. Unsubscribe enters closesubstream(), clears inputtriggered through the provider trigger callback and returns from cancelworksync(). The substream is still opened. 3. The completion resumes. sndrawmidireceive() takes substream->lock, sees opened set and queues runtime->eventwork before dropping the lock. 4. Close clears opened under that lock, closes the provider and frees the runtime. Stopping USB URBs does not drain the raw-MIDI work. 5. The queued work runs and sndrawmidiinputeventwork() reads event or substream from the freed runtime, causing a use-after-free.
Cancel input eventwork again after clearing opened, before closing the provider or releasing the runtime's private data. Receive holds substream->lock through its opened check and work enqueue, so once close has cleared opened under that lock, no further receive can queue work. The final cancellation therefore drains any late work before the runtime is freed. Keep it outside the spinlock so a running callback can finish.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
In the Linux kernel ALSA raw-MIDI close path, cancel the input event work again after clearing substream->opened and before closing the provider or freeing the runtime.