Skip to content
Memory corruption Disclosed report Advanced CVE-2017-7793

Heap-use-after-free in mozilla::dom::(anonymous namespace)::ConsumeBodyDoneObserver<mozilla::dom::Request>::OnStreamComplete

A use-after-free occurs in Firefox's fetch implementation when a Request object created inside a DOM Worker is freed by the worker's cycle collector while a stream-completion callback still holds a reference to it. An attacker could trigger a memory-safety crash in the content process, which in principle may be exploitable for code execution.

Abhishek Arya Follow

Originally disclosed on Mozilla

  • Fixed in 11 days
  • Paid in 10 days
  • Disclosed after 11 days

Created attachment 8876357 t.zip

================================================================= ==107957==ERROR: AddressSanitizer: heap-use-after-free on address 0x60d000066990 at pc 0x7f6f64bc192f bp 0x7ffcea9dbcf0 sp 0x7ffcea9dbce8 READ of size 8 at 0x60d000066990 thread T0 (Web Content) #0 0x7f6f64bc192e in mozilla::dom::(anonymous namespace)::ConsumeBodyDoneObservermozilla::dom::Request::OnStreamComplete(nsIStreamLoader*, nsISupports*, nsresult, unsigned int, unsigned char const*) dom/fetch/Fetch.cpp:1006:21 #1 0x7f6f613b41e7 in mozilla::net::nsStreamLoader::OnStopRequest(nsIRequest*, nsISupports*, nsresult) netwerk/base/nsStreamLoader.cpp:105:30 #2 0x7f6f6131fc95 in nsInputStreamPump::OnStateStop() netwerk/base/nsInputStreamPump.cpp:734:20 #3 0x7f6f6131e44e in nsInputStreamPump::OnInputStreamReady(nsIAsyncInputStream*) netwerk/base/nsInputStreamPump.cpp:448:25 #4 0x7f6f611532fd in nsInputStreamReadyEvent::Run() xpcom/io/nsStreamUtils.cpp:96:20 #5 0x7f6f6119a898 in mozilla::ThrottledEventQueue::Inner::ExecuteRunnable() xpcom/threads/ThrottledEventQueue.cpp:190:22 #6 0x7f6f6119a47f in mozilla::ThrottledEventQueue::Inner::Executor::Run() xpcom/threads/ThrottledEventQueue.cpp:74:15 #7 0x7f6f6119a898 in mozilla::ThrottledEventQueue::Inner::ExecuteRunnable() xpcom/threads/ThrottledEventQueue.cpp:190:22 #8 0x7f6f6119a47f in mozilla::ThrottledEventQueue::Inner::Executor::Run() xpcom/threads/ThrottledEventQueue.cpp:74:15 #9 0x7f6f611827c8 in mozilla::SchedulerGroup::Runnable::Run() xpcom/threads/SchedulerGroup.cpp:359:25 #10 0x7f6f611ad373 in nsThread::ProcessNextEvent(bool, bool*) xpcom/threads/nsThread.cpp:1406:14 #11 0x7f6f611b7278 in NS_ProcessNextEvent(nsIThread*, bool) xpcom/threads/nsThreadUtils.cpp:472:10 #12 0x7f6f61d66358 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) ipc/glue/MessagePump.cpp:96:21 #13 0x7f6f61ccd9ed in RunHandler ipc/chromium/src/base/message_loop.cc:231:3 #14 0x7f6f61ccd9ed in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:211 #15 0x7f6f65f1b0fa in nsBaseAppShell::Run() widget/nsBaseAppShell.cpp:156:27 #16 0x7f6f693d6aac in XRE_RunAppShell() toolkit/xre/nsEmbedFunctions.cpp:896:22 #17 0x7f6f61ccd9ed in RunHandler ipc/chromium/src/base/message_loop.cc:231:3 #18 0x7f6f61ccd9ed in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:211 #19 0x7f6f693d6598 in XRE_InitChildProcess(int, char**, XREChildData const*) toolkit/xre/nsEmbedFunctions.cpp:712:34 #20 0x524fc1 in content_process_main browser/app/../../ipc/contentproc/plugin-container.cpp:64:30 #21 0x524fc1 in main browser/app/nsBrowserApp.cpp:286 #22 0x7f6f79ee7f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44) #23 0x41d905 in _start (objdir-ff-asan/dist/bin/firefox-bin+0x41d905)

