Skip to content
Race condition Advisory Advanced CVE-2026-7350

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.cc
  • media/midi/midi_manager.cc
  • media/midi/midi_service.cc
  • content/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:

  1. Premature Destruction: When a renderer requests a MIDI session, MidiService creates a MidiManagerWin which begins hardware initialization on a background thread (MidiServiceThread). The client is added to pending_clients_. If the renderer immediately closes its Mojo pipe, MidiHost::EndSession handles the disconnect and removes the client from pending_clients_. The service then calls MidiManager::HasOpenSession() to check if the manager should be destroyed. However, HasOpenSession() (in media/midi/midi_manager.cc) only checks clients_.size() != 0u and ignores pending_clients_. Because the count evaluates to 0, MidiService deletes the manager while the initialization task is actively running.

  2. Unsynchronized Destructor: The ~MidiManagerWin() destructor (in media/midi/midi_manager_win.cc) iterates over port_manager_->inputs() and outputs() to call Finalize() on each port. Crucially, it does so without holding GetTaskLock(). Concurrently, the background thread running InitializeOnTaskRunner holds the lock and invokes ReflectActiveDeviceList, 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::vector backing 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 a std::unique_ptr (hdr_). Concurrently, the IO thread calls InPort::Finalize(), which moves that same unique_ptr. This torn state causes MIDIHDRDeleter to double-free the heap chunk.
  • Map Corruption: Concurrent reads and writes to hmidiin_to_index_map_ corrupt the underlying std::map Red-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)

  1. Attacker achieves initial code execution in a sandboxed renderer process.
  2. The compromised renderer binds the WebMIDI Mojo interface and calls StartSession.
  3. The browser process instantiates MidiManagerWin, places the client in pending_clients_, and spawns the initialization task on a background thread.
  4. Before initialization completes (which can be delayed due to slow Windows MIDI APIs like midiInGetDevCaps), the renderer deliberately closes the Mojo pipe.
  5. The browser process handles the disconnect, checks HasOpenSession(), receives false, and destructs MidiManagerWin.
  6. The ~MidiManagerWin destructor races with the still-running background initialization, causing the memory corruption primitives detailed above.

Suggested Fix

  1. Fix Lifecycle Check: Update MidiManager::HasOpenSession() in media/midi/midi_manager.cc to accurately reflect pending initialization states. It should check both clients_ and pending_clients_:

    C++
    bool MidiManager::HasOpenSession() {
      base::AutoLock auto_lock(lock_);
      return clients_.size() != 0u || pending_clients_.size() != 0u;
    }
    
  2. Synchronize Destructor: In media/midi/midi_manager_win.cc, ensure that GetTaskLock() 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.

The original report as published on the Chromium issue tracker. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

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

  1. Gain code execution in a sandboxed renderer process.
  2. Bind the WebMIDI interface and call StartSession.
  3. The browser creates the Windows MIDI manager and starts initialisation on a background thread.
  4. Close the Mojo pipe before initialisation finishes.
  5. The browser sees no open session and destroys the manager.
  6. 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.

More from Google Chrome

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.