Heap-buffer-overflow in AAHairlineBatch::onPrepareDraws
A heap-buffer-overflow occurs in Skia's AAHairlineBatch::onPrepareDraws when drawing a canvas path with many line segments. An attacker could trigger a crash or potentially execute code by crafting a malicious web page.
Originally disclosed on Mozilla
- Fixed in 2 months
- Paid in 3 months
- Disclosed after 2 months
Created attachment 8796563
firefox-heap-buffer-overflow-add_line.html
Tested on:
OS: Ubuntu 16.04.1 LTS
Firefox: moz_source_stamp: f713114b8c8d352b668b3e8052bc51ece4df34e0
ASAN-trace:
==6370==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7fb8bec14003 at pc 0x7fb8cdf9c78a bp 0x7ffc4226db70 sp 0x7ffc4226db68
WRITE of size 8 at 0x7fb8bec14003 thread T0
#0 0x7fb8cdf9c789 in add_line /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/skia/skia/src/gpu/batches/GrAAHairLinePathRenderer.cpp:592:25
#1 0x7fb8cdf9c789 in AAHairlineBatch::onPrepareDraws(GrVertexBatch::Target*) const /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/skia/skia/src/gpu/batches/GrAAHairLinePathRenderer.cpp:861
#2 0x7fb8ce2a9799 in GrVertexBatch::onPrepare(GrBatchFlushState*) /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/skia/skia/src/gpu/batches/GrVertexBatch.cpp:19:5
#3 0x7fb8ce1ca790 in prepare /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/skia/skia/src/gpu/batches/GrBatch.h:109:46
#4 0x7fb8ce1ca790 in GrDrawTarget::prepareBatches(GrBatchFlushState*) /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/skia/skia/src/gpu/GrDrawTarget.cpp:202
#5 0x7fb8ce1db713 in GrDrawingManager::flush() /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/skia/skia/src/gpu/GrDrawingManager.cpp:77:9
#6 0x7fb8ce1c73a1 in flush /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/skia/skia/src/gpu/GrContext.cpp:237:9
#7 0x7fb8ce1c73a1 in GrContext::prepareSurfaceForExternalIO(GrSurface*) /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/skia/skia/src/gpu/GrContext.cpp:537
#8 0x7fb8c6aaf1d4 in mozilla::layers::PersistentBufferProviderBasic::ReturnDrawTarget(already_AddRefed<mozilla::gfx::DrawTarget>) /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/layers/PersistentBufferProvider.cpp:46:5
#9 0x7fb8c948f28b in mozilla::dom::CanvasRenderingContext2D::ReturnTarget() /builds/slave/m-cen-l64-asan-000000000000000/build/src/dom/canvas/CanvasRenderingContext2D.cpp:1767:5
#10 0x7fb8c9494016 in mozilla::dom::CanvasRenderingContext2D::OnStableState() /builds/slave/m-cen-l64-asan-000000000000000/build/src/dom/canvas/CanvasRenderingContext2D.cpp:1499:3
#11 0x7fb8c9550a22 in applyImpl<mozilla::dom::CanvasRenderingContext2D, void (mozilla::dom::CanvasRenderingContext2D::*)()> /builds/slave/m-cen-l64-asan-000000000000000/build/src/obj-firefox/dist/include/nsThreadUtils.h:729:12
#12 0x7fb8c9550a22 in apply<mozilla::dom::CanvasRenderingContext2D, void (mozilla::dom::CanvasRenderingContext2D::*)()> /builds/slave/m-cen-l64-asan-000000000000000/build/src/obj-firefox/dist/include/nsThreadUtils.h:735
#13 0x7fb8c9550a22 in mozilla::detail::RunnableMethodImpl<void (mozilla::dom::CanvasRenderingContext2D::*)(), true, false>::Run() /builds/slave/m-cen-l64-asan-000000000000000/build/src/obj-firefox/dist/include/nsThreadUtils.h:764
.
.
.
0x7fb8bec14003 is located 6141 bytes to the left of 140400-byte region [0x7fb8bec15800,0x7fb8bec37c70)
allocated by thread T0 here:
#0 0x4b27ce in realloc /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:71:3
#1 0x4e0d7d in moz_xrealloc /builds/slave/m-cen-l64-asan-000000000000000/build/src/memory/mozalloc/mozalloc.cpp:105:20
#2 0x7fb8ce56eefe in makeSpace /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/skia/skia/include/core/SkPathRef.h:424:46
#3 0x7fb8ce56eefe in SkPathRef::growForVerb(int, float) /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/skia/skia/src/core/SkPathRef.cpp:439
#4 0x7fb8ce552bce in growForVerb /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/skia/skia/include/core/SkPathRef.h:73:20
#5 0x7fb8ce552bce in SkPath::moveTo(float, float) /builds/slave/m-cen-l64-asan-000000000000000/build/src/gfx/skia/skia/src/core/SkPath.cpp:731
#6 0x7fb8c85f18b1 in MoveTo /builds/slave/m-cen-l64-asan-000000000000000/build/src/obj-firefox/dist/include/mozilla/dom/CanvasRenderingContext2D.h:306:7
#7 0x7fb8c85f18b1 in mozilla::dom::CanvasRenderingContext2DBinding::moveTo(JSContext*, JS::Handle<JSObject*>, mozilla::dom::CanvasRenderingContext2D*, JSJitMethodCallArgs const&) /builds/slave/m-cen-l64-asan-000000000000000/build/src/obj-firefox/dom/bindings/CanvasRenderingContext2DBinding.cpp:6060
.
.
.
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 an incorrect calculation of the required buffer size for hairline paths in Skia's AAHairlineBatch, leading to a write beyond the allocated region.
Impact
A crafted web page could crash the browser and potentially allow arbitrary code execution.
What the attacker needed
Victim visits a malicious web page
How it was found
- Open the attached HTML file in Firefox.
- The page draws a canvas path with many line segments.
- The browser crashes with a heap-buffer-overflow.
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 heap-buffer-overflow is a memory safety bug where a program writes data past the end of a reserved memory block. Here, drawing a complex line on a canvas causes the browser to write outside its buffer, which can crash the browser or let an attacker run their own code.
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.