0x60d000066990 is located 16 bytes inside of 144-byte region [0x60d000066980,0x60d000066a10) freed by thread T104 (DOM Worker) here: #0 0x4e8890 in __interceptor_free /build/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:47 #1 0x7f6f6108dd75 in SnowWhiteKiller::~SnowWhiteKiller() xpcom/base/nsCycleCollector.cpp:2651:25 #2 0x7f6f6108d1f1 in nsCycleCollector::FreeSnowWhite(bool) xpcom/base/nsCycleCollector.cpp:2826:3 #3 0x7f6f61093ee8 in nsCycleCollector::BeginCollection(ccType, nsICycleCollectorListener*) xpcom/base/nsCycleCollector.cpp:3829:3 #4 0x7f6f61093852 in nsCycleCollector::Collect(ccType, js::SliceBudget&, nsICycleCollectorListener*, bool) xpcom/base/nsCycleCollector.cpp:3650:9 #5 0x7f6f61094f74 in ShutdownCollect xpcom/base/nsCycleCollector.cpp:3591:10 #6 0x7f6f61094f74 in nsCycleCollector::Shutdown(bool) xpcom/base/nsCycleCollector.cpp:3886 #7 0x7f6f61096b4c in nsCycleCollector_shutdown(bool) xpcom/base/nsCycleCollector.cpp:4247:23 #8 0x7f6f65a486cb in (anonymous namespace)::WorkerJSContext::~WorkerJSContext() dom/workers/RuntimeService.cpp:1144:5 #9 0x7f6f65a47f3a in (anonymous namespace)::WorkerThreadPrimaryRunnable::Run() dom/workers/RuntimeService.cpp:2952:3 #10 0x7f6f611ad373 in nsThread::ProcessNextEvent(bool, bool*) xpcom/threads/nsThread.cpp:1406:14 #11 0x7f6f611b7278 in NS_ProcessNextEvent(nsIThread*, bool) xpcom/threads/nsThreadUtils.cpp:472:10 #12 0x7f6f61d67896 in mozilla::ipc::MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate*) ipc/glue/MessagePump.cpp:338:20 #13 0x7f6f61ccd9ed in RunHandler ipc/chromium/src/base/message_loop.cc:231:3 #14 0x7f6f61ccd9ed in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:211 #15 0x7f6f611a650f in nsThread::ThreadFunc(void*) xpcom/threads/nsThread.cpp:501:11 #16 0x7f6f775d222c in _pt_root nsprpub/pr/src/pthreads/ptthread.c:216:5 #17 0x7f6f7aec2183 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8183)

