Use after free in WebRTC (CVE-2026-7341)
A use-after-free race condition exists in RTCEncodedVideoStreamTransformerDelegate where a WeakPtr callback on the WebRTC worker thread can resolve after the delegate is destroyed on the signaling thread. An attacker could potentially reclaim the freed memory to hijack a virtual function call and achieve arbitrary code execution in the renderer.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 9 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 Chrome Security team. Please see https://chromium.googlesource.com/chromium/src/+/main/docs/security/ai-generated-security-bugs-faq.md for more information.
Overview: A potential use-after-free vulnerability exists in RTCEncodedVideoStreamTransformerDelegate due to a Time-of-Check Time-of-Use (TOCTOU) race condition when resolving a base::WeakPtr across different threads. In release builds, bypassed sequence checks allow the object to be destroyed while a callback is simultaneously executing on a different thread. An attacker could potentially reclaim the freed memory to achieve arbitrary code execution via a hijacked virtual function call.
Affected files:
third_party/blink/renderer/platform/peerconnection/rtc_encoded_video_stream_transformer.cc
Estimated timestamp from git blame: 2024-01-09
Summary
A potential Use-After-Free (UAF) vulnerability has been identified in RTCEncodedVideoStreamTransformerDelegate within the Blink renderer. The issue arises from a base::WeakPtr being captured in a callback that executes on the WebRTC worker thread, while the delegate object itself is destroyed on a different thread (typically the WebRTC signaling thread). Because base::WeakPtr sequence affinity checks are disabled in release builds, a Time-of-Check Time-of-Use (TOCTOU) race condition allows the worker thread to successfully resolve the WeakPtr and execute methods on the delegate after its memory has been freed.
Root Cause Analysis
When an encoded video stream is transformed, RTCEncodedVideoStreamTransformerDelegate::Transform() executes on the WebRTC worker thread. If a metronome is active, it schedules a callback for the next tick, capturing a base::WeakPtr to itself:
// third_party/blink/renderer/platform/peerconnection/rtc_encoded_video_stream_transformer.cc
metronome_->RequestCallOnNextTick(
[delegate = weak_factory_.GetWeakPtr()] {
if (delegate) {
delegate->InvokeQueuedTransforms();
}
});
The delegate is a thread-safe ref-counted object (webrtc::RefCountedObject) owned jointly by a Blink-managed RTCEncodedVideoStreamTransformer (destroyed on the main thread) and a native WebRTC receiver proxy. During teardown, the final reference is typically released when the native WebRTC receiver proxy completes its destruction on the WebRTC signaling thread.
The vulnerability occurs due to a race condition between the metronome tick executing on the worker thread and the delegate destructor executing on the signaling thread:
- On the worker thread, the lambda evaluates
if (delegate). This reads the atomic validity flag insideinternal::WeakReference::Flag::IsValid(). - Concurrently, the signaling thread begins destroying the delegate. It reaches
base::WeakPtrFactory::~WeakPtrFactory(), which callsInvalidate()to mark the atomic flag as invalid. - In release builds (
DCHECK_IS_ON()is false),Invalidate()skips theDCHECK_CALLED_ON_VALID_SEQUENCEcheck. The cross-thread invalidation succeeds without crashing the process. - If the worker thread reads the atomic flag just before the signaling thread marks it invalid,
if (delegate)passes. The subsequentdelegate->check also passes. - The delegate is fully destroyed on the signaling thread, and the memory is returned to the allocator.
- The worker thread proceeds to call
InvokeQueuedTransforms()on the now-danglingthispointer.
Impact
This vulnerability bypasses MiraclePtr (BackupRefPtr) protections because base::WeakPtr explicitly uses RAW_PTR_EXCLUSION T* ptr_ for its internal pointer to avoid keeping allocations in quarantine.
If an attacker can precisely time the teardown and perform heap spraying to reclaim the freed memory chunk, they can control the execution context of InvokeQueuedTransforms():
- The function begins with
base::AutoLock locker(source_task_runner_lock_);. By filling the reclaimed memory with zeros, the underlying platform mutex will appear unlocked, allowing the lock acquisition to succeed without crashing. - The function iterates over
queued_frames_(aWTF::Vector). An attacker can manipulate the vector's metadata in the reclaimed memory to point to arbitrary locations. - Inside the loop, it calls
PostCrossThreadTask(*source_task_runner_, ...). If the attacker controls thesource_task_runner_pointer, this leads to a virtual function call (PostTask) on attacker-controlled memory.
This vtable hijack can be leveraged to achieve Arbitrary Code Execution (RCE) within the sandboxed Renderer process.
Potential Reproduction Steps
Note: These are suggested steps to trigger the vulnerability; a working proof-of-concept has not been verified via tooling yet.
- In JavaScript, negotiate a WebRTC connection with a video stream.
- Attach an
RTCRtpScriptTransformto the receiver to force the creation of theRTCEncodedVideoStreamTransformerDelegate. - Send a burst of encoded video frames to ensure the
Transformmethod schedules the metronome callback on the worker thread. - Just before the metronome tick is expected to fire, aggressively tear down the connection (e.g.,
pc.close()and drop references) to trigger destruction of the delegate on the signaling thread. - Concurrently, perform heap spraying (e.g., via a Web Worker) with objects of the exact size of the delegate, filling the payload with zeros for the lock and attacker-controlled addresses for the
source_task_runner_pointer. - If the race is won, the worker thread will execute
InvokeQueuedTransforms()on the attacker's payload.
Suggested Fix
To prevent this vulnerability, RTCEncodedVideoStreamTransformerDelegate must guarantee that any scheduled callbacks are either safely canceled or executed on valid memory.
One approach is to avoid capturing a WeakPtr bound to a different sequence than where destruction occurs. Instead, the class could implement a tear-down method that synchronously cancels the metronome task or invalidates the WeakPtrFactory on the worker thread before allowing the final reference count to drop and the destructor to run. Alternatively, a separate ref-counted state object could be created exclusively for the metronome callback to hold the queued frames, decoupling the callback's lifecycle from the delegate's lifecycle.
Evaluated with Chrome root at commit: 7353d249d9cacf9c7218e1d7b8a39cf39c72d646
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 race condition where a base::WeakPtr is resolved on one thread while the object is destroyed on another, and release builds skip sequence checks that would otherwise catch the cross-thread invalidation.
Impact
If an attacker can precisely time the teardown and perform heap spraying, they could potentially achieve arbitrary code execution within the sandboxed renderer process.
What the attacker needed
Ability to run JavaScript in the renderer; precise timing of teardown; heap spraying capability
The fix
The delegate should cancel scheduled callbacks or invalidate the WeakPtrFactory on the worker thread before destruction, or use a separate ref-counted state object for the callback.
How it was found
- Negotiate a WebRTC connection with a video stream in JavaScript.
- Attach an RTCRtpScriptTransform to the receiver to create the delegate.
- Send a burst of encoded video frames to schedule the metronome callback.
- Tear down the connection just before the metronome tick to destroy the delegate.
- Heap spray with objects of the delegate's size, filling zeros for the lock and controlled addresses for the source_task_runner_ pointer.
- If the race is won, the worker thread executes InvokeQueuedTransforms() on the attacker's payload.
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 use-after-free happens when a program frees an object's memory but then keeps using it, like deleting a file and still trying to open it. Here, two threads race: one checks if the object is still alive, the other destroys it at the same moment, so the first thread ends up using freed memory. An attacker who can control what fills that freed memory might redirect the program to 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.