Use after free in WebCodecs (CVE-2024-2886)
A use-after-free in Chromium's WebCodecs code arises from the incorrect assumption that PinArrayBufferContent() keeps the backing store from being reallocated. An attacker could trigger an immediate crash, and the reporter argues the flaw is likely exploitable through data races on non-shared ArrayBuffers.
Originally disclosed on Chrome VRP
- Fix shipped in 6 days
This is a sub-bug from the primary pwn2own bug. This is tracking the memory safety issues from the incorrect assumption that PinArrayBufferContent() prevents the backing store itself from being reallocated. I am going to leave the full details in the main bug, but I am breaking this one out separately to track fixes:
- Run a webserver to serve the given
poc.htmlfile (e.g.python3 -m http.server -b 127.0.0.1 8000) - Start Chrome or Edge
- Assert that hardware accelerated compositing is enabled.
- Visit
chrome://gpu - Check that
Compositing: Hardware accelerated - If not, kill all
chrome.exeormsedge.exeprocess and retry from step 2 with--ignore-gpu-blocklistflag added (if this still fails, hardware is likely ancient or is lacking proper graphics driver support) - Browse to
http://127.0.0.1:8000/poc.html - Result should be an immediate crash with
STATUS_ACCESS_VIOLATION.
The reporter also notes that:
Triggering the bug via
ArrayBuffer.prototype.transferand its variants is blocked behind--harmony-rab-gsab-transferflag from M105 which is later enabled by default in M114 (commit 6387763c).
And has a non-transfer-based version to trigger this as well; that being said, I believe the underlying flaw is the same.
This bug is still likely to be exploitable without ArrayBuffer.prototype.transfer by exploiting data races on non-shared ArrayBuffers, for example with the following execution order:
- Create ArrayBuffer
abon main JS thread - Create a worker thread
- Dispatch
VideoFrame.copyTo(ab)operation - Zero-copy transfer
abto the worker thread viapostMessage()
- Now the worker thread is able to operate on the ArrayBuffer concurrently with the main JS thread
- Race the two operations:
- Worker thread: Either one of the following:
- Optimized
TypedArray.prototype.sort()usingstd::sort(), similar to https://chromium-review.googlesource.com/c/v8/v8/+/1581641 - WASM compiling non-shared ArrayBuffer, similar to https://issues.chromium.org/issues/40088842
- Optimized
- Main JS thread: Copy operation in
ReadbackDone()
I've confirmed that the data race does trigger by hitting a check (
int 3; ud2;) withTypedArray.prototype.sort()- this is included in the attachments aspoc_no_transfer.html[...]
And finally the reporter's thoughts on a fix:
Stop acquiring raw pointers and
base::spanofArrayBuffer-like objects across awaitable points or threaded operations. Either steal the underlying backing store as if we detach the buffer (this violates spec), or mark the buffer as shared (only internally). Marking it as shared should not actually make it a SharedArrayBuffer, but instead should result in all non-shared ArrayBuffer optimizations to be avoided while being internally shared
And followup work that would be good to carry out (but IMO out of scope here):
Validate and mark all unsafe buffer usages as per https://issues.chromium.org/issues/40284755, notably initial spanification points that are worthy of marking
UNSAFE_BUFFERS()
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 code assumed PinArrayBufferContent() kept the ArrayBuffer backing store alive and stable, but the backing store could still be reallocated while a raw pointer or span was held across an awaitable or threaded operation.
Impact
The proof of concept causes an immediate browser crash, and the reporter believes the same flaw is likely exploitable without the transfer API by racing a copy operation against worker-thread buffer operations.
What the attacker needed
Victim visits a crafted page; hardware accelerated compositing enabled
The fix
The reporter recommends never holding raw pointers or spans of ArrayBuffer-like objects across awaitable or threaded operations, and instead stealing the backing store or internally marking the buffer as shared; the text does not state that a fix was applied.
How it was found
- Serve the proof-of-concept HTML file from a local web server.
- Start Chrome or Edge and confirm hardware accelerated compositing is enabled via chrome://gpu.
- If compositing is not hardware accelerated, kill the browser processes and restart with the ignore-gpu-blocklist flag.
- Browse to the proof-of-concept page.
- Observe an immediate crash with STATUS_ACCESS_VIOLATION.
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 program can hold a reference to a block of memory (a buffer) while another part of the program frees or moves that memory. If the first part then keeps using the old reference, it reads or writes memory that no longer belongs to it, which is called a use-after-free. Here the browser's media code made that mistake, so a crafted page could crash the browser and might be turned into code execution.
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.