previously allocated by thread T104 (DOM Worker) here: #0 0x4e8be8 in malloc /build/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:66 #1 0x52622d in moz_xmalloc memory/mozalloc/mozalloc.cpp:83:17 #2 0x7f6f64b9c3d9 in operator new objdir-ff-asan/dist/include/mozilla/mozalloc.h:194:12 #3 0x7f6f64b9c3d9 in mozilla::dom::Request::Constructor(mozilla::dom::GlobalObject const&, mozilla::dom::RequestOrUSVString const&, mozilla::dom::RequestInit const&, mozilla::ErrorResult&) dom/fetch/Request.cpp:581 #4 0x7f6f63c1c7c6 in mozilla::dom::RequestBinding::_constructor(JSContext*, unsigned int, JS::Value*) objdir-ff-asan/dom/bindings/RequestBinding.cpp:1851:53 #5 0x7f6f697c0069 in CallJSNative js/src/jscntxtinlines.h:293:15 #6 0x7f6f697c0069 in CallJSNativeConstructor js/src/jscntxtinlines.h:326 #7 0x7f6f697c0069 in InternalConstruct(JSContext*, js::AnyConstructArgs const&) js/src/vm/Interpreter.cpp:573 #8 0x7f6f697bfe2c in js::ConstructFromStack(JSContext*, JS::CallArgs const&) js/src/vm/Interpreter.cpp:599:12 #9 0x7f6f6979b493 in Interpret(JSContext*, js::RunState&) js/src/vm/Interpreter.cpp:3056:18 #10 0x7f6f697941bb in js::RunScript(JSContext*, js::RunState&) js/src/vm/Interpreter.cpp:410:12 #11 0x7f6f697c153a in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, js::AbstractFramePtr, JS::Value*) js/src/vm/Interpreter.cpp:699:15 #12 0x7f6f697c1ec1 in js::Execute(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value*) js/src/vm/Interpreter.cpp:731:12 #13 0x7f6f69efa8ea in Evaluate(JSContext*, js::ScopeKind, JS::Handle<JSObject*>, JS::ReadOnlyCompileOptions const&, JS::SourceBufferHolder&, JS::MutableHandleJS::Value) js/src/jsapi.cpp:4662:19 #14 0x7f6f69efac60 in JS::Evaluate(JSContext*, JS::ReadOnlyCompileOptions const&, JS::SourceBufferHolder&, JS::MutableHandleJS::Value) js/src/jsapi.cpp:4727:12 #15 0x7f6f65a537ee in (anonymous namespace)::ScriptExecutorRunnable::WorkerRun(JSContext*, mozilla::dom::workers::WorkerPrivate*) dom/workers/ScriptLoader.cpp:1969:10 #16 0x7f6f65ae4ad1 in mozilla::dom::workers::WorkerRunnable::Run() dom/workers/WorkerRunnable.cpp:374:12 #17 0x7f6f611ad373 in nsThread::ProcessNextEvent(bool, bool*) xpcom/threads/nsThread.cpp:1406:14 #18 0x7f6f611b7278 in NS_ProcessNextEvent(nsIThread*, bool) xpcom/threads/nsThreadUtils.cpp:472:10 #19 0x7f6f65ad11b3 in mozilla::dom::workers::WorkerPrivate::RunCurrentSyncLoop() dom/workers/WorkerPrivate.cpp:5874:7 #20 0x7f6f65a16e51 in (anonymous namespace)::LoadAllScripts(mozilla::dom::workers::WorkerPrivate*, nsTArray<(anonymous namespace)::ScriptLoadInfo>&, bool, mozilla::dom::workers::WorkerScriptType, mozilla::ErrorResult&) dom/workers/ScriptLoader.cpp:2127:12 #21 0x7f6f65a169b0 in mozilla::dom::workers::scriptloader::LoadMainScript(mozilla::dom::workers::WorkerPrivate*, nsAString const&, mozilla::dom::workers::WorkerScriptType, mozilla::ErrorResult&) dom/workers/ScriptLoader.cpp:2245:3 #22 0x7f6f65af35bb in (anonymous namespace)::CompileScriptRunnable::WorkerRun(JSContext*, mozilla::dom::workers::WorkerPrivate*) dom/workers/WorkerPrivate.cpp:586:5 #23 0x7f6f65ae4ad1 in mozilla::dom::workers::WorkerRunnable::Run() dom/workers/WorkerRunnable.cpp:374:12 #24 0x7f6f611ad373 in nsThread::ProcessNextEvent(bool, bool*) xpcom/threads/nsThread.cpp:1406:14 #25 0x7f6f611b7278 in NS_ProcessNextEvent(nsIThread*, bool) xpcom/threads/nsThreadUtils.cpp:472:10 #26 0x7f6f65acb4fb in mozilla::dom::workers::WorkerPrivate::DoRunLoop(JSContext*) dom/workers/WorkerPrivate.cpp:5115:7 #27 0x7f6f65a47ebb in (anonymous namespace)::WorkerThreadPrimaryRunnable::Run() dom/workers/RuntimeService.cpp:2919:25 #28 0x7f6f611ad373 in nsThread::ProcessNextEvent(bool, bool*) xpcom/threads/nsThread.cpp:1406:14 #29 0x7f6f611b7278 in NS_ProcessNextEvent(nsIThread*, bool) xpcom/threads/nsThreadUtils.cpp:472:10 #30 0x7f6f61d67896 in mozilla::ipc::MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate*) ipc/glue/MessagePump.cpp:338:20 #31 0x7f6f61ccd9ed in RunHandler ipc/chromium/src/base/message_loop.cc:231:3 #32 0x7f6f61ccd9ed in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:211 #33 0x7f6f611a650f in nsThread::ThreadFunc(void*) xpcom/threads/nsThread.cpp:501:11

