Skip to content
Memory corruption Disclosed report Advanced CVE-2020-26959

Heap use-after-free via ContentParent::RecvInitStreamFilter

A fuzzing harness for ContentParent IPC triggered a heap use-after-free when a WebRequestService singleton was released during XPCOM shutdown after being created via RecvInitStreamFilter. The crash is a memory-safety fault observed only in the fuzzing harness, and the reporter is unsure whether it is reachable in a running browser.

tunnelshade Follow

Originally disclosed on Mozilla

  • Fixed in 22 days
  • Paid in 28 days
  • Disclosed after 22 days

Created attachment 9179865 latest-stock-85713

Introduction

While fuzzing ContentParent IPC with a slightly modified harness, I came across a very weird crash. Crash happens during xpcom shutdown, possibly due to refcounting a freed instance via a stale pointer.

Steps

Used fuzzfetch to get latest release fuzzing build to reproduce on stock harness.

$ ./m-r-20201005120340-fuzzing-asan-opt/firefox latest-stock-85713

*** You are running in headless mode.
Running Fuzzer tests...
INFO: Seed: 1293591897
INFO: Loaded 1 modules   (1524233 inline 8-bit counters): 1524233 [0x7f76db165038, 0x7f76db2d9241),
INFO: Loaded 1 PC tables (1524233 PCs): 1524233 [0x7f76db2d9248,0x7f76dca1b2d8),
./m-r-20201005120340-fuzzing-asan-opt/firefox: Running 1 inputs 1 time(s) each.
Running: triage-2/latest-stock-85713
Executed triage-2/latest-stock-85713 in 0 ms
***
*** NOTE: fuzzing was not performed, you have only
***       executed the target code on a fixed set of inputs.
***
=================================================================
==560090==ERROR: AddressSanitizer: heap-use-after-free on address 0x604000092a50 at pc 0x7f76d1282502 bp 0x7ffc50927ce0 sp 0x7ffc50927cd8
READ of size 8 at 0x604000092a50 thread T0 (MainThread)
    #0 0x7f76d1282501 in operator-- /builds/worker/workspace/obj-build/dist/include/nsISupportsImpl.h:321:34
    #1 0x7f76d1282501 in Release /builds/worker/checkouts/gecko/toolkit/components/extensions/webrequest/WebRequestService.h:46:3
    #2 0x7f76d1282501 in Release /builds/worker/workspace/obj-build/dist/include/mozilla/RefPtr.h:50:40
    #3 0x7f76d1282501 in Release /builds/worker/workspace/obj-build/dist/include/mozilla/RefPtr.h:381:36
    #4 0x7f76d1282501 in assign_assuming_AddRef /builds/worker/workspace/obj-build/dist/include/mozilla/RefPtr.h:69:7
    #5 0x7f76d1282501 in operator= /builds/worker/workspace/obj-build/dist/include/mozilla/RefPtr.h:168:5
    #6 0x7f76d1282501 in mozilla::ClearOnShutdown_Internal::PointerClearer<RefPtr<mozilla::extensions::WebRequestService> >::Shutdown() /builds/worker/workspace/obj-build/dist/include/mozilla/ClearOnShutdown.h:72:13
    #7 0x7f76c5846dad in mozilla::KillClearOnShutdown(mozilla::ShutdownPhase) /builds/worker/checkouts/gecko/xpcom/base/ClearOnShutdown.cpp:53:19
    #8 0x7f76c5ab3b6d in mozilla::ShutdownXPCOM(nsIServiceManager*) /builds/worker/checkouts/gecko/xpcom/build/XPCOMInit.cpp:662:5
    #9 0x7f76d176978d in ~ScopedXPCOM /builds/worker/checkouts/gecko/tools/fuzzing/interface/harness/FuzzerTestHarness.h:106:21
    #10 0x7f76d176978d in mozilla::_InitFuzzer::DeinitXPCOM() /builds/worker/checkouts/gecko/tools/fuzzing/interface/harness/FuzzerRunner.cpp:25:23
    #11 0x7f76e2351db6 in __run_exit_handlers (/usr/lib/libc.so.6+0x3fdb6)
    #12 0x7f76e2351f5d in exit (/usr/lib/libc.so.6+0x3ff5d)
    #13 0x55d833a9f4a5 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /builds/worker/checkouts/gecko/tools/fuzzing/libfuzzer/FuzzerDriver.cpp
    #14 0x7f76d176904f in mozilla::FuzzerRunner::Run(int*, char***) /builds/worker/checkouts/gecko/tools/fuzzing/interface/harness/FuzzerRunner.cpp:75:13
    #15 0x7f76d16aa57e in XREMain::XRE_mainStartup(bool*) /builds/worker/checkouts/gecko/toolkit/xre/nsAppRunner.cpp:3851:35
    #16 0x7f76d16bb268 in XREMain::XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/checkouts/gecko/toolkit/xre/nsAppRunner.cpp:4941:12
    #17 0x7f76d16bc0b3 in XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/checkouts/gecko/toolkit/xre/nsAppRunner.cpp:5008:21
    #18 0x55d833921f97 in do_main /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:217:22
    #19 0x55d833921f97 in main /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:331:16
    #20 0x7f76e233a151 in __libc_start_main (/usr/lib/libc.so.6+0x28151)
    #21 0x55d833876309 in _start (/home/tunnelshade/workspace/firefox/m-r-20201005120340-fuzzing-asan-opt/firefox+0xa4309)

