Use after free in CameraCapture (CVE-2026-11654)
A race condition in the macOS/iOS video capture code allows the main thread and an AVFoundation background thread to access the same WeakPtrFactory concurrently, which can cause a use-after-free of internal reference-counting structures. An attacker could potentially trigger this from web content with camera permissions, leading to arbitrary code execution in a privileged process.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 25 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 race condition in VideoCaptureDeviceAVFoundation allows concurrent access to a base::WeakPtrFactory from the main thread and a background AVFoundation thread. This can result in a Use-After-Free (UAF) of internal memory safety structures, potentially leading to arbitrary code execution in privileged processes.
Affected files:
media/capture/video/apple/video_capture_device_avfoundation.mm
Estimated timestamp from git blame: 2023-01-04
Potential Vulnerability: Concurrent WeakPtrFactory Access and Use-After-Free
A potential race condition exists in media/capture/video/apple/video_capture_device_avfoundation.mm where _weakPtrHolderForTakePhoto.weak_ptr_factory is accessed concurrently from the main thread (Device Task Runner) and an internal AVFoundation dispatch queue.
Root Cause
In VideoCaptureDeviceAVFoundation, the WeakPtrFactory is invalidated on the main thread in stopPhotoOutput (at line 782) without holding the class lock _lock. Simultaneously, the AVFoundation background thread may call GetWeakPtr() within the captureOutput:didFinishProcessingPhoto:error: delegate callback (at line 747) while holding _lock.
Since base::WeakPtrFactory is not thread-safe and must be used on a single sequence, this concurrent access violates Chromium's memory safety invariants.
Memory Corruption Mechanics
The race occurs within base::internal::WeakReferenceOwner. When InvalidateWeakPtrs() is called on Thread A (Main), it replaces the internal scoped_refptr<Flag> with a new one. Concurrently, GetWeakPtr() on Thread B (Background) reads the raw pointer of the old Flag to increment its reference count (AddRef).
If Thread A releases the old Flag and it is deallocated before Thread B performs the increment, a Use-After-Free write (atomic increment) occurs on the freed memory. This can result in a WeakPtr that erroneously appears valid even after the factory has been destroyed.
Impact
This issue is potentially reachable from web content via the ImageCapture.takePhoto() and MediaStreamTrack.stop() APIs, provided camera permissions are granted.
The impacted process is highly privileged:
- macOS: The Video Capture service runs in a Utility process with
kNoSandbox(equivalent to browser privileges). - iOS: The service runs directly in the Browser process.
Since internal pointers in scoped_refptr and WeakPtr are marked with RAW_PTR_EXCLUSION, they are not protected by MiraclePtr, increasing the likelihood of successful exploitation for remote code execution.
Suggested Potential Steps to Reproduce
- Grant camera permissions to a malicious origin.
- Call
ImageCapture.takePhoto()to initiate a capture operation. - Immediately call
MediaStreamTrack.stop()to triggerstopCaptureandInvalidateWeakPtrs()on the main thread. - If the camera callback arrives exactly during the invalidation, the race may trigger the UAF on the
WeakReference::Flag. - If successful, a corrupted task is posted to the main thread that may dereference a dangling pointer to the
VideoCaptureDeviceAVFoundationobject or its internalSelfHolderstruct.
Suggested Fix
Ensure that all calls to InvalidateWeakPtrs() on _weakPtrHolderForTakePhoto.weak_ptr_factory are performed while holding _lock, or ensure that GetWeakPtr() is only ever called from the main thread. A common pattern is to create the WeakPtr on the main thread when initiating the request and passing it to the background callback context.
Evaluated with Chrome root at commit: b3153093eb3c78c3e88ccf562bcbc20437a04b0e
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
The WeakPtrFactory is invalidated on the main thread without holding the class lock, while a background thread may call GetWeakPtr() under the lock, violating the single-sequence requirement for WeakPtrFactory.
Impact
This could lead to arbitrary code execution in a highly privileged process (unsandboxed utility process on macOS, browser process on iOS), but it requires camera permissions and a precise timing race.
What the attacker needed
Camera permissions granted; malicious web content; precise timing of camera callback
The fix
All calls to InvalidateWeakPtrs() should be made while holding the class lock, or GetWeakPtr() should only be called from the main thread.
How it was found
- Grant camera permissions to a malicious origin.
- Call ImageCapture.takePhoto() to start a capture.
- Immediately call MediaStreamTrack.stop() to trigger stopCapture and InvalidateWeakPtrs() on the main thread.
- If the camera callback arrives during invalidation, the race may trigger a use-after-free on the WeakReference::Flag.
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 WeakPtrFactory is a helper that lets code safely check whether an object still exists before using it. Here, two threads (independent sequences of execution) use the same helper at the same time without proper locking, so one thread can free memory while the other is still reading it. That memory error can be abused to run attacker-controlled code, especially because the affected process has high privileges.
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.