Use after free in Media (CVE-2026-9945)
A cross-thread use-after-free race exists in MediaFoundationStreamWrapper because its COM reference-counted lifetime can end on a background Media Foundation thread while a queued task on the Chromium media thread still dereferences a WeakPtr. An attacker could trigger playback and rapid teardown to win the race and potentially achieve arbitrary code execution in the utility process.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 41 days
Flapjack, 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 Chrome Security team. Please see go/chrome-ai-generated-security-bugs-faq for more information.
Overview: MediaFoundationStreamWrapper's lifetime is managed by COM reference counting, permitting its destruction on a background Media Foundation thread. This creates a Time-of-Check to Time-of-Use (TOCTOU) race condition when executing tasks posted to the Chromium media thread via base::WeakPtr. A successful race can lead to a Use-After-Free (UAF) and arbitrary code execution in the MediaFoundationService utility process.
Affected files:
media/renderers/win/media_foundation_stream_wrapper.ccmedia/renderers/win/media_foundation_stream_wrapper.h
Estimated timestamp from git blame: 2025-11-24
Summary
A potential cross-thread Use-After-Free (UAF) vulnerability exists in MediaFoundationStreamWrapper (media/renderers/win/media_foundation_stream_wrapper.cc). The class relies on default COM reference counting for lifetime management, meaning its destruction can occur on a background Windows Media Foundation (MF) threadpool thread. However, it uses a base::WeakPtrFactory to post tasks to the Chromium media thread. Because base::WeakPtr is not thread-safe for concurrent destruction and dereferencing, a Time-of-Check to Time-of-Use (TOCTOU) race condition exists that allows the media thread to execute methods on freed memory.
Technical Details
MediaFoundationStreamWrapper implements IMFMediaStream and inherits from Microsoft::WRL::RuntimeClass. It interacts with both the Chromium media pipeline and the asynchronous MF pipeline. When the MF pipeline requests a sample (RequestSample), the wrapper posts a task to the Chromium media thread:
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&MediaFoundationStreamWrapper::ProcessRequestsIfPossible,
weak_factory_.GetWeakPtr()));
Because there is no custom Release() override that trampolines destruction to the task_runner_, if the MF pipeline drops the final COM reference, ~MediaFoundationStreamWrapper() executes synchronously on the MF background thread. This destroys the weak_factory_.
Concurrently, when the task executes on the Chromium media thread, the base::internal::InvokeHelper evaluates the WeakPtr. It unwraps the pointer, checks its validity, and then invokes the bound method. If the MF thread invalidates the WeakPtr and frees the MediaFoundationStreamWrapper's memory after the WeakPtr's validity has been confirmed but before or during the execution of the target method, a UAF occurs.
Notably, the underlying pointer within base::WeakPtr is declared as RAW_PTR_EXCLUSION T* ptr_; (base/memory/weak_ptr.h). Therefore, the freed memory is not quarantined by MiraclePtr (BackupRefPtr), leaving it immediately exploitable.
Potential Attacker Steps
Note: These are suggested steps; our tooling has not executed a live Proof of Concept.
- Trigger playback: An attacker creates a webpage hosting DRM-protected media or specific codecs that initialize the
MediaFoundationRendererinside theMediaFoundationServiceutility process. - Queue tasks: The MF pipeline asynchronously calls
RequestSample(), queuingProcessRequestsIfPossible()tasks bound toWeakPtrs on the Chromium media thread. - Initiate Teardown: The attacker rapidly destroys the
<video>element. The Chromium pipeline drops its COM references to theMediaFoundationSourceWrapperand its streams. - Race Condition: The MF pipeline subsequently shuts down and drops its final reference to the
MediaFoundationStreamWrapperon a background thread. - TOCTOU Gap: On the Chromium media thread, the queued task begins execution.
InvokeHelperconfirms theWeakPtris valid and resolves it to a raw C++ reference. - Object Destruction: Before the method fully executes, the MF thread destroys the
MediaFoundationStreamWrapperand its memory is deallocated. - Heap Grooming: The attacker leverages cross-process heap grooming (via Mojo IPCs to the utility process) to immediately reallocate the freed memory block with forged contents (e.g., an unlocked
base::Lockstate and a controlleddemuxer_stream_pointer). - Exploitation:
ProcessRequestsIfPossible()executes on the attacker-controlled memory block. It acquires the forged lock, reads the forgeddemuxer_stream_pointer, and makes a virtual method call (demuxer_stream_->Read()), redirecting control flow and achieving Remote Code Execution (RCE) in the utility process.
Suggested Fix
Implement a custom thread-hopping Release() override in MediaFoundationStreamWrapper (and similar COM-visible classes in this directory, like MediaFoundationSourceWrapper) to ensure the object is always destructed on the correct Chromium sequence.
For example:
ULONG STDMETHODCALLTYPE Release() override {
ULONG ref_count = Microsoft::WRL::RuntimeClass<...>::Release();
if (ref_count == 0) {
// Note: requires modifying the class to not auto-delete in the base Release(),
// or using a custom Deleter with a smart pointer instead of strict WRL inheritance.
}
return ref_count;
}
Alternatively, use base::RefCountedDeleteOnSequence paradigms, or wrap the WRL RuntimeClass inside an inner object so the outer Chromium-facing class controls the teardown strictly on the task_runner_.
Evaluated with Chrome root at commit: c0eb5541aebfa4ea08806eaf6e94bcc69f87ab2f
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 class relies on default COM reference counting, so destruction can happen on a background thread while a WeakPtr-based task on the media thread is being checked and invoked, creating a time-of-check to time-of-use gap.
What the attacker needed
Victim visits attacker webpage; DRM-protected media or specific codecs; rapid teardown of video element; cross-process heap grooming
The fix
The report suggests implementing a custom thread-hopping Release() override or using base::RefCountedDeleteOnSequence to ensure the object is always destructed on the correct Chromium sequence.
How it was found
- An attacker creates a webpage that initialises the MediaFoundationRenderer inside the utility process.
- The Media Foundation pipeline calls RequestSample, queuing tasks bound to WeakPtrs on the Chromium media thread.
- The attacker rapidly destroys the video element, causing the Chromium pipeline to drop its COM references.
- The Media Foundation pipeline shuts down and drops its final reference on a background thread.
- A queued task on the media thread confirms the WeakPtr is valid and resolves it to a raw reference.
- Before the method executes, the background thread destroys the object, and the attacker uses heap grooming to reallocate the freed memory with forged contents.
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 is a race condition where one part of the program frees an object while another part is still about to use it, leading to a use-after-free. An attacker who can control timing, for example by starting and quickly stopping video playback, might trick the program into using the freed memory and potentially 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.