0x604000092a50 is located 0 bytes inside of 48-byte region [0x604000092a50,0x604000092a80)
freed by thread T0 (MainThread) here:
    #0 0x55d8338eea3d in free /builds/worker/fetches/llvm-project/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:123:3
    #1 0x7f76e2351db6 in __run_exit_handlers (/usr/lib/libc.so.6+0x3fdb6)

previously allocated by thread T0 (MainThread) here:
    #0 0x55d8338eecbd in malloc /builds/worker/fetches/llvm-project/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:145:3
    #1 0x55d833924dad in moz_xmalloc /builds/worker/checkouts/gecko/memory/mozalloc/mozalloc.cpp:52:15
    #2 0x7f76d125d20c in operator new /builds/worker/workspace/obj-build/dist/include/mozilla/cxxalloc.h:33:10
    #3 0x7f76d125d20c in mozilla::extensions::WebRequestService::GetSingleton() /builds/worker/checkouts/gecko/toolkit/components/extensions/webrequest/WebRequestService.cpp:23:16
    #4 0x7f76d126c56c in mozilla::extensions::StreamFilterParent::Create(mozilla::dom::ContentParent*, unsigned long, nsTSubstring<char16_t> const&) /builds/worker/checkouts/gecko/toolkit/components/extensions/webrequest/StreamFilterParent.cpp:116:18
    #5 0x7f76cd3d2a35 in mozilla::dom::ContentParent::RecvInitStreamFilter(unsigned long const&, nsTString<char16_t> const&, std::function<void (mozilla::ipc::Endpoint<mozilla::extensions::PStreamFilterChild>&&)>&&) /builds/worker/checkouts/gecko/dom/ipc/ContentParent.cpp:3903:3
    #6 0x7f76c710cd54 in mozilla::dom::PContentParent::OnMessageReceived(IPC::Message const&) /builds/worker/workspace/obj-build/ipc/ipdl/PContentParent.cpp:7626:57
    #7 0x7f76c529dbc3 in void mozilla::ipc::FuzzProtocol<mozilla::dom::ContentParent>(mozilla::dom::ContentParent*, unsigned char const*, unsigned long, nsTArray<nsTString<char> > const&) /builds/worker/workspace/obj-build/dist/include/ProtocolFuzzer.h:99:18
    #8 0x7f76c529d038 in RunContentParentIPCFuzzing(unsigned char const*, unsigned long) /builds/worker/checkouts/gecko/dom/ipc/fuzztest/content_parent_ipc_libfuzz.cpp:27:3
    #9 0x55d833aafa2e in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /builds/worker/checkouts/gecko/tools/fuzzing/libfuzzer/FuzzerLoop.cpp:562:11
    #10 0x55d833a99d0e in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /builds/worker/checkouts/gecko/tools/fuzzing/libfuzzer/FuzzerDriver.cpp:301:6
    #11 0x55d833a9f441 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /builds/worker/checkouts/gecko/tools/fuzzing/libfuzzer/FuzzerDriver.cpp:802:9
    #12 0x7f76d176904f in mozilla::FuzzerRunner::Run(int*, char***) /builds/worker/checkouts/gecko/tools/fuzzing/interface/harness/FuzzerRunner.cpp:75:13
    #13 0x7f76d16aa57e in XREMain::XRE_mainStartup(bool*) /builds/worker/checkouts/gecko/toolkit/xre/nsAppRunner.cpp:3851:35
    #14 0x7f76d16bb268 in XREMain::XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/checkouts/gecko/toolkit/xre/nsAppRunner.cpp:4941:12
    #15 0x7f76d16bc0b3 in XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/checkouts/gecko/toolkit/xre/nsAppRunner.cpp:5008:21
    #16 0x55d833921f97 in do_main /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:217:22
    #17 0x55d833921f97 in main /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:331:16
    #18 0x7f76e233a151 in __libc_start_main (/usr/lib/libc.so.6+0x28151)

