Use after free in GetUserMedia (CVE-2026-113070)
A use-after-free race condition exists in MediaDevicesDispatcherHost where a WeakPtr check on the UI thread can pass before the object is destroyed on the IO thread, allowing the UI thread to access freed memory. An attacker who can reallocate the freed chunk could hijack a function pointer to achieve remote code execution and sandbox escape, though reachability requires a disabled feature flag.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 7 months
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 potential Use-After-Free (UAF) exists in MediaDevicesDispatcherHost due to a Time-Of-Check to Time-Of-Use (TOCTOU) race condition with a base::WeakPtr. A callback bound on the IO thread is executed directly on the UI thread, allowing the host object to be destroyed concurrently after the WeakPtr validity check passes but before execution completes. Because base::WeakPtr's internal pointer is not protected by MiraclePtr, this race can lead to an exploitable browser-process sandbox escape.
Affected files:
content/browser/renderer_host/media/media_devices_dispatcher_host.cccontent/browser/renderer_host/media/media_stream_ui_proxy.cccontent/browser/web_contents/web_contents_impl.cccontent/public/browser/web_contents_delegate.cc
Estimated timestamp from git blame: 2024-11-08
Vulnerability Details
A cross-thread Time-Of-Check to Time-Of-Use (TOCTOU) Use-After-Free vulnerability exists in the Browser process, specifically within MediaDevicesDispatcherHost.
The issue originates in MediaDevicesDispatcherHost::OnEnumeratedAudioOutputDevices (running on the IO thread). This method binds a base::WeakPtr to the OnSelectedDeviceInfo callback and passes it to the UI proxy:
// content/browser/renderer_host/media/media_devices_dispatcher_host.cc
ui_proxy->RequestSelectAudioOutput(
...,
base::BindOnce(&MediaDevicesDispatcherHost::OnSelectedDeviceInfo,
weak_factory_.GetWeakPtr(), std::move(enumeration)));
This callback is routed to the UI thread via MediaStreamUIProxy. If the WebContentsImpl lacks a delegate (or uses a default implementation), it executes the callback synchronously on the UI thread:
// content/browser/web_contents/web_contents_impl.cc:6029
std::move(callback).Run(base::unexpected(content::SelectAudioOutputError::kNotSupported));
When Run() is invoked on the UI thread, the internal base::BindOnce execution helper evaluates the validity of the WeakPtr. In Release builds, this performs a lock-free check against an AtomicFlag. If the check passes, the raw pointer is unwrapped, and the UI thread jumps into MediaDevicesDispatcherHost::OnSelectedDeviceInfo.
However, because the MediaDevicesDispatcherHost instance is owned by a mojo::UniqueReceiverSet on the IO thread, an attacker can concurrently close the Mojo pipe. This causes the IO thread to destroy the MediaDevicesDispatcherHost object after the UI thread's WeakPtr check passes, but before the UI thread finishes executing the callback.
When the UI thread proceeds to execute the fallback logic inside OnSelectedDeviceInfo, it accesses this->select_audio_output_callback_. Since this now points to freed memory, a Use-After-Free occurs.
Impact
The base::WeakPtr implementation stores its internal pointer using RAW_PTR_EXCLUSION. Therefore, the freed MediaDevicesDispatcherHost object is not protected or quarantined by MiraclePtr (BackupRefPtr). An attacker who reallocates this memory chunk can craft a fake base::OnceCallback state to hijack the polymorphic_invoke function pointer, leading to arbitrary Remote Code Execution (RCE) and a full Sandbox Escape.
Note: Reachability currently requires the blink::features::kSelectAudioOutput feature flag to be enabled, which is disabled by default in production.
Potential Steps to Reproduce
(Note: These are suggested steps based on static analysis; our tooling agent does not yet have the ability to run code or execute a PoC.)
- Prerequisite: Ensure the browser is running with
--enable-features=SelectAudioOutput. - From a compromised renderer, obtain or simulate transient user activation.
- Trigger the
blink::mojom::MediaDevicesDispatcherHost::SelectAudioOutputIPC request. - Ensure the request is handled by a WebContents without a delegate (or a guest view that immediately rejects it) to force synchronous UI-thread callback execution.
- Immediately close the Mojo pipe (e.g., by dropping the remote) to trigger destruction of the
MediaDevicesDispatcherHoston the IO thread. - If timed correctly, the UI thread passes the
WeakPtrcheck and attempts to runselect_audio_output_callback_.Run()on the freed object.
Suggested Fix
To ensure the WeakPtr is checked and the callback is executed safely on the sequence it belongs to, wrap the callback using base::BindPostTask (or base::BindPostTaskToCurrentDefault()) when it is created on the IO thread:
ui_proxy->RequestSelectAudioOutput(
...,
base::BindPostTaskToCurrentDefault(
base::BindOnce(&MediaDevicesDispatcherHost::OnSelectedDeviceInfo,
weak_factory_.GetWeakPtr(), std::move(enumeration))));
This guarantees the callback will be posted back to the IO thread before the WeakPtr is unwrapped, preventing the cross-thread TOCTOU race.
Evaluated with Chrome root at commit: ff3d2b74fa39431785bd60e51463b08fcc71ee33
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 a cross-thread time-of-check to time-of-use race: a WeakPtr validity check on the UI thread is not atomic with the object's destruction on the IO thread, and the WeakPtr's internal pointer is excluded from MiraclePtr protection.
Impact
An attacker who reallocates the freed memory could craft a fake callback state to hijack a function pointer, leading to arbitrary remote code execution and a full sandbox escape, but reachability currently requires the SelectAudioOutput feature flag which is disabled by default.
What the attacker needed
Compromised renderer; SelectAudioOutput feature flag enabled; transient user activation
The fix
The callback should be wrapped with base::BindPostTaskToCurrentDefault when created on the IO thread, so the WeakPtr is checked and the callback executed on the correct sequence.
How it was found
- Enable the SelectAudioOutput feature flag.
- From a compromised renderer, obtain or simulate transient user activation.
- Trigger the SelectAudioOutput IPC request.
- Ensure the request is handled by a WebContents without a delegate to force synchronous UI-thread callback execution.
- Immediately close the Mojo pipe to trigger destruction of the host on the IO thread.
- If timed correctly, the UI thread passes the WeakPtr check and runs the callback on freed 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.
This report describes a timing bug in a web browser's media device handling. A check that an object is still alive happens on one thread, but another thread can free the object right after the check, so the first thread then uses freed memory. If an attacker can control what replaces that memory, they could run their own code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.