heap-buffer-overflow write in add_line
A heap buffer overflow write occurs in Skia's anti-aliased hairline path renderer when preparing a canvas draw operation, triggered by a crafted HTML testcase. An attacker could crash the browser process, and the out-of-bounds write may allow memory corruption.
Originally disclosed on Mozilla
- Fixed in 5 days
- Paid in 9 days
- Disclosed after 5 days
Created attachment 9022386 heap-buffer-overflow-addline-prepare-GrRenderTargetOpListonPrepare.html
Tested on:
OS: Ubuntu 18.04
Firefox: Downloaded with fuzzfetch:
:$ fuzzfetch --target firefox --os Linux --asan --fuzzing [2018-11-03 19:51:41] > Task ID: eKR8so7vRgyEkAmBz42SeA [2018-11-03 19:51:41] > Rank: 1541238293 [2018-11-03 19:51:41] > Changeset: ef27c14b46bf58f710753ae6bb6d2c01a8c3631f [2018-11-03 19:51:41] > Build ID: 20181103094453
Firefox executed with ffpuppet using prefs.js from: https://github.com/MozillaSecurity/fuzzdata/blob/master/settings/firefox/prefs-default.js
The issue doesn't reproduce without the prefs.js.
To reproduce, use system with at least 8GB of RAM. Original reproducer caused mozalloc_abort with 4GB RAM, I minimized the testcase on a machine with 8GB of RAM.
ASAN-trace:
==94392==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7f2f4710c000 at pc 0x7f2f5b3ceb60 bp 0x7fffdcf23b70 sp 0x7fffdcf23b68 WRITE of size 4 at 0x7f2f4710c000 thread T0 #0 0x7f2f5b3ceb5f in add_line /builds/worker/workspace/build/src/gfx/skia/skia/src/gpu/ops/GrAAHairLinePathRenderer.cpp:695:30 #1 0x7f2f5b3ceb5f in (anonymous namespace)::AAHairlineOp::onPrepareDraws(GrMeshDrawOp::Target*) /builds/worker/workspace/build/src/gfx/skia/skia/src/gpu/ops/GrAAHairLinePathRenderer.cpp:989 #2 0x7f2f5b60286c in prepare /builds/worker/workspace/build/src/gfx/skia/skia/src/gpu/ops/GrOp.h:158:49 #3 0x7f2f5b60286c in GrRenderTargetOpList::onPrepare(GrOpFlushState*) /builds/worker/workspace/build/src/gfx/skia/skia/src/gpu/GrRenderTargetOpList.cpp:112 #4 0x7f2f5b5ba407 in GrOpList::prepare(GrOpFlushState*) /builds/worker/workspace/build/src/gfx/skia/skia/src/gpu/GrOpList.cpp:88:11 #5 0x7f2f5b597374 in GrDrawingManager::executeOpLists(int, int, GrOpFlushState*) /builds/worker/workspace/build/src/gfx/skia/skia/src/gpu/GrDrawingManager.cpp:386:17 #6 0x7f2f5b57d07c in GrDrawingManager::flush(GrSurfaceProxy*, int, GrBackendSemaphore*) /builds/worker/workspace/build/src/gfx/skia/skia/src/gpu/GrDrawingManager.cpp:304:23 #7 0x7f2f5b5877e4 in GrDrawingManager::prepareSurfaceForExternalIO(GrSurfaceProxy*, int, GrBackendSemaphore*) /builds/worker/workspace/build/src/gfx/skia/skia/src/gpu/GrDrawingManager.cpp:441:24 #8 0x7f2f5b5fcb2e in GrRenderTargetContext::prepareForExternalIO(int, GrBackendSemaphore*) /builds/worker/workspace/build/src/gfx/skia/skia/src/gpu/GrRenderTargetContext.cpp:1408:36 #9 0x7f2f51916dbd in mozilla::layers::PersistentBufferProviderBasic::ReturnDrawTarget(already_AddRefedmozilla::gfx::DrawTarget) /builds/worker/workspace/build/src/gfx/layers/PersistentBufferProvider.cpp:50:9 #10 0x7f2f55f61dd2 in mozilla::dom::CanvasRenderingContext2D::ReturnTarget(bool) /builds/worker/workspace/build/src/dom/canvas/CanvasRenderingContext2D.cpp:1949:22 #11 0x7f2f55f6694c in mozilla::dom::CanvasRenderingContext2D::OnStableState() /builds/worker/workspace/build/src/dom/canvas/CanvasRenderingContext2D.cpp:1550:3 #12 0x7f2f5606538b in applyImpl<mozilla::dom::CanvasRenderingContext2D, void (mozilla::dom::CanvasRenderingContext2D::)()> /builds/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:1191:12 #13 0x7f2f5606538b in apply<mozilla::dom::CanvasRenderingContext2D, void (mozilla::dom::CanvasRenderingContext2D::)()> /builds/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:1197 #14 0x7f2f5606538b in mozilla::detail::RunnableMethodImpl<mozilla::dom::CanvasRenderingContext2D*, void (mozilla::dom::CanvasRenderingContext2D::)(), true, (mozilla::RunnableKind)0>::Run() /builds/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:1242 #15 0x7f2f4e78fa67 in mozilla::CycleCollectedJSContext::ProcessStableStateQueue() /builds/worker/workspace/build/src/xpcom/base/CycleCollectedJSContext.cpp:366:12 #16 0x7f2f4e792822 in mozilla::CycleCollectedJSContext::AfterProcessTask(unsigned int) /builds/worker/workspace/build/src/xpcom/base/CycleCollectedJSContext.cpp:431:3 #17 0x7f2f50c266e5 in XPCJSContext::AfterProcessTask(unsigned int) /builds/worker/workspace/build/src/js/xpconnect/src/XPCJSContext.cpp:1288:30 #18 0x7f2f4e9d8adf in nsThread::ProcessNextEvent(bool, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1302:24 #19 0x7f2f4e9e091d in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:530:10 #20 0x7f2f4fc46eff in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:97:21 #21 0x7f2f4fb4325e in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:325:10 #22 0x7f2f4fb4325e in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:318 #23 0x7f2f4fb4325e in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:298 #24 0x7f2f58ab94d3 in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:158:27 #25 0x7f2f5cee1000 in nsAppStartup::Run() /builds/worker/workspace/build/src/toolkit/components/startup/nsAppStartup.cpp:290:30 #26 0x7f2f5d1afa2e in XREMain::XRE_mainRun() /builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4784:22 #27 0x7f2f5d1b2209 in XREMain::XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4929:8 #28 0x7f2f5d1b3ce3 in XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:5021:21 #29 0x56184ee2167c in do_main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:237:22 #30 0x56184ee2167c in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:329 #31 0x7f2f71aafb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310 #32 0x56184ed46eec in _start (/dev/shm/firefox/firefox+0x2deec)
0x7f2f4710c000 is located 6144 bytes to the left of 208584-byte region [0x7f2f4710d800,0x7f2f471406c8) allocated by thread T0 here: #0 0x56184edef1b2 in realloc /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:165:3 #1 0x56184ee2299d in moz_xrealloc /builds/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:93:20 #2 0x7f2f5bcb57fd in makeSpace /builds/worker/workspace/build/src/gfx/skia/skia/include/private/SkPathRef.h:472:46 #3 0x7f2f5bcb57fd in SkPathRef::growForVerb(int, float) /builds/worker/workspace/build/src/gfx/skia/skia/src/core/SkPathRef.cpp:677 #4 0x7f2f5bc8a24c in growForVerb /builds/worker/workspace/build/src/gfx/skia/skia/include/private/SkPathRef.h:77:30 #5 0x7f2f5bc8a24c in SkPath::moveTo(float, float) /builds/worker/workspace/build/src/gfx/skia/skia/src/core/SkPath.cpp:777 #6 0x7f2f5454f847 in MoveTo /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/dom/CanvasRenderingContext2D.h:320:21 #7 0x7f2f5454f847 in mozilla::dom::CanvasRenderingContext2D_Binding::moveTo(JSContext*, JS::Handle<JSObject*>, mozilla::dom::CanvasRenderingContext2D*, JSJitMethodCallArgs const&) /builds/worker/workspace/build/src/obj-firefox/dom/bindings/CanvasRenderingContext2DBinding.cpp:4915 #8 0x379d8f364c74 (<unknown module>) #9 0x379d8ef8a4e1 (<unknown module>)
SUMMARY: AddressSanitizer: heap-buffer-overflow /builds/worker/workspace/build/src/gfx/skia/skia/src/gpu/ops/GrAAHairLinePathRenderer.cpp:695:30 in add_line Shadow bytes around the buggy address: 0x0fe668e197b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0fe668e197c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0fe668e197d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0fe668e197e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0fe668e197f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x0fe668e19800:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0fe668e19810: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0fe668e19820: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0fe668e19830: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0fe668e19840: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0fe668e19850: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb Shadow gap: cc ==94392==ABORTING
Context
This is a Mozilla bug report about a memory safety defect in Firefox's graphics stack. The crash occurs in Skia, the 2D graphics library bundled with Firefox, specifically in the anti-aliased hairline path renderer (GrAAHairLinePathRenderer). The path is reached through the Canvas2D API: a page draws a path with moveTo and related calls, and when the canvas target is returned to the compositor the queued drawing operations are prepared for the GPU. During that preparation an out-of-bounds write happens in add_line.
The weakness class recorded for the report is an out-of-bounds access, and the platform lists it as high severity. The affected asset is Core: Graphics: Canvas2D.
Setup
The researcher tested on Ubuntu 18.04 with a Firefox build downloaded through fuzzfetch, using the ASAN and fuzzing options:
fuzzfetch --target firefox --os Linux --asan --fuzzing
The tool reported the following build details:
[2018-11-03 19:51:41] > Task ID: eKR8so7vRgyEkAmBz42SeA
[2018-11-03 19:51:41] > Rank: 1541238293
[2018-11-03 19:51:41] > Changeset: [redacted]
[2018-11-03 19:51:41] > Build ID: 20181103094453
Firefox was launched with ffpuppet using the prefs.js from MozillaSecurity's fuzzdata repository, at settings/firefox/prefs-default.js. That detail matters: the issue does not reproduce without those preferences, so the non-default configuration is a precondition for the crash.
There is also a hardware precondition. The system needs at least 8GB of RAM. The original reproducer caused mozalloc_abort on a machine with 4GB of RAM, and the testcase was minimised on a machine with 8GB.
The report includes a minimised testcase as an attachment named heap-buffer-overflow-addline-prepare-GrRenderTargetOpListonPrepare.html. The report text does not reproduce the contents of that file.
Finding it
The crash was observed on an ASAN-instrumented build. The signal is an AddressSanitizer report of a heap-buffer-overflow, a WRITE of size 4, at an address that sits 6144 bytes to the left of a 208584-byte heap region. The write happens in add_line in gfx/skia/skia/src/gpu/ops/GrAAHairLinePathRenderer.cpp at line 695, column 30.
The allocation that the write runs off the front of is a Skia path buffer. The allocation stack shows SkPathRef::growForVerb reaching makeSpace in SkPathRef.h, called from SkPath::moveTo, which is in turn called from the Canvas2D binding [redacted]::moveTo. In other words, the buffer was grown while a page was building a canvas path, and the overflow happens later, when that path is rendered as an anti-aliased hairline.
Exploitation
The steps below follow the call chain recorded in the ASAN trace.
Step 1: build the path from page script
Page JavaScript calls moveTo on a Canvas2D context. The allocation stack records the call chain:
This grows the Skia path buffer through SkPathRef::growForVerb and makeSpace. The resulting region is 208584 bytes, starting at 0x7f2f4710d800 and ending at 0x7f2f471406c8.
Step 2: let the canvas target be returned
When the canvas rendering context returns its draw target, the queued GPU operations are prepared. The stack shows the path from the DOM into Skia:
OnStableState runs from the stable state queue processed by CycleCollectedJSContext::ProcessStableStateQueue, so the flush is deferred to a stable state rather than happening inline in the script call.
Step 3: the write in add_line
During GrRenderTargetOpList::onPrepare, the queued AAHairlineOp prepares its draws and calls add_line:
ASAN reports the write of size 4 at 0x7f2f4710c000, which is 6144 bytes before the start of the path region. The shadow memory around the address is marked fa, the heap left redzone, confirming the access is to the left of the allocation.
==94392==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7f2f4710c000 at pc 0x7f2f5b3ceb60 bp 0x7fffdcf23b70 sp 0x7fffdcf23b68
WRITE of size 4 at 0x7f2f4710c000 thread T0
The full call chain from the write back to the event loop runs through GrDrawingManager::flush, GrDrawingManager::prepareSurfaceForExternalIO, GrRenderTargetContext::prepareForExternalIO, the canvas return path, the stable state queue, nsThread::ProcessNextEvent and the browser's message loop. The summary line is:
Root cause
The write in add_line indexes outside the path buffer that was allocated when the path was built. The buffer is grown by SkPathRef::growForVerb via makeSpace, and the overflow lands 6144 bytes before the start of that region, so the renderer is writing at a negative offset relative to the path data rather than past its end.
The report does not state the exact arithmetic in add_line that produces the negative offset, nor which property of the path (for example its geometry or verb sequence) triggers it. What the trace establishes is the sequence: a canvas path built through moveTo, an anti-aliased hairline draw queued for the GPU, and a write in add_line during op preparation that falls outside the path allocation.
The build is ASAN-instrumented, which is what turns the out-of-bounds write into an abort with a report. The crash also depends on the non-default prefs.js from fuzzdata, so the default configuration did not exercise the same path in the researcher's testing.
Impact
The report documents a heap-buffer-overflow write of size 4 in a canvas path rendering path. A write outside a heap allocation is memory corruption, and in a browser that means content-triggered corruption of the renderer's heap. The report does not demonstrate code execution, an information leak, or a sandbox escape, and it does not describe how reliably the out-of-bounds address can be influenced. The practical impact beyond the crash is therefore not established in the text.
Fix
It provides the minimised testcase and the ASAN trace, which is what a fix would be built from.
Variants to test
- Other path construction sequences. Build canvas paths with different combinations of
moveTo, line and curve verbs and render them as hairlines. A positive result is an ASAN report inadd_lineor elsewhere inGrAAHairLinePathRendererwith an address outside the path allocation. - Different stroke widths and anti-aliasing settings. The crashing op is the AA hairline op, so vary whether anti-aliasing is on and whether the stroke qualifies as a hairline. A positive result is the same
add_lineframe with a different allocation size or offset. - Different canvas sizes and path sizes. The allocation in the trace is 208584 bytes and the overflow is 6144 bytes before it. A positive result is a crash whose reported offset changes with path size, which would show the offset is derived from path data.
- Default versus fuzzdata preferences. Since the issue does not reproduce without the fuzzdata
prefs.js, test both configurations. A positive result in the default profile would widen the affected population considerably. - Lower memory machines. The original reproducer aborted in
mozalloc_abortwith 4GB of RAM. A positive result is a reproducible ASAN report on a machine with less memory than the minimisation environment.
Hunting notes
This kind of bug hides in the boundary between a JavaScript-facing drawing API and the GPU backend that consumes the recorded drawing operations. Canvas2D is the obvious surface, but the same pattern applies to any API that records geometry and replays it later during a flush: the allocation happens at record time and the indexing happens at prepare time, so a mismatch between the two is only visible when the deferred work runs.
The useful signals during triage are ASAN reports whose allocation stack and crash stack are in different subsystems, here SkPath::moveTo on the allocation side and add_line on the write side. That split tells you the bug is in how recorded geometry is interpreted, not in how it was created. A crash address that sits before the allocation, in the fa redzone, rather than after it, is worth noting: it points at a negative index rather than a simple overrun.
The report includes a minimised testcase, the build changeset and build ID, the launch tooling and preferences, and the ASAN trace with crash and allocation stacks. That is enough for a graphics memory-safety report to be triaged without further guesswork about the environment.
What happened, in plain words
A security researcher found a bug in Firefox, the web browser. When a web page asked Firefox to draw a particular kind of line on a canvas (the drawing area a page can use to paint shapes and pictures), Firefox wrote data in the wrong place in its own memory. It wrote just outside a block of memory it had set aside for the drawing, in the space just before that block rather than inside it.
Writing outside a reserved block is called a heap-buffer-overflow. "Heap" is the area of memory a program uses for things it creates while running, and "buffer" is a reserved chunk of that memory. "Overflow" means the program went past the chunk's edges. A useful comparison is a row of numbered lockers: each locker belongs to one person, and writing in the wrong locker damages someone else's property. Here Firefox wrote into memory that did not belong to the drawing.
The bug was found with a special build of Firefox that watches every memory access and stops the program the moment one goes out of bounds. That tool is called AddressSanitizer, or ASAN. Without it, the same mistake might have gone unnoticed or caused strange behaviour later.
The report is a crash reproduction, not a working attack. It shows how to make Firefox trip over the bug, and it includes the technical trace of where in the code the mistake happens. The platform records the weakness as an out-of-bounds access, rates it high severity, and lists the affected area as Core: Graphics: Canvas2D.
Background: the pieces involved
Before walking through the report, here are the parts of Firefox it touches.
- Canvas2D is a feature web pages use to draw. A page gets a drawing surface and calls instructions such as "start a line here" and "draw a line to there". The browser records those instructions and later turns them into pixels.
- Skia is the 2D graphics library bundled inside Firefox. It does the actual drawing work, including on the graphics card (the GPU).
- A path is a shape described as a series of points and line or curve instructions. When a page calls
moveTo, it is starting a new part of a path at a given point. - Anti-aliasing smooths jagged edges by blending colours along the border of a shape. A hairline is a line so thin that it is drawn as a single hair's width rather than as a filled shape.
- The GPU is the graphics processor. Firefox hands drawing work to it in batches. The code that organises those batches is where the crash happens.
- An API is a defined set of instructions one piece of software offers to another. Canvas2D is an API that web pages use to ask the browser to draw.
- A preference (
prefs.js) is a browser setting stored in a file. Firefox has many, and some change how graphics are handled.
Setup
The researcher tested on Ubuntu 18.04, a version of the Linux operating system. The Firefox build was downloaded with a tool called fuzzfetch, which fetches special test builds from Mozilla's build system. The options asked for a Linux build with ASAN instrumentation and fuzzing support enabled:
fuzzfetch --target firefox --os Linux --asan --fuzzing
Line by line:
fuzzfetchruns the download tool.--target firefoxsays the product wanted is Firefox itself, not some other component.--os Linuxselects a Linux build.--asanasks for a build compiled with AddressSanitizer, the memory-watching tool. This is what turns a bad memory access into a clear, immediate error report.--fuzzingasks for the fuzzing variant of the build, which is set up for automated testing.
The tool printed the build details it had fetched:
[2018-11-03 19:51:41] > Task ID: eKR8so7vRgyEkAmBz42SeA
[2018-11-03 19:51:41] > Rank: 1541238293
[2018-11-03 19:51:41] > Changeset: [redacted]
[2018-11-03 19:51:41] > Build ID: 20181103094453
What each line means:
- The timestamp shows when the download happened.
Task IDidentifies the build job on Mozilla's build servers.Rankis a scheduling number used by that build system.Changesetis the exact version of the source code the build was made from. It lets anyone else fetch the same code.Build IDis the identifier stamped on that particular compiled build.
Firefox was then launched with another tool, ffpuppet, using a preferences file taken from MozillaSecurity's fuzzdata repository, at settings/firefox/prefs-default.js. This matters a great deal: the researcher states that the issue does not reproduce without those preferences. In other words, the crash depends on a non-default configuration. A preference file is just a list of settings; changing settings can change which code paths the browser takes, and here one of those paths is needed to reach the bug.
There is also a hardware requirement. The system needs at least 8GB of RAM. The original reproducer caused mozalloc_abort on a machine with 4GB of RAM, and the testcase was minimised on a machine with 8GB. mozalloc_abort is Firefox's own memory allocator giving up and stopping the program, which is what happened when there was not enough memory.
The report includes a minimised testcase as an attachment named heap-buffer-overflow-addline-prepare-GrRenderTargetOpListonPrepare.html. "Minimised" means the researcher shrank the original page down to the smallest version that still triggers the bug, which makes it easier to analyse. The contents of that file are not reproduced in the report text.
Finding it
The crash was observed on a build compiled with fuzzing support. The build was instrumented with ASAN, so when the bad write happened, ASAN produced a detailed report instead of letting the program continue with corrupted memory.
The signal is an AddressSanitizer report of a heap-buffer-overflow: a write of 4 bytes at an address that sits 6144 bytes to the left of a 208584-byte heap region. In plain terms, Firefox reserved a block of about 208,584 bytes for a drawing path, and then wrote 4 bytes into the space 6,144 bytes before the start of that block. That space is not part of the block, so the write is out of bounds.
The write happens in a function called add_line, in the file gfx/skia/skia/src/gpu/ops/GrAAHairLinePathRenderer.cpp, at line 695, column 30. The file name tells the story: it is the renderer for anti-aliased hairline paths.
The allocation that the write runs off the front of is a Skia path buffer. The allocation stack (the list of function calls that created the memory) shows SkPathRef::growForVerb reaching makeSpace in SkPathRef.h, called from SkPath::moveTo, which is in turn called from the Canvas2D binding [redacted]::moveTo. In other words, the buffer was grown while a page was building a canvas path, and the overflow happens later, when that path is rendered as an anti-aliased hairline. The creation and the misuse happen at different moments, which is why the two stacks point at different parts of the code.
Exploitation
The steps below follow the call chain recorded in the ASAN trace. They describe how to make the bug happen, not how to turn it into an attack.
Step 1: build the path from page script
Page JavaScript calls moveTo on a Canvas2D context. The allocation stack records the call chain:
Reading the lines from bottom to top, because that is the order the calls happened in:
#7is the binding layer, the code that connects a JavaScript call from the page to the browser's internal C++ code. The page asked to move the drawing position.#6is the internal Canvas2D method that handles the request.#5is Skia's path function that records the move.
This grows the Skia path buffer through SkPathRef::growForVerb and makeSpace. growForVerb means "make room for one more path instruction", and makeSpace is the helper that actually resizes the memory. The resulting region is 208584 bytes, starting at 0x7f2f4710d800 and ending at 0x7f2f471406c8. Those two addresses are the boundaries of the reserved block; anything outside them is not the path's memory.
Step 2: let the canvas target be returned
When the canvas rendering context returns its draw target, the queued GPU operations are prepared. The stack shows the path from the DOM (the browser's representation of the page) into Skia:
Again reading from bottom to top:
#11OnStableStateis called when the browser reaches a stable state, a moment when it is safe to do deferred work.#10ReturnTargethands the drawing target back.#9ReturnDrawTargetis the layer code that receives it and triggers the preparation of queued drawing operations.
OnStableState runs from the stable state queue processed by CycleCollectedJSContext::ProcessStableStateQueue, so the flush is deferred to a stable state rather than happening inline in the script call. In everyday terms, the page says "draw this", Firefox notes it down, and only later, at a convenient moment, does it actually prepare the drawing for the graphics card. The bug fires during that later preparation.
Step 3: the write in add_line
During GrRenderTargetOpList::onPrepare, the queued AAHairlineOp prepares its draws and calls add_line:
From bottom to top:
#3GrRenderTargetOpList::onPrepareis the batch of queued drawing operations being prepared.#2prepareis the generic preparation step for one operation.#1AAHairlineOp::onPrepareDrawsis the specific operation for an anti-aliased hairline, preparing its geometry.#0add_lineis where the actual out-of-bounds write occurs.
ASAN reports the write of size 4 at 0x7f2f4710c000, which is 6144 bytes before the start of the path region. The shadow memory around the address is marked fa, the heap left redzone, confirming the access is to the left of the allocation. "Shadow memory" is ASAN's own bookkeeping: for every chunk of real memory it keeps a small map saying whether that memory is valid, and fa is the marker for the forbidden zone just before a heap block.
==94392==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7f2f4710c000 at pc 0x7f2f5b3ceb60 bp 0x7fffdcf23b70 sp 0x7fffdcf23b68
WRITE of size 4 at 0x7f2f4710c000 thread T0
Line by line:
==94392==ERRORis ASAN announcing an error, with the process number in the brackets.heap-buffer-overflowis the class of mistake: an access outside a heap block.on address 0x7f2f4710c000is the memory address that was wrongly touched.pc,bpandspare the program counter, base pointer and stack pointer at the moment of the crash. They are internal registers that help a developer locate the exact instruction.WRITE of size 4says the program tried to store 4 bytes, not read them.thread T0says it happened on the main thread.
The full call chain from the write back to the event loop runs through GrDrawingManager::flush, GrDrawingManager::prepareSurfaceForExternalIO, GrRenderTargetContext::prepareForExternalIO, the canvas return path, the stable state queue, nsThread::ProcessNextEvent and the browser's message loop. That chain is the browser's normal machinery for handling events and drawing; the bug is simply sitting inside it. The summary line is:
This is ASAN's one-line verdict: the kind of error, the file and line, and the function where it happened.
Root cause
The write in add_line indexes outside the path buffer that was allocated when the path was built. The buffer is grown by SkPathRef::growForVerb via makeSpace, and the overflow lands 6144 bytes before the start of that region, so the renderer is writing at a negative offset relative to the path data rather than past its end. "Offset" here means a position measured from a starting point; a negative offset means going backwards from the start, into memory that was never part of the buffer.
The report does not state the exact arithmetic in add_line that produces the negative offset, nor which property of the path (for example its geometry or verb sequence) triggers it. What the trace establishes is the sequence: a canvas path built through moveTo, an anti-aliased hairline draw queued for the GPU, and a write in add_line during op preparation that falls outside the path allocation.
On defences: the build is ASAN-instrumented, which is what turns the out-of-bounds write into a deterministic abort rather than silent corruption. Without that instrumentation, the same write might have damaged unrelated memory and produced confusing behaviour much later. The crash also depends on the non-default prefs.js from fuzzdata, so the default configuration did not exercise the same path in the researcher's testing.
Impact
The report documents a heap-buffer-overflow write of size 4 in a canvas path rendering path. "Reachable from web content" means an ordinary web page can trigger it, without the user installing anything. A write outside a heap allocation is memory corruption, and in a browser that means content-triggered corruption of the renderer's heap. The renderer is the part of the browser that turns pages into what you see, and it holds a lot of data that a page can influence.
The report does not demonstrate code execution, an information leak, or a sandbox escape, and it does not describe how reliably the out-of-bounds address can be influenced. The practical impact beyond the crash is therefore not established in the text. In other words, we know a page can make Firefox write in the wrong place and stop; we do not know from this report whether an attacker could turn that into anything more.
Fix
It provides the minimised testcase and the ASAN trace, which is what a fix would be built from. A developer would use the trace to find the faulty arithmetic in add_line and the testcase to confirm the fix stops the crash.
Variants to test
These are follow-up experiments a researcher might run to understand the bug better. Each one changes a single factor and looks for a clear signal.
- Other path construction sequences. Build canvas paths with different combinations of
moveTo, line and curve verbs and render them as hairlines. A positive result is an ASAN report inadd_lineor elsewhere inGrAAHairLinePathRendererwith an address outside the path allocation. The point is to learn whether the bug needs one specific shape or appears for many. - Different stroke widths and anti-aliasing settings. The crashing op is the AA hairline op, so vary whether anti-aliasing is on and whether the stroke qualifies as a hairline. A positive result is the same
add_lineframe with a different allocation size or offset. This tests whether the bug is tied to the hairline path specifically. - Different canvas sizes and path sizes. The allocation in the trace is 208584 bytes and the overflow is 6144 bytes before it. A positive result is a crash whose reported offset changes with path size, which would show the offset is derived from path data. If the offset moves when the path grows, the bug is likely a calculation based on the path's contents.
- Default versus fuzzdata preferences. Since the issue does not reproduce without the fuzzdata
prefs.js, test both configurations. A positive result in the default profile would widen the affected population considerably, because most users run default settings. - Lower memory machines. The original reproducer aborted in
mozalloc_abortwith 4GB of RAM. A positive result is a reproducible ASAN report on a machine with less memory than the minimisation environment. This would tell us whether the 8GB requirement is fundamental or just an artefact of the test setup.
Hunting notes
This kind of bug hides in the boundary between a JavaScript-facing drawing API and the GPU backend that consumes the recorded drawing operations. Canvas2D is the obvious surface, but the same pattern applies to any API that records geometry and replays it later during a flush: the allocation happens at record time and the indexing happens at prepare time, so a mismatch between the two is only visible when the deferred work runs. Think of taking an order at a restaurant and cooking it later: if the order slip and the kitchen's understanding of it disagree, the mistake only shows up when the dish is made.
The useful signals during triage are ASAN reports whose allocation stack and crash stack are in different subsystems, here SkPath::moveTo on the allocation side and add_line on the write side. That split tells you the bug is in how recorded geometry is interpreted, not in how it was created. A crash address that sits before the allocation, in the fa redzone, rather than after it, is worth noting: it points at a negative index rather than a simple overrun. A simple overrun is like reading one page past the end of a book; a negative index is like opening the book several pages before the first page.
The report includes a minimised testcase, the build changeset and build ID, the launch tooling and preferences, and the ASAN trace with crash and allocation stacks. That is enough for a graphics memory-safety report to be triaged without further guesswork about the environment. "Triaged" means the receiving team can confirm the bug, judge its severity and route it to the right developers.
Glossary
- AddressSanitizer (ASAN): a tool built into a program that checks every memory access and stops the program with a detailed report when one goes out of bounds.
- Allocation: a block of memory a program reserves for its own use while running.
- Allocation stack: the list of function calls that were running when a block of memory was reserved.
- Anti-aliasing: smoothing jagged edges by blending colours along the border of a shape.
- API: a defined set of instructions one piece of software offers to another.
- Buffer: a reserved chunk of memory used to hold data.
- Build ID: an identifier stamped on a particular compiled build of a program.
- Canvas2D: the browser feature that lets web pages draw shapes, lines and images on a drawing surface.
- Changeset: the exact version of source code a build was made from.
- Crash stack: the list of function calls that were running when a program crashed.
- DOM: the browser's in-memory representation of a web page and its elements.
- Fuzzing: feeding a program large amounts of generated input and watching for crashes.
- GPU: the graphics processor, which handles drawing work in parallel with the main processor.
- Hairline: a line so thin that it is drawn as a single hair's width rather than as a filled shape.
- Heap: the area of memory a program uses for things it creates while running.
- Heap-buffer-overflow: an access outside the edges of a reserved block of heap memory.
- Memory corruption: damage to memory caused by writing where the program should not.
- Minimised testcase: the smallest version of an input that still triggers a bug.
- mozalloc_abort: Firefox's own memory allocator giving up and stopping the program.
- Negative offset: a position measured backwards from a starting point, into memory before the buffer.
- Out-of-bounds access: reading or writing memory outside the area a program is allowed to touch.
- Path: a shape described as a series of points and line or curve instructions.
- Preference (
prefs.js): a browser setting stored in a file. - Redzone: a forbidden area ASAN places around a memory block to catch accesses that stray outside it.
- Renderer: the part of the browser that turns a page into what you see on screen.
- Sandbox escape: breaking out of the restricted environment a browser puts around page content.
- Shadow memory: ASAN's bookkeeping map recording which parts of memory are valid.
- Skia: the 2D graphics library bundled inside Firefox.
- Stable state: a moment when the browser is between tasks and can safely do deferred work.
- Triage: the process of confirming a bug, judging its severity and routing it to the right developers.
- Verb: a single instruction in a path, such as a move or a line.
- Web content: anything a web page itself supplies and runs in the browser.