Use after free in WebCodecs (CVE-2026-10013)
A thread-affinity violation in VideoEncoder.isConfigSupported allows a Persistent handle created on a worker thread to be destroyed on the main thread after the worker terminates, potentially corrupting the main thread's PersistentRegion free-list. This memory corruption could be exploited for remote code execution in the renderer process.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 9 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. Please see https://chromium.googlesource.com/chromium/src/+/main/docs/security/ai-generated-security-bugs-faq.md for more information.
Overview: A thread-affinity violation occurs when VideoEncoder.isConfigSupported() is called from a Web Worker that is subsequently terminated. A garbage-collected Persistent handle is inadvertently destroyed on the main thread when a PostTask fails, potentially corrupting the main thread's PersistentRegion free-list if the worker's memory pages have been recycled. This memory corruption can potentially be exploited for Remote Code Execution (RCE) in the renderer process.
Affected files:
third_party/blink/renderer/modules/webcodecs/video_encoder.ccthird_party/blink/renderer/platform/heap/heap_barrier_callback.hthird_party/blink/renderer/modules/webcodecs/gpu_factories_retriever.ccmedia/mojo/clients/mojo_codec_factory.cc
Estimated timestamp from git blame: 2024-02-29
Summary
A potential memory corruption vulnerability exists in VideoEncoder::isConfigSupported due to the improper cross-thread handling of cppgc::Persistent handles.
When isConfigSupported is called from a Web Worker, it utilizes HeapBarrierCallback to aggregate results. This callback captures a thread-affine Persistent handle but is wrapped in a type-erased base::RepeatingCallback. This circumvents CrossThreadBindOnce's static safety checks, allowing the callback to be safely passed to the main thread via RetrieveGpuFactoriesWithKnownEncoderSupport.
The callback is registered in MojoCodecFactory using base::BindPostTaskToCurrentDefault. If the originating worker thread is terminated before the GPU factory response is received, the worker's task runner is invalidated. When the main thread attempts to execute the BindPostTask trampoline, the underlying PostTask fails. In Chromium, a failed PostTask results in the synchronous destruction of the passed closure on the calling thread. Consequently, the Persistent handle created on the worker thread is destroyed on the main thread.
Technical Details
HeapBarrierCallback(third_party/blink/renderer/platform/heap/heap_barrier_callback.h) stores results in aBarrierCallbackInfowhich holds aPersistent<GCedHeapVector>.- This
BarrierCallbackInfois captured by value in abase::RepeatingCallbackand sent across threads toMojoCodecFactory::NotifyEncoderSupportKnown, bypassing Blink's thread-affinity checks. MojoCodecFactorywraps this in aBindPostTaskTrampolineto ensure it runs on the worker thread.- If the worker terminates, its task runner shuts down and its Oilpan
HeapBaseandPersistentRegionare destroyed. The backing memory forPersistentNodeSlotsis freed to the system allocator. - When the main thread calls
.Run()on the trampoline,task_runner_->PostTaskfails and immediately destroys the closure on the main thread. - The destruction sequence calls
Persistent::Clear(), which invokesWeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode()). GetPersistentRegionlocates the region by inspecting theBasePageof the pointee (GetValue()). If PartitionAlloc has recycled the worker's freed 128KB page into the main thread's Oilpan heap,BasePage::FromPayloadwill return the main thread'sHeapBase.FreeNodeexecutes on the main thread'sPersistentRegion. Because the thread-check is a debug-onlyCPPGC_DCHECK, execution proceeds without locks in release builds.FreeNodeblindly inserts the danglingGetNode()pointer (which belonged to the worker's freed memory) into the main thread'sfree_list_head_.- Subsequent
Persistentallocations on the main thread will pop this attacker-controlled pointer, leading to arbitrary memory writes (Write-Whereprimitive) whenInitializeAsUsedNodeis called.
Potential Steps to Reproduce
Note: These are suggested steps; our tooling agent does not have the ability to run code to verify them.
- Spawn a Web Worker from a malicious webpage.
- In the worker, call
VideoEncoder.isConfigSupported(config)with a configuration that requires hardware detection (e.g., leavinghw_prefunset or setting it toprefer-hardware). - Immediately terminate the worker (
self.close()orworker.terminate()). - Perform heap grooming on the main thread to encourage Oilpan page recycling.
- When the hardware detection completes asynchronously, the main thread attempts to post the callback, fails, and destroys the
Persistenthandle, corrupting its own free-list.
Suggested Fix
HeapBarrierCallback should not encapsulate Persistent handles if the resulting callback is intended to be moved across threads.
- Modify
BarrierCallbackInfointhird_party/blink/renderer/platform/heap/heap_barrier_callback.hto useCrossThreadPersistentinstead ofPersistent. - Alternatively, ensure that
VideoEncoder::isConfigSupportedutilizesCrossThreadHandleand explicitly unwraps the handle only when safely back on the worker thread, avoiding the capture of garbage-collected pointers orPersistenthandles inside theHeapBarrierCallbackthat is passed across thread boundaries.
Evaluated with Chrome root at commit: b7d0c4d810da1b31400f198c70d9720fc8f0e5a0
Results so far have been promising, but there can be wrong deductions. Feel free to adjust as follows:
- If you are familiar with the severity guidelines, you may adjust the severity.
- If this is a false positive, and there's no work to be done, please close as WAI.
- If there is work to do here but not a vulnerability, please change the issue type to Task/Bug/FR.
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 Persistent handle created on a worker thread is captured in a callback that is posted to the main thread; when the worker terminates, the failed PostTask destroys the handle on the main thread, corrupting the main thread's free-list.
What the attacker needed
Victim visits a malicious webpage; browser supports WebCodecs; worker terminated before GPU response
The fix
HeapBarrierCallback should use CrossThreadPersistent instead of Persistent, or VideoEncoder.isConfigSupported should use CrossThreadHandle and unwrap it only on the worker thread.
How it was found
- Spawn a Web Worker from a malicious webpage.
- In the worker, call VideoEncoder.isConfigSupported with a configuration that requires hardware detection.
- Immediately terminate the worker.
- Perform heap grooming on the main thread to encourage Oilpan page recycling.
- When hardware detection completes, the main thread attempts to post the callback, fails, and destroys the Persistent handle, corrupting its own free-list.
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 web page can start a background worker that asks the browser to check video encoder support. If the worker is closed before the check finishes, a memory pointer meant for the worker is freed on the main page's memory manager. This can corrupt memory and, in theory, let an attacker 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.