Thread T104 (DOM Worker) created by T0 (Web Content) here: #0 0x4362cd in __interceptor_pthread_create /build/llvm/projects/compiler-rt/lib/asan/asan_interceptors.cc:314 #1 0x7f6f775cee35 in _PR_CreateThread nsprpub/pr/src/pthreads/ptthread.c:457:14 #2 0x7f6f775cea2e in PR_CreateThread nsprpub/pr/src/pthreads/ptthread.c:548:12 #3 0x7f6f611a83d1 in nsThread::Init(nsACString const&) xpcom/threads/nsThread.cpp:683:8 #4 0x7f6f65aeeecb in mozilla::dom::workers::WorkerThread::Create(mozilla::dom::workers::WorkerThreadFriendKey const&) dom/workers/WorkerThread.cpp:90:7 #5 0x7f6f65a0edc1 in mozilla::dom::workers::RuntimeService::ScheduleWorker(mozilla::dom::workers::WorkerPrivate*) dom/workers/RuntimeService.cpp:1918:14 #6 0x7f6f65a0d298 in mozilla::dom::workers::RuntimeService::RegisterWorker(mozilla::dom::workers::WorkerPrivate*) dom/workers/RuntimeService.cpp:1745:19 #7 0x7f6f65ac8533 in mozilla::dom::workers::WorkerPrivate::Constructor(JSContext*, nsAString const&, bool, mozilla::dom::WorkerType, nsAString const&, nsACString const&, mozilla::dom::workers::WorkerLoadInfo*, mozilla::ErrorResult&) dom/workers/WorkerPrivate.cpp:4657:24 #8 0x7f6f65ac7e1d in mozilla::dom::workers::WorkerPrivate::Constructor(mozilla::dom::GlobalObject const&, nsAString const&, bool, mozilla::dom::WorkerType, nsAString const&, mozilla::dom::workers::WorkerLoadInfo*, mozilla::ErrorResult&) dom/workers/WorkerPrivate.cpp:4574:10 #9 0x7f6f65ac7daf in mozilla::dom::workers::WorkerPrivate::Constructor(mozilla::dom::GlobalObject const&, nsAString const&, mozilla::dom::WorkerOptions const&, mozilla::ErrorResult&) dom/workers/WorkerPrivate.cpp:4515:10 #10 0x7f6f642848bf in mozilla::dom::WorkerBinding::_constructor(JSContext*, unsigned int, JS::Value*) objdir-ff-asan/dom/bindings/WorkerBinding.cpp:971:68 #11 0x7f6f697c0069 in CallJSNative js/src/jscntxtinlines.h:293:15 #12 0x7f6f697c0069 in CallJSNativeConstructor js/src/jscntxtinlines.h:326 #13 0x7f6f697c0069 in InternalConstruct(JSContext*, js::AnyConstructArgs const&) js/src/vm/Interpreter.cpp:573 #14 0x7f6f697bfe2c in js::ConstructFromStack(JSContext*, JS::CallArgs const&) js/src/vm/Interpreter.cpp:599:12 #15 0x7f6f6979b493 in Interpret(JSContext*, js::RunState&) js/src/vm/Interpreter.cpp:3056:18 #16 0x7f6f697941bb in js::RunScript(JSContext*, js::RunState&) js/src/vm/Interpreter.cpp:410:12 #17 0x7f6f697c153a in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, js::AbstractFramePtr, JS::Value*) js/src/vm/Interpreter.cpp:699:15 #18 0x7f6f697c1ec1 in js::Execute(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value*) js/src/vm/Interpreter.cpp:731:12 #19 0x7f6f69ef98ee in ExecuteScript(JSContext*, JS::AutoObjectVector&, JS::Handle<JSScript*>, JS::Value*) js/src/jsapi.cpp:4578:12 #20 0x7f6f69ef95c4 in JS_ExecuteScript(JSContext*, JS::AutoObjectVector&, JS::Handle<JSScript*>, JS::MutableHandleJS::Value) js/src/jsapi.cpp:4599:12 #21 0x7f6f63547b68 in nsJSUtils::ExecutionContext::CompileAndExec(JS::CompileOptions&, JS::SourceBufferHolder&, JS::MutableHandle<JSScript*>) dom/base/nsJSUtils.cpp:267:8 #22 0x7f6f65e2fd93 in mozilla::dom::ScriptLoader::EvaluateScript(mozilla::dom::ScriptLoadRequest*) dom/script/ScriptLoader.cpp:2129:25 #23 0x7f6f65e2d254 in mozilla::dom::ScriptLoader::ProcessRequest(mozilla::dom::ScriptLoadRequest*) dom/script/ScriptLoader.cpp:1725:10 #24 0x7f6f65e1bf5b in mozilla::dom::ScriptLoader::ProcessScriptElement(nsIScriptElement*) dom/script/ScriptLoader.cpp:1427:10 #25 0x7f6f65e19a3c in mozilla::dom::ScriptElement::MaybeProcessScript() dom/script/ScriptElement.cpp:149:18 #26 0x7f6f6289453d in nsIScriptElement::AttemptToExecute() objdir-ff-asan/dist/include/nsIScriptElement.h:225:18 #27 0x7f6f62893b13 in nsHtml5TreeOpExecutor::RunScript(nsIContent*) parser/html/nsHtml5TreeOpExecutor.cpp:698:22 #28 0x7f6f6288f693 in nsHtml5TreeOpExecutor::RunFlushLoop() parser/html/nsHtml5TreeOpExecutor.cpp:499:7 #29 0x7f6f62897265 in nsHtml5ExecutorFlusher::Run() parser/html/nsHtml5StreamParser.cpp:129:20 #30 0x7f6f611827c8 in mozilla::SchedulerGroup::Runnable::Run() xpcom/threads/SchedulerGroup.cpp:359:25 #31 0x7f6f611ad373 in nsThread::ProcessNextEvent(bool, bool*) xpcom/threads/nsThread.cpp:1406:14 #32 0x7f6f611b7278 in NS_ProcessNextEvent(nsIThread*, bool) xpcom/threads/nsThreadUtils.cpp:472:10 #33 0x7f6f61d66358 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) ipc/glue/MessagePump.cpp:96:21 #34 0x7f6f61ccd9ed in RunHandler ipc/chromium/src/base/message_loop.cc:231:3 #35 0x7f6f61ccd9ed in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:211 #36 0x7f6f65f1b0fa in nsBaseAppShell::Run() widget/nsBaseAppShell.cpp:156:27 #37 0x7f6f693d6aac in XRE_RunAppShell() toolkit/xre/nsEmbedFunctions.cpp:896:22 #38 0x7f6f61ccd9ed in RunHandler ipc/chromium/src/base/message_loop.cc:231:3 #39 0x7f6f61ccd9ed in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:211 #40 0x7f6f693d6598 in XRE_InitChildProcess(int, char**, XREChildData const*) toolkit/xre/nsEmbedFunctions.cpp:712:34 #41 0x524fc1 in content_process_main browser/app/../../ipc/contentproc/plugin-container.cpp:64:30 #42 0x524fc1 in main browser/app/nsBrowserApp.cpp:286 #43 0x7f6f79ee7f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

SUMMARY: AddressSanitizer: heap-use-after-free dom/fetch/Fetch.cpp:1006:21 in mozilla::dom::(anonymous namespace)::ConsumeBodyDoneObservermozilla::dom::Request::OnStreamComplete(nsIStreamLoader*, nsISupports*, nsresult, unsigned int, unsigned char const*) Shadow bytes around the buggy address: 0x0c1a80004ce0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c1a80004cf0: fa fa fa fa fa fa fa fa fa fa fa fa fd fd fd fd 0x0c1a80004d00: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa 0x0c1a80004d10: fa fa fa fa fa fa fd fd fd fd fd fd fd fd fd fd 0x0c1a80004d20: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa =>0x0c1a80004d30: fd fd[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c1a80004d40: fd fd fa fa fa fa fa fa fa fa fd fd fd fd fd fd 0x0c1a80004d50: fd fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa 0x0c1a80004d60: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd 0x0c1a80004d70: fd fd fd fd fd fa fa fa fa fa fa fa fa fa fa fa 0x0c1a80004d80: 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 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 ==107957==ABORTING

The original report as published on Mozilla's Bugzilla, by Abhishek Arya. 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 the ConsumeBodyDoneObserver holds a raw pointer to the Request that is not kept alive across the asynchronous stream completion, so the worker's cycle collector frees the Request before OnStreamComplete runs.

Impact

A crafted page could cause a heap use-after-free in the content process, leading to a crash and potentially to code execution within the browser's sandboxed content process.

What the attacker needed

Victim visits a crafted page; page runs script in a DOM Worker

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 web page asks the browser to fetch a resource, the browser creates an internal object to track that request. Here, that object was created inside a background worker (a script running off the main page thread) and was cleaned up by the worker's garbage collector while a network callback was still trying to read it. Reading memory that has already been freed is a use-after-free, a serious memory-safety bug that can crash the browser and sometimes be turned into code execution.

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 Abhishek Arya

View all

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