Use after free in ANGLE (CVE-2026-9877)
A use-after-free write exists in ANGLE's EGL image creation because a deferred lambda captures a member variable by reference and runs after the global EGL lock is released. A concurrent thread can destroy the object and cause a write into freed memory, potentially leading to arbitrary read/write and sandbox escape.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 2 months
Project Fortify, an experimental security project, has identified the following potential security issue.
Overview: A potential Use-After-Free (UAF) write vulnerability exists in ANGLE's EGL image creation logic. A deferred lambda captures a member variable by reference and executes after the global EGL lock is released, allowing a concurrent thread to destroy the object and trigger a write into freed memory.
Affected files:
third_party/angle/src/libANGLE/renderer/gl/egl/ImageEGL.cppthird_party/angle/src/libGLESv2/entry_points_egl_autogen.cppthird_party/angle/src/libGLESv2/entry_points_egl_ext_autogen.cppthird_party/angle/src/libANGLE/renderer/gl/egl/ImageEGL.h
Estimated timestamp from git blame: 2024-04-29
Vulnerability Details
In ANGLE's GL/EGL backend, ImageEGL::initialize defers the actual driver-level image creation using UnlockedTailCall to avoid holding the global EGL lock during potentially slow operations. The deferred lambda captures the mImage member variable by reference (&image = mImage):
// third_party/angle/src/libANGLE/renderer/gl/egl/ImageEGL.cpp
egl::Display::GetCurrentThreadUnlockedTailCall()->add([egl = mEGL, &image = mImage, ...](void *resultOut) {
image = egl->createImageKHR(context, target, buffer, attributes.data());
// ...
});
In the autogenerated EGL entry points (e.g., EGL_CreateImage), the ANGLE_SCOPED_GLOBAL_LOCK() is released just before UnlockedTailCall::run() is invoked.
Because the newly created frontend egl::Image is inserted into the display's global mImageMap before the lock is released, it becomes visible to other threads. A concurrent thread can guess the predictable ImageID (allocated sequentially by HandleAllocator) and call eglDestroyImage. This destroys the egl::Image and its backend ImageEGL object, freeing its memory. When the original thread resumes and executes the tail call lambda, it writes the newly created 8-byte driver handle into the image reference, resulting in a Use-After-Free write.
Potential Trigger Steps
Note: These are suggested steps generated by an AI agent that does not have the ability to run or verify code. They represent a theoretical exploitation sequence.
- Predict ID: An attacker in the Renderer process predicts the next
ImageIDto be allocated, as ANGLE'sHandleAllocatorallocates IDs sequentially from 1. - Trigger Creation: The attacker triggers an IPC call that invokes
EGL_CreateImageon Thread A in the GPU process. Thread A allocates the object, queues the lambda, adds the image tomImageMap, and releases the global EGL lock. - Concurrent Destruction: Before Thread A executes the tail call, the attacker uses a concurrent Web Worker to trigger
eglDestroyImageon Thread B, providing the predictedImageID. - Free Memory: Thread B successfully acquires the lock, finds the image in
mImageMap, and destroys it. The memory forImageEGL(which falls into the 64-byte PartitionAlloc bucket) is freed. - Heap Grooming: The attacker immediately allocates controlled data of the same size (e.g., by supplying a 16-element attribute list to another EGL function or using WebGL queries) to reclaim the freed 64-byte chunk.
- UAF Write: Thread A executes the pending
UnlockedTailCalllambda. The native driver creates the EGL image and writes its 8-byte handle into the captured&imagereference, corrupting the attacker's overlapping object.
Impact
This flaw provides a controlled 8-byte UAF write in the GPU process. An attacker can overlap the freed ImageEGL object with another object to overwrite a critical pointer or size field, leading to arbitrary read/write and potentially a sandbox escape (Remote Code Execution in the GPU process). MiraclePtr (BackupRefPtr) does not mitigate this because the dangling pointer is held as a native C++ reference inside the std::function closure.
Suggested Fix
There are a few ways to resolve this race condition:
- Extend Lifetime: Have the lambda capture a strong reference to the frontend
egl::Imageobject to keep theImageEGLbackend object alive until the tail call completes. - Avoid Reference Captures: Do not capture
mImageby reference. Instead, have the tail call return the driver handle via theresultOutpointer, and let the caller assign it safely if the object still exists. - Defer Map Insertion: Do not insert the newly created
egl::Imageinto the globalmImageMapuntil after theUnlockedTailCallhas successfully finished executing.
Evaluated with Chrome root at commit: 0eb4855bda702feaaa8b899336664f97e3df88b8
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. Please feel free to reach out to me if you have concerns or feedback.
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 deferred lambda captures the mImage member by reference and the frontend image is inserted into the global map before the lock is released, so another thread can destroy it before the lambda writes to the captured reference.
Impact
This flaw provides a controlled 8-byte UAF write in the GPU process, which could lead to arbitrary read/write and potentially a sandbox escape (Remote Code Execution in the GPU process).
What the attacker needed
Attacker in the Renderer process; ability to trigger EGL_CreateImage; concurrent Web Worker; predictable ImageID
The fix
The race condition should be fixed by extending the lifetime of the frontend image, avoiding reference captures, or deferring map insertion until after the tail call completes.
How it was found
- Predict the next ImageID to be allocated, since IDs are sequential.
- Trigger EGL_CreateImage on Thread A, which allocates the object, queues the lambda, adds it to the map, and releases the lock.
- Use a concurrent Web Worker to call eglDestroyImage on Thread B with the predicted ID before Thread A runs the tail call.
- Thread B destroys the image, freeing the ImageEGL memory in the 64-byte bucket.
- Heap groom by allocating controlled data of the same size to reclaim the freed chunk.
- Thread A executes the pending lambda, writing the 8-byte driver handle into the freed memory.
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.
When a program creates an image, it briefly unlocks a shared resource so other threads can run. One thread can then delete the image while the first thread still holds a pointer to it, and when the first thread writes to that pointer, it writes into memory that has been freed. This is called a use-after-free bug, and it can let an attacker control what gets written where.
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.