SUMMARY: AddressSanitizer: heap-use-after-free /builds/worker/workspace/obj-build/dist/include/nsISupportsImpl.h:321:34 in operator--
Shadow bytes around the buggy address:
  0x0c088000a4f0: fa fa 00 00 00 00 00 00 fa fa 00 00 00 00 00 00
  0x0c088000a500: fa fa 00 00 00 00 00 00 fa fa 00 00 00 00 00 00
  0x0c088000a510: fa fa 00 00 00 00 00 00 fa fa 00 00 00 00 00 06
  0x0c088000a520: fa fa 00 00 00 00 00 06 fa fa 00 00 00 00 00 06
  0x0c088000a530: fa fa 00 00 00 00 00 fa fa fa fd fd fd fd fd fd
=>0x0c088000a540: fa fa fd fd fd fd fd fa fa fa[fd]fd fd fd fd fd
  0x0c088000a550: fa fa 00 00 00 00 00 fa fa fa fd fd fd fd fd fa
  0x0c088000a560: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fa
  0x0c088000a570: fa fa fd fd fd fd fd fa fa fa 00 00 00 00 00 00
  0x0c088000a580: fa fa fd fd fd fd fd fa fa fa 00 00 00 00 00 fa
  0x0c088000a590: fa fa 00 00 00 00 00 fa fa fa fd fd fd fd fd 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
  Shadow gap:              cc
==560090==ABORTING

Speculative Root Cause

Ref counting on a stale reference to WebRequestService object during xpcom shutdown. I am not sure if this can be reproduced in a running browser instance and not just the fuzzing harness.

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

Impact

The text only shows a crash under the fuzzing harness and does not demonstrate that a running browser can be made to crash or be exploited.

What the attacker needed

Fuzzing build with ASan; crafted IPC input to ContentParent

How it was found

  1. Build or fetch the fuzzing build with AddressSanitizer enabled.
  2. Run the fuzzer binary against the saved crashing input file.
  3. Observe the AddressSanitizer heap-use-after-free report during XPCOM shutdown.

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.

When a program frees a chunk of memory but keeps a pointer to it and later uses that pointer, this is called a use-after-free. Here a browser internal object was freed during shutdown and then its reference count was decremented, which the memory checker flagged as an error. The reporter found it by feeding random input to the browser's internal messaging code, not by using the browser normally.

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 tunnelshade

View all

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