Use after free in WebRTC (CVE-2026-9962)
A use-after-free flaw in WebRTC's SctpDataChannel arises because a task safety flag is not invalidated during object destruction, allowing a delayed task to run on freed memory. An attacker could exploit this via a malicious webpage to potentially achieve remote code execution in the renderer process.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 38 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 Use-After-Free (UAF) vulnerability exists in WebRTC's SctpDataChannel due to improper management of a task safety flag. The network_safety_ flag is not invalidated during object destruction, allowing delayed tasks capturing a raw this pointer to execute after the object is freed. This can be exploited to potentially achieve Remote Code Execution in the renderer process.
Affected files:
third_party/webrtc/pc/sctp_data_channel.ccthird_party/webrtc/pc/sctp_data_channel.hthird_party/webrtc/pc/data_channel_controller.ccthird_party/blink/renderer/modules/peerconnection/rtc_data_channel.cc
Estimated timestamp from git blame: 2023-04-11
Summary
A potential Use-After-Free (UAF) vulnerability has been identified in webrtc::SctpDataChannel. The issue arises because the PendingTaskSafetyFlag used to guard tasks posted to the network thread is not invalidated when the object is destroyed. If a task is queued on the network thread while the object is concurrently destroyed on the signaling thread, the task will still execute on a dangling this pointer. An attacker can exploit this via a malicious webpage to potentially achieve Remote Code Execution (RCE) in the sandboxed renderer process.
Root Cause Analysis
In third_party/webrtc/pc/sctp_data_channel.cc, SendAsync posts a task to the network thread using the SafeTask wrapper, capturing this as a raw pointer:
void SctpDataChannel::SendAsync(
DataBuffer buffer,
absl::AnyInvocable<void(RTCError) &&> on_complete) {
// ...
network_thread_->PostTask(SafeTask(
network_safety_, [this, buffer = std::move(buffer),
on_complete = std::move(on_complete)]() mutable {
RTC_DCHECK_RUN_ON(network_thread_);
RTCError err = SendImpl(std::move(buffer));
// ...
}));
}
The SafeTask helper relies on network_safety_ (a scoped_refptr<PendingTaskSafetyFlag>) to determine if the object is still alive. For SafeTask to prevent execution on a destroyed object, SetNotAlive() must be explicitly called before or during destruction.
However, SctpDataChannel::~SctpDataChannel does not call network_safety_->SetNotAlive(). It is only invoked in the abrupt error path (CloseAbruptlyWithError). Consequently, SafeTask holds a strong reference to the flag, keeping it alive and marked as valid even after the SctpDataChannel object itself has been deallocated. When the delayed task executes, the lambda runs and dereferences the dangling this pointer.
Potential Exploitation Scenario
An attacker can reliably trigger this UAF using JavaScript by widening the race window between task queuing and object destruction:
- The attacker creates an
RTCDataChanneland callschannel.send(largeBlob). Because the payload is a Blob, Blink initiates an asynchronous read and defers posting theSendAsynctask. - While the Blob is being read, the attacker causes the data channel to close (e.g., via a remote peer SCTP stream reset) and drops all local JavaScript references to the
RTCDataChannelobject. - The WebRTC channel reaches the
kClosedstate, causing theDataChannelControllerto drop its internal reference to theSctpDataChannel. - The Blob finishes reading, triggering
SendDataBufferwhich posts theSendAsynctask to the network thread. - Garbage collection in V8 reclaims the JavaScript object, triggering Blink's
RTCDataChannel::Dispose(), which drops the final WebRTC proxy reference. - The
SctpDataChannelobject is destroyed on the signaling thread. The safety flag remains valid. - The attacker uses heap spraying to reclaim the memory previously occupied by the
SctpDataChannel. - The network thread executes the pending
SendAsynctask on the attacker-controlled memory.
The attacker crafts the sprayed payload to forge the state_ member to appear kOpen and overwrites the controller_ member, which is a webrtc::WeakPtr. By pointing the WeakPtr's internal reference flag to a sprayed fake valid flag, and pointing the interface pointer to a fake vtable, the attacker can hijack the virtual call to controller_->SendData(...) in SctpDataChannel::SendDataMessage, leading to RCE.
Note: This vulnerability is not mitigated by MiraclePtr (BackupRefPtr) because the WebRTC library is largely outside the scope of BRP, and the lambda captures a raw pointer (T*) rather than a base::raw_ptr.
Suggested Fix
Invalidate the safety flag in the SctpDataChannel destructor to ensure pending tasks are aborted:
SctpDataChannel::~SctpDataChannel() {
network_safety_->SetNotAlive();
if (observer_adapter_)
ObserverAdapter::DeleteOnSignalingThread(std::move(observer_adapter_));
}
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
The destructor of SctpDataChannel does not call SetNotAlive() on the network safety flag, so pending tasks guarded by that flag still execute after the object is freed.
Impact
An attacker could potentially achieve remote code execution in the sandboxed renderer process, though the text notes this is a potential issue and not mitigated by MiraclePtr.
What the attacker needed
Victim visits a malicious webpage; browser supports WebRTC
The fix
The safety flag should be invalidated in the SctpDataChannel destructor to abort pending tasks.
How it was found
- Create an RTCDataChannel and call send with a large Blob, which defers posting the send task.
- While the Blob is being read, close the data channel and drop all local JavaScript references.
- The channel reaches the closed state and the controller drops its internal reference.
- The Blob finishes reading and posts the send task to the network thread.
- Garbage collection reclaims the JavaScript object, leading to destruction of the SctpDataChannel.
- Heap spray to reclaim the freed memory and execute the pending task on attacker-controlled data.
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 memory but later uses it again, like deleting a file and then trying to open it. Here, a background task still runs after the object it refers to is gone, so it reads or writes memory that may now belong to something else. An attacker who can control that reused memory might trick the program into running their 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.