Skip to content
Memory corruption Disclosed report Advanced

AddressSanitizer: heap-use-after-free READ of size 513 IPC

A heap-use-after-free occurs in Firefox's background hang monitor when serialising a hang stack for IPC, because the stack buffer is freed before the string length is read. An attacker could potentially trigger a crash, but the report does not demonstrate remote exploitation.

Francisco A Follow

Originally disclosed on Mozilla

  • Fixed in 37 days
  • Paid in 45 days
  • Disclosed after 37 days

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.14 Safari/537.36

Steps to reproduce:

I got this crash on one of my fuzzers. I'm trying to see if I can reproduce it with a specific test case. To make sure it is not duplicated I sent it just in case.

tested on Firefox Nightly 59.0a1 (2017-12-10) (64-bit)

Actual results:

=================================================================
==8897==ERROR: AddressSanitizer: heap-use-after-free on address 0x615002329700 at pc 0x0000004319bb bp 0x7ffec68d23d0 sp 0x7ffec68d1b78
READ of size 513 at 0x615002329700 thread T0 (Web Content)
#0 0x4319ba in __interceptor_strlen /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:303:5
#1 0x7f70daa7ee37 in length /builds/worker/workspace/build/src/obj-firefox/dist/include/nsCharTraits.h:468:12
#2 0x7f70daa7ee37 in nsTDependentString /builds/worker/workspace/build/src/obj-firefox/dist/include/nsTDependentString.h:81
#3 0x7f70daa7ee37 in IPC::ParamTraitsmozilla::HangStack::Write(IPC::Message*, mozilla::HangStack const&) /builds/worker/workspace/build/src/toolkit/components/backgroundhangmonitor/HangStack.cpp:223
#4 0x7f70daa7bcb4 in WriteParammozilla::HangStack /builds/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_message_utils.h:111:3
#5 0x7f70daa7bcb4 in IPC::ParamTraitsmozilla::HangDetails::Write(IPC::Message*, mozilla::HangDetails const&) /builds/worker/workspace/build/src/toolkit/components/backgroundhangmonitor/HangDetails.cpp:310
#6 0x7f70d0c4920a in WriteParammozilla::HangDetails /builds/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_message_utils.h:111:3
#7 0x7f70d0c4920a in Writemozilla::HangDetails /builds/worker/workspace/build/src/obj-firefox/ipc/ipdl/_ipdlheaders/mozilla/dom/PContentChild.h:2308
#8 0x7f70d0c4920a in mozilla::dom::PContentChild::SendBHRThreadHang(mozilla::HangDetails const&) /builds/worker/workspace/build/src/obj-firefox/ipc/ipdl/PContentChild.cpp:4491 #9 0x7f70daa826d9 in operator() /builds/worker/workspace/build/src/toolkit/components/backgroundhangmonitor/HangDetails.cpp:248:23
#10 0x7f70daa826d9 in mozilla::detail::RunnableFunctionmozilla::nsHangDetails::Submit()::$_0::Run() /builds/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:529
#11 0x7f70cf4d4b54 in mozilla::SchedulerGroup::Runnable::Run() /builds/worker/workspace/build/src/xpcom/threads/SchedulerGroup.cpp:396:25
#12 0x7f70cf4fb42e in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1033:14
#13 0x7f70cf516d90 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:508:10
#14 0x7f70d039e21a in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:97:21
#15 0x7f70d02f51a9 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10
#16 0x7f70d02f51a9 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319
#17 0x7f70d02f51a9 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299
#18 0x7f70d68a4dda in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:157:27
#19 0x7f70dafd8b0b in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:865:22
#20 0x7f70d02f51a9 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10
#21 0x7f70d02f51a9 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319
#22 0x7f70d02f51a9 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299
#23 0x7f70dafd84fd in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:691:34
#24 0x4ee965 in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:63:30
#25 0x4ee965 in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:280
#26 0x7f70ee108039 in __libc_start_main (/lib64/libc.so.6+0x21039)
#27 0x41dfe8 in _start (/home/fuzzer/browsers/firefox/firefox+0x41dfe8)

0x615002329900 is located 0 bytes to the right of 512-byte region [0x615002329700,0x615002329900)
freed by thread T0 (Web Content) here:
#0 0x4bea42 in _interceptor_free /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:68:3
#1 0x7f70d0553f59 in free
/builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/AllocPolicy.h:119:5
#2 0x7f70d0553f59 in ~Vector /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/Vector.h:930
#3 0x7f70d0553f59 in ~HangStack /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/HangStack.h:25
#4 0x7f70d0553f59 in mozilla::HangDetails::~HangDetails() /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/HangDetails.h:29
#5 0x7f70daa8200b in ~nsHangDetails /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/HangDetails.h:87:29
#6 0x7f70daa8200b in mozilla::nsHangDetails::~nsHangDetails() /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/HangDetails.h:87
#7 0x7f70daa7a48c in mozilla::nsHangDetails::Release() /builds/worker/workspace/build/src/toolkit/components/backgroundhangmonitor/HangDetails.cpp:279:1
#8 0x7f70daa8299e in Release /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/RefPtr.h:41:11
#9 0x7f70daa8299e in Release /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/RefPtr.h:398
#10 0x7f70daa8299e in ~RefPtr /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/RefPtr.h:79
#11 0x7f70daa8299e in ~ /builds/worker/workspace/build/src/toolkit/components/backgroundhangmonitor/HangDetails.cpp:237
#12 0x7f70daa8299e in ~RunnableFunction /builds/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:517 #13 0x7f70daa8299e in mozilla::detail::RunnableFunctionmozilla::nsHangDetails::Submit()::$_0::~RunnableFunction() /builds/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:517 #14 0x7f70cf5133dc in mozilla::Runnable::Release() /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:43:1
#15 0x7f70cf4d4d83 in assign_assuming_AddRef /builds/worker/workspace/build/src/obj-firefox/dist/include/nsCOMPtr.h:355:7
#16 0x7f70cf4d4d83 in operator= /builds/worker/workspace/build/src/obj-firefox/dist/include/nsCOMPtr.h:631
#17 0x7f70cf4d4d83 in mozilla::SchedulerGroup::Runnable::Run() /builds/worker/workspace/build/src/xpcom/threads/SchedulerGroup.cpp:401
#18 0x7f70cf4fb42e in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1033:14
#19 0x7f70cf516d90 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:508:10
#20 0x7f70d039e21a in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:97:21
#21 0x7f70d02f51a9 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10
#22 0x7f70d02f51a9 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319
#23 0x7f70d02f51a9 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299
#24 0x7f70d68a4dda in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:157:27
#25 0x7f70dafd8b0b in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:865:22
#26 0x7f70d02f51a9 in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10
#27 0x7f70d02f51a9 in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319
#28 0x7f70d02f51a9 in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299
#29 0x7f70dafd84fd in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:691:34
#30 0x4ee965 in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:63:30
#31 0x4ee965 in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:280
#32 0x7f70ee108039 in __libc_start_main (/lib64/libc.so.6+0x21039)

previously allocated by thread T20 (BgHangManager) here:
#0 0x4bed83 in malloc /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:88:3
#1 0x7f70d1fa3612 in maybe_pod_malloc<char> /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/AllocPolicy.h:81:28
#2 0x7f70d1fa3612 in pod_malloc<char> /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/AllocPolicy.h:102
#3 0x7f70d1fa3612 in convertToHeapStorage /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/Vector.h:959
#4 0x7f70d1fa3612 in mozilla::Vector<char, 0ul, mozilla::MallocAllocPolicy>::growStorageBy(unsigned long) /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/Vector.h:1050
#5 0x7f70daa803a5 in reserve /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/Vector.h:1112:9
#6 0x7f70daa803a5 in EnsureBufferCapacity /builds/worker/workspace/build/src/toolkit/components/backgroundhangmonitor/HangStack.h:270
#7 0x7f70daa803a5 in mozilla::ThreadStackHelper::PrepareStackBuffer(mozilla::HangStack&) /builds/worker/workspace/build/src/toolkit/components/backgroundhangmonitor/ThreadStackHelper.cpp:98
#8 0x7f70daa747f6 in GetStack /builds/worker/workspace/build/src/toolkit/components/backgroundhangmonitor/ThreadStackHelper.cpp:124:8
#9 0x7f70daa747f6 in mozilla::BackgroundHangManager::RunMonitorThread() /builds/worker/workspace/build/src/toolkit/components/backgroundhangmonitor/BackgroundHangMonitor.cpp:366
#10 0x7f70daa73d23 in mozilla::BackgroundHangManager::MonitorThread(void*) /builds/worker/workspace/build/src/toolkit/components/backgroundhangmonitor/BackgroundHangMonitor.cpp:76:49 #11 0x7f70eb7d7d7e in _pt_root /builds/worker/workspace/build/src/nsprpub/pr/src/pthreads/ptthread.c:216:5
#12 0x7f70ef1d1608 in start_thread (/lib64/libpthread.so.0+0x7608)
Thread T20 (BgHangManager) created by T0 (Web Content) here:
#0 0x4a80dd in __interceptor_pthread_create /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_interceptors.cc:204:3
#1 0x7f70eb7d4acf in _PR_CreateThread /builds/worker/workspace/build/src/nsprpub/pr/src/pthreads/ptthread.c:457:14
#2 0x7f70eb7d46be in PR_CreateThread /builds/worker/workspace/build/src/nsprpub/pr/src/pthreads/ptthread.c:548:12
#3 0x7f70daa7722e in BackgroundHangManager /builds/worker/workspace/build/src/toolkit/components/backgroundhangmonitor/BackgroundHangMonitor.cpp:261:24
#4 0x7f70daa7722e in mozilla::BackgroundHangMonitor::Startup() /builds/worker/workspace/build/src/toolkit/components/backgroundhangmonitor/BackgroundHangMonitor.cpp:619
#5 0x7f70cf555243 in NS_InitXPCOM2 /builds/worker/workspace/build/src/xpcom/build/XPCOMInit.cpp:724:3
#6 0x7f70dafd79a3 in XRE_InitEmbedding2(nsIFile*, nsIFile*, nsIDirectoryServiceProvider*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:187:8
#7 0x7f70d03a929e in mozilla::ipc::ScopedXREEmbed::Start() /builds/worker/workspace/build/src/ipc/glue/ScopedXREEmbed.cpp
#8 0x7f70d607632a in mozilla::dom::ContentProcess::Init(int, char**) /builds/worker/workspace/build/src/dom/ipc/ContentProcess.cpp:245:13
#9 0x7f70dafd84eb in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:663:21
#10 0x4ee965 in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:63:30
#11 0x4ee965 in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:280
#12 0x7f70ee108039 in __libc_start_main (/lib64/libc.so.6+0x21039)

SUMMARY: AddressSanitizer: heap-use-after-free /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:303:5 in __interceptor_strlen Shadow bytes around the buggy address:
0x0c2a8045d290: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c2a8045d2a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c2a8045d2b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c2a8045d2c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c2a8045d2d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c2a8045d2e0:[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c2a8045d2f0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c2a8045d300: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c2a8045d310: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c2a8045d320: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c2a8045d330: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 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 Freed heap region: fd [175/1818] 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
==8897==ABORTING

The original report as published on Mozilla's Bugzilla, by Francisco A.. 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 a use-after-free where a HangStack buffer is freed by the background hang manager thread while the main thread still holds a reference and later reads its length during IPC serialisation.

Impact

Could cause a browser crash (denial of service) in the content process; no evidence of code execution or data theft is provided.

What the attacker needed

Firefox Nightly build with ASan; Fuzzer-generated input

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.

This is a memory safety bug in Firefox. A chunk of memory was freed but then read again, which can crash the browser. The report is a crash dump from a fuzzer, not a full exploit.

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 Francisco A

View all

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