Use after free in WebMIDI (CVE-2026-7350)
A race condition in the Windows MIDI manager lifecycle lets the manager be destroyed while its background initialisation task is still running, because the open-session check ignores pending clients. A compromised renderer could trigger heap corruption primitives in the browser process and potentially escape the sandbox.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 23 days
Project Fortify, an experimental security project, has identified the following potential security issue. If you're a feature owner CC-ed on this bug, please do your best to review these reports without the security team.
Overview: A data race in the Windows MIDI implementation allows the MidiManagerWin destructor to run concurrently with its initialization task on a background thread. This unsynchronized access leads to potential heap corruption primitives in the browser process, including vector backing-store use-after-free and double-frees. A compromised renderer could potentially exploit this race to achieve a sandbox escape.
Affected files:
media/midi/midi_manager_win.ccmedia/midi/midi_manager.ccmedia/midi/midi_service.cccontent/browser/media/midi_host.cc
Estimated timestamp from git blame: 2018-10-03
Description
A race condition exists in the lifecycle management of MidiManagerWin that can lead to severe heap corruption in the browser process. The vulnerability stems from two interconnected logic flaws:
-
Premature Destruction: When a renderer requests a MIDI session,
MidiServicecreates aMidiManagerWinwhich begins hardware initialization on a background thread (MidiServiceThread). The client is added topending_clients_. If the renderer immediately closes its Mojo pipe,MidiHost::EndSessionhandles the disconnect and removes the client frompending_clients_. The service then callsMidiManager::HasOpenSession()to check if the manager should be destroyed. However,HasOpenSession()(inmedia/midi/midi_manager.cc) only checksclients_.size() != 0uand ignorespending_clients_. Because the count evaluates to 0,MidiServicedeletes the manager while the initialization task is actively running. -
Unsynchronized Destructor: The
~MidiManagerWin()destructor (inmedia/midi/midi_manager_win.cc) iterates overport_manager_->inputs()andoutputs()to callFinalize()on each port. Crucially, it does so without holdingGetTaskLock(). Concurrently, the background thread runningInitializeOnTaskRunnerholds the lock and invokesReflectActiveDeviceList, which pushes new ports into these very same vectors.
Impact
This race condition results in multiple highly exploitable memory corruption primitives in the unsandboxed browser process:
- Vector Use-After-Free: As the background thread pushes new ports, the
std::vectorbacking array can reallocate. The concurrent iteration in the IO thread's destructor will then operate on a freed backing array. - Double-Free: The background thread calls
InPort::Open(), allocating a 32KB buffer into astd::unique_ptr(hdr_). Concurrently, the IO thread callsInPort::Finalize(), which moves that sameunique_ptr. This torn state causesMIDIHDRDeleterto double-free the heap chunk. - Map Corruption: Concurrent reads and writes to
hmidiin_to_index_map_corrupt the underlyingstd::mapRed-Black tree.
Because these structures are not protected by MiraclePtr, a compromised renderer could potentially groom the heap and weaponize these primitives to achieve a full Sandbox Escape (Browser Process RCE).
Potential Steps to Trigger
(Note: Our tooling does not execute code; these are suggested steps an attacker would follow based on static analysis)
- Attacker achieves initial code execution in a sandboxed renderer process.
- The compromised renderer binds the WebMIDI Mojo interface and calls
StartSession. - The browser process instantiates
MidiManagerWin, places the client inpending_clients_, and spawns the initialization task on a background thread. - Before initialization completes (which can be delayed due to slow Windows MIDI APIs like
midiInGetDevCaps), the renderer deliberately closes the Mojo pipe. - The browser process handles the disconnect, checks
HasOpenSession(), receivesfalse, and destructsMidiManagerWin. - The
~MidiManagerWindestructor races with the still-running background initialization, causing the memory corruption primitives detailed above.
Suggested Fix
-
Fix Lifecycle Check: Update
MidiManager::HasOpenSession()inmedia/midi/midi_manager.ccto accurately reflect pending initialization states. It should check bothclients_andpending_clients_:C++ bool MidiManager::HasOpenSession() { base::AutoLock auto_lock(lock_); return clients_.size() != 0u || pending_clients_.size() != 0u; } -
Synchronize Destructor: In
media/midi/midi_manager_win.cc, ensure thatGetTaskLock()is acquired before iterating over the port lists in~MidiManagerWin(), preventing the data race entirely if premature destruction somehow occurs.
Evaluated with Chrome root at commit: f200f57a19490707ff8bc7aa5de3cbc443a3afad
Results so far have been promising, but there can be wrong deductions. If this proves to be a false positive, please close as WAI; data from false positives will be used to improve accuracy over time. And please feel free to reach out to me directly if you have concerns or feedback on the project.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the open-session check only counts active clients and ignores pending ones, so the manager is deleted while its background initialisation still runs, and the destructor iterates the port lists without taking the task lock.
Impact
A compromised renderer could potentially groom the heap and use these primitives to escape the sandbox and run code in the browser process; the report is based on static analysis and has not been demonstrated.
What the attacker needed
Code execution in a renderer; WebMIDI available in the browser; slow MIDI initialisation on Windows
The fix
The open-session check should also count pending clients, and the destructor should take the task lock before iterating the port lists.
How it was found
- Gain code execution in a sandboxed renderer process.
- Bind the WebMIDI interface and call StartSession.
- The browser creates the Windows MIDI manager and starts initialisation on a background thread.
- Close the Mojo pipe before initialisation finishes.
- The browser sees no open session and destroys the manager.
- The destructor races with the still-running initialisation, corrupting memory.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A browser splits work into a locked-down part that runs web pages (the renderer) and a more powerful part (the browser process). Here, when a page asks to use MIDI devices and then quickly disconnects, the browser process frees an object while a background thread is still filling it in, so two threads touch the same memory at once. That kind of clash can corrupt memory, and an attacker who already controls a web page might use it to break out of the sandbox.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.