Use after free in Canvas (CVE-2024-2627)
A use-after-free flaw in Chromium's Canvas implementation occurs when ResetInternal obtains a PaintCanvas pointer, then WillDraw triggers CheckForGpuContextLost which may destroy the canvas resource provider, and the stale pointer is used for drawRect. An attacker could potentially exploit this to cause memory corruption, though the report does not demonstrate a full exploit.
- Fix shipped in 59 days
##Reproduce The issue was found by code review, and I will provide a POC later.
##RCA Similar to the issue(1511567) I previously reported.
- ResetInternal calls GetPaintCanvas to get the PaintCanvas object pointer c[1], which is valid at this time.
- Then WillDraw[2] is called, and WillDraw will call CheckForGpuContextLost, which may cause the "canvas resource provider" to be destroyed.
- Ultimately, c->drawRect()[3] uses the PaintCanvas object pointer c obtained in step 1, resulting in an UAF.
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc;drc=3cc22c22d7637bc5604e8fef3b0882b51a762901;l=437
void BaseRenderingContext2D::ResetInternal() {
if (UNLIKELY(identifiability_study_helper_.ShouldUpdateBuilder())) {
identifiability_study_helper_.UpdateBuilder(CanvasOps::kReset);
}
ValidateStateStack();
state_stack_.resize(1);
state_stack_.front() = MakeGarbageCollected<CanvasRenderingContext2DState>();
layer_count_ = 0;
SetIsTransformInvertible(true);
CanvasPath::Clear();
RestartRecording();
// Clear the frame in case a flush previously drew to the canvas surface.
if (cc::PaintCanvas* c = GetPaintCanvas()) { << [1]
int width = Width(); // Keeping results to avoid repetitive virtual calls.
int height = Height();
WillDraw(SkIRect::MakeXYWH(0, 0, width, height), << [2]
CanvasPerformanceMonitor::DrawType::kOther);
c->drawRect(SkRect::MakeXYWH(0.0f, 0.0f, width, height), GetClearFlags()); << [3]
}
ValidateStateStack();
origin_tainted_by_content_ = false;
}
//CALL HIERARCHY
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (1 result)
590: CheckForGpuContextLost() {... ResourceProvider()->IsGpuContextLost()) { ...}
third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.cc (1 result)
193: GetOrCreateCanvasResourceProvider() {... host->CheckForGpuContextLost(); ...}
third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.cc (9 results)
155: FinalizeFrame( reason) {... if (!GetOrCreateCanvasResourceProvider()) ...}
third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.cc (4 results)
231: PushFrame() {... FinalizeFrame(FlushReason::kOffscreenCanvasPushFrame); ...}
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (1 result)
536: PushFrameIfNeeded() {... return context_->PushFrame(); ...}
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (1 result)
536: PushFrameIfNeeded() {... return context_->PushFrame(); ...}
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (1 result, 18 displayed)
521: BeginFrame() {... return PushFrameIfNeeded(); ...}
third_party/blink/renderer/platform/graphics/canvas_resource_dispatcher.cc (2 results, 18 displayed)
344: SetNeedsBeginFrame( needs_begin_frame) {... Client()->BeginFrame(); ...}
third_party/blink/renderer/core/html/canvas/html_canvas_element.cc (1 result)
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (2 results, 4 displayed)
514: DidDraw(const rect) {... GetOrCreateResourceDispatcher()->SetNeedsBeginFrame(true); ...}
third_party/blink/renderer/core/html/canvas/canvas_rendering_context.cc (1 result)
third_party/blink/renderer/core/html/canvas/canvas_rendering_context_host.h (1 result)
third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.cc (1 result)
333: WillDraw(const dirty_rect, draw_type) {... Host()->DidDraw(dirty_rect_for_commit_); ...}
third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc (5 results)
453: ResetInternal() {... WillDraw(SkIRect::MakeXYWH(0, 0, width, height), ...}
What the report shows
This is a Chrome VRP advisory for a use-after-free in the Canvas code of Chromium, tracked as CVE-2024-2627. The affected feature is the 2D canvas rendering path, and the report is filed against the Canvas component. The researcher is listed as anonymous, the severity is medium, and the bounty was 4,000 USD.
The issue was found by code review rather than by fuzzing or by driving a browser. The report says a proof of concept would be provided later, so the text itself contains no HTML, JavaScript or steps to trigger the bug. What it does contain is a root cause analysis and a call hierarchy taken from the Chromium source.
The researcher notes that the bug is similar to an earlier issue they previously reported, 1511567. The analysis walks through BaseRenderingContext2D::ResetInternal:
ResetInternalcallsGetPaintCanvasto obtain thePaintCanvasobject pointerc, which is valid at that moment.WillDrawis then called, andWillDrawcallsCheckForGpuContextLost, which may cause the canvas resource provider to be destroyed.c->drawRect()then uses thePaintCanvaspointercobtained in step 1, producing a use-after-free.
The relevant source is quoted with line markers for the three steps:
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc;drc=[redacted];l=437
void BaseRenderingContext2D::ResetInternal() {
if (UNLIKELY(identifiability_study_helper_.ShouldUpdateBuilder())) {
identifiability_study_helper_.UpdateBuilder(CanvasOps::kReset);
}
ValidateStateStack();
state_stack_.resize(1);
state_stack_.front() = MakeGarbageCollected<CanvasRenderingContext2DState>();
layer_count_ = 0;
SetIsTransformInvertible(true);
CanvasPath::Clear();
RestartRecording();
// Clear the frame in case a flush previously drew to the canvas surface.
if (cc::PaintCanvas* c = GetPaintCanvas()) { << [1]
int width = Width(); // Keeping results to avoid repetitive virtual calls.
int height = Height();
WillDraw(SkIRect::MakeXYWH(0, 0, width, height), << [2]
CanvasPerformanceMonitor::DrawType::kOther);
c->drawRect(SkRect::MakeXYWH(0.0f, 0.0f, width, height), GetClearFlags()); << [3]
}
ValidateStateStack();
origin_tainted_by_content_ = false;
}
The report also includes the call hierarchy that connects ResetInternal to the GPU context loss check, spanning the offscreen canvas, canvas resource dispatcher and HTML canvas element files:
//CALL HIERARCHY
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (1 result)
590: CheckForGpuContextLost() {... ResourceProvider()->IsGpuContextLost()) { ...}
third_party/blink/renderer/modules/canvas/offscreencanvas2d/[redacted].cc (1 result)
193: GetOrCreateCanvasResourceProvider() {... host->CheckForGpuContextLost(); ...}
third_party/blink/renderer/modules/canvas/offscreencanvas2d/[redacted].cc (9 results)
155: FinalizeFrame( reason) {... if (!GetOrCreateCanvasResourceProvider()) ...}
third_party/blink/renderer/modules/canvas/offscreencanvas2d/[redacted].cc (4 results)
231: PushFrame() {... FinalizeFrame(FlushReason::kOffscreenCanvasPushFrame); ...}
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (1 result)
536: PushFrameIfNeeded() {... return context_->PushFrame(); ...}
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (1 result)
536: PushFrameIfNeeded() {... return context_->PushFrame(); ...}
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (1 result, 18 displayed)
521: BeginFrame() {... return PushFrameIfNeeded(); ...}
third_party/blink/renderer/platform/graphics/canvas_resource_dispatcher.cc (2 results, 18 displayed)
344: SetNeedsBeginFrame( needs_begin_frame) {... Client()->BeginFrame(); ...}
third_party/blink/renderer/core/html/canvas/html_canvas_element.cc (1 result)
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (2 results, 4 displayed)
514: DidDraw(const rect) {... GetOrCreateResourceDispatcher()->SetNeedsBeginFrame(true); ...}
third_party/blink/renderer/core/html/canvas/canvas_rendering_context.cc (1 result)
third_party/blink/renderer/core/html/canvas/canvas_rendering_context_host.h (1 result)
third_party/blink/renderer/modules/canvas/offscreencanvas2d/[redacted].cc (1 result)
333: WillDraw(const dirty_rect, draw_type) {... Host()->DidDraw(dirty_rect_for_commit_); ...}
third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc (5 results)
453: ResetInternal() {... WillDraw(SkIRect::MakeXYWH(0, 0, width, height), ...}
Root cause
The likely mistake is a stale pointer held across a call that can invalidate it. ResetInternal caches the PaintCanvas pointer returned by GetPaintCanvas, then calls WillDraw. That call reaches CheckForGpuContextLost, which can tear down the canvas resource provider backing the paint canvas. When control returns, the cached pointer is dereferenced by drawRect. The code assumes the object stays alive for the duration of the function, but a callback in the middle of the function breaks that assumption.
Impact
The report describes the bug as a use-after-free, and the platform rates it medium. A use-after-free in a renderer gives an attacker a path to memory corruption, which in a browser is the first step towards code execution in the renderer process. The report itself does not describe an exploit, a sandbox escape or any demonstrated consequence, so the practical impact beyond the memory safety violation is not established in the text.
How this kind of bug works
A use-after-free happens when code keeps a pointer or reference to an object, the object is freed through another path, and the pointer is then used. In garbage-collected or reference-counted systems the free usually comes from a callback, a re-entrant call or an event that runs between the acquisition and the use. The classic pattern is exactly what this report shows: fetch a pointer, call something that can trigger cleanup, then use the pointer.
Defences fall into three groups. Ownership rules that forbid holding raw pointers across calls that can mutate state, with smart pointers or handles used instead. Lifetime checks such as weak pointers that become invalid when the object dies, so the use can be detected and skipped. And memory hardening at the allocator and compiler level, such as quarantine, pointer authentication and heap partitioning, which makes exploitation harder but does not remove the bug.
How to test for it
- Look for code that stores a pointer or reference, then calls into another component before using it. Review is the most reliable route, which is how this bug was found.
- Identify the callbacks that can free or replace the object: context loss, resize, navigation, garbage collection, frame boundaries.
- Build a page that drives the object into that state between the acquisition and the use. For canvas, that means forcing a GPU context loss while a drawing operation is in flight.
- Run the page under AddressSanitizer or a debug build of the browser. A positive result is a crash report naming the freed allocation and the later read or write.
- Confirm the crash is reproducible and tied to the sequence, not to an unrelated failure.
Common false positives are crashes caused by out-of-memory conditions, by the test harness itself, or by a different bug in the same area. A crash alone is not proof; the sanitizer report must show the free and the use on the same object.
How it is fixed
Where the object can legitimately disappear, the code should check for validity before use.
Hunting notes
This class of bug hides in rendering and graphics code, in event dispatch, in asynchronous frame callbacks and anywhere a function calls out to code it does not control. Recon signals include large C++ codebases with manual pointer management, frequent refactors around ownership, and components that interact with the GPU process.
What happened, in plain words
The bug is tracked as CVE-2024-2627, a use-after-free in the Canvas part of Chromium, the open-source project Chrome is built from. The researcher is listed as anonymous, the severity is medium, and the bounty was 4,000 USD.
Canvas is the feature of a web page that lets JavaScript draw pictures, charts and animations inside a rectangle on the screen. A page can also use an offscreen canvas, which draws into memory without being shown directly, often so the work can be handed to the graphics processor (GPU).
The bug was found by reading the Chromium source code, not by running a browser or by automated testing. The report says a proof of concept would be provided later, so the text contains no HTML, JavaScript or click-by-click steps to trigger it. What it does contain is a root cause analysis and a call hierarchy taken from the source.
The researcher notes the bug is similar to an earlier issue they previously reported, 1511567. The analysis walks through one function, BaseRenderingContext2D::ResetInternal, in three steps:
ResetInternalcallsGetPaintCanvasto obtain thePaintCanvasobject pointerc, which is valid at that moment.WillDrawis then called, andWillDrawcallsCheckForGpuContextLost, which may cause the canvas resource provider to be destroyed.c->drawRect()then uses thePaintCanvaspointercobtained in step 1, producing a use-after-free.
A pointer is simply a note of where an object lives in memory. A use-after-free means the code keeps that note, the object is thrown away through another path, and the code then uses the note as if the object were still there. It is like writing down a friend's address, the friend moves out, and you still post a letter to the old house.
The report quotes the relevant source with markers for the three steps:
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc;drc=[redacted];l=437
void BaseRenderingContext2D::ResetInternal() {
if (UNLIKELY(identifiability_study_helper_.ShouldUpdateBuilder())) {
identifiability_study_helper_.UpdateBuilder(CanvasOps::kReset);
}
ValidateStateStack();
state_stack_.resize(1);
state_stack_.front() = MakeGarbageCollected<CanvasRenderingContext2DState>();
layer_count_ = 0;
SetIsTransformInvertible(true);
CanvasPath::Clear();
RestartRecording();
// Clear the frame in case a flush previously drew to the canvas surface.
if (cc::PaintCanvas* c = GetPaintCanvas()) { << [1]
int width = Width(); // Keeping results to avoid repetitive virtual calls.
int height = Height();
WillDraw(SkIRect::MakeXYWH(0, 0, width, height), << [2]
CanvasPerformanceMonitor::DrawType::kOther);
c->drawRect(SkRect::MakeXYWH(0.0f, 0.0f, width, height), GetClearFlags()); << [3]
}
ValidateStateStack();
origin_tainted_by_content_ = false;
}
Line by line, the parts that matter:
if (cc::PaintCanvas* c = GetPaintCanvas())asks for the paint canvas and stores its address inc. Marker[1]marks this moment: the object is alive and the address is good.WillDraw(...)tells the rest of the drawing system that a draw is about to happen. Marker[2]marks this call. The problem is that this call can run other code, and that other code can destroy the objectcpoints to.c->drawRect(...)draws a rectangle using the address saved earlier. Marker[3]marks the use. If the object was destroyed in between, this reads or writes memory that no longer belongs to it.
The report also includes the call hierarchy that connects ResetInternal to the GPU context loss check, spanning the offscreen canvas, canvas resource dispatcher and HTML canvas element files:
//CALL HIERARCHY
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (1 result)
590: CheckForGpuContextLost() {... ResourceProvider()->IsGpuContextLost()) { ...}
third_party/blink/renderer/modules/canvas/offscreencanvas2d/[redacted].cc (1 result)
193: GetOrCreateCanvasResourceProvider() {... host->CheckForGpuContextLost(); ...}
third_party/blink/renderer/modules/canvas/offscreencanvas2d/[redacted].cc (9 results)
155: FinalizeFrame( reason) {... if (!GetOrCreateCanvasResourceProvider()) ...}
third_party/blink/renderer/modules/canvas/offscreencanvas2d/[redacted].cc (4 results)
231: PushFrame() {... FinalizeFrame(FlushReason::kOffscreenCanvasPushFrame); ...}
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (1 result)
536: PushFrameIfNeeded() {... return context_->PushFrame(); ...}
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (1 result)
536: PushFrameIfNeeded() {... return context_->PushFrame(); ...}
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (1 result, 18 displayed)
521: BeginFrame() {... return PushFrameIfNeeded(); ...}
third_party/blink/renderer/platform/graphics/canvas_resource_dispatcher.cc (2 results, 18 displayed)
344: SetNeedsBeginFrame( needs_begin_frame) {... Client()->BeginFrame(); ...}
third_party/blink/renderer/core/html/canvas/html_canvas_element.cc (1 result)
third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.cc (2 results, 4 displayed)
514: DidDraw(const rect) {... GetOrCreateResourceDispatcher()->SetNeedsBeginFrame(true); ...}
third_party/blink/renderer/core/html/canvas/canvas_rendering_context.cc (1 result)
third_party/blink/renderer/core/html/canvas/canvas_rendering_context_host.h (1 result)
third_party/blink/renderer/modules/canvas/offscreencanvas2d/[redacted].cc (1 result)
333: WillDraw(const dirty_rect, draw_type) {... Host()->DidDraw(dirty_rect_for_commit_); ...}
third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc (5 results)
453: ResetInternal() {... WillDraw(SkIRect::MakeXYWH(0, 0, width, height), ...}
This is a map of who calls whom, read from the bottom up. ResetInternal calls WillDraw, which calls DidDraw, which asks for a new frame, which eventually reaches CheckForGpuContextLost. That check can tear down the canvas resource provider, the object that backs the paint canvas. So a call that looks like a simple notification can, several steps later, free the very object the caller is still holding.
The likely mistake is a stale pointer held across a call that can invalidate it. The code assumes the object stays alive for the whole function, but a callback in the middle breaks that assumption.
On impact: the report describes the bug as a use-after-free, and the platform rates it medium. A use-after-free in a renderer gives an attacker a path to memory corruption, which in a browser is the first step towards code execution in the renderer process. The report itself does not describe an exploit, a sandbox escape or any demonstrated consequence, so the practical impact beyond the memory safety violation is not established in the text.
In general, how this kind of bug works
A use-after-free happens when code keeps a pointer or reference to an object, the object is freed through another path, and the pointer is then used. In garbage-collected or reference-counted systems the free usually comes from a callback, a re-entrant call or an event that runs between the acquisition and the use. The classic pattern is exactly what this report shows: fetch a pointer, call something that can trigger cleanup, then use the pointer.
Defences fall into three groups. Ownership rules that forbid holding raw pointers across calls that can mutate state, with smart pointers or handles used instead. Lifetime checks such as weak pointers that become invalid when the object dies, so the use can be detected and skipped. And memory hardening at the allocator and compiler level, such as quarantine, pointer authentication and heap partitioning, which makes exploitation harder but does not remove the bug.
How to test for it
- Look for code that stores a pointer or reference, then calls into another component before using it. Review is the most reliable route, which is how this bug was found.
- Identify the callbacks that can free or replace the object: context loss, resize, navigation, garbage collection, frame boundaries.
- Build a page that drives the object into that state between the acquisition and the use. For canvas, that means forcing a GPU context loss while a drawing operation is in flight.
- Run the page under AddressSanitizer or a debug build of the browser. A positive result is a crash report naming the freed allocation and the later read or write.
- Confirm the crash is reproducible and tied to the sequence, not to an unrelated failure.
Common false positives are crashes caused by out-of-memory conditions, by the test harness itself, or by a different bug in the same area. A crash alone is not proof; the sanitizer report must show the free and the use on the same object.
How it is fixed
Where the object can legitimately disappear, the code should check for validity before use.
Hunting notes
This class of bug hides in rendering and graphics code, in event dispatch, in asynchronous frame callbacks and anywhere a function calls out to code it does not control. Recon signals include large C++ codebases with manual pointer management, frequent refactors around ownership, and components that interact with the GPU process.
Glossary
- Advisory: a public notice describing a security bug, usually with an identifier and a severity rating.
- AddressSanitizer: a tool built into a program during testing that detects memory errors such as reading freed memory.
- Bounty: money paid by a vendor to a researcher who reports a valid security bug.
- Callback: code passed along to be run later by another part of the program, often at a moment the caller does not control.
- Canvas: a web page element that lets JavaScript draw graphics into a rectangle.
- Chromium: the open-source browser project that Google Chrome and several other browsers are built from.
- CVE: a public identifier for a specific known vulnerability.
- Garbage collection: automatic memory management where the system frees objects no longer in use.
- GPU: graphics processing unit, the chip that draws images; browsers often hand drawing work to it.
- GPU context loss: a situation where the connection to the graphics processor is lost, forcing the browser to tear down and rebuild graphics resources.
- Heap: the area of memory where a program stores objects it creates while running.
- Memory corruption: a state where a program reads or writes memory it should not, which can change its behaviour.
- Offscreen canvas: a canvas that draws into memory rather than directly on screen.
- Pointer: a value that records the memory address of an object.
- Proof of concept (PoC): a small example that demonstrates a bug actually happens.
- Renderer process: the sandboxed part of a browser that turns a web page into what you see.
- Root cause analysis (RCA): an explanation of the underlying reason a bug happens, not just its symptoms.
- Sandbox escape: a way for code inside a restricted process to break out and affect the rest of the system.
- Severity: a rating of how serious a bug is, here medium.
- Smart pointer: a pointer type that automatically manages the lifetime of the object it refers to.
- Stale pointer: a pointer that still holds an address after the object there has been freed or moved.
- Use-after-free (UAF): using an object after it has been freed, which can lead to memory corruption.
- VRP: Vulnerability Reward Program, a vendor scheme that pays for security bug reports.
- Weak pointer: a pointer that becomes invalid automatically when the object it refers to is destroyed.