Skip to content
Memory corruption Disclosed report Advanced

Heap-use-after-free in mozilla::MediaStreamGraphImpl::UpdateMainThreadState

A heap-use-after-free occurs in Firefox's media stream graph code when a driver object is freed on one thread while another thread still reads from it. An attacker could potentially trigger a crash or memory corruption by causing the audio driver to be torn down and restarted through crafted media content.

Abhishek Arya Follow

Originally disclosed on Mozilla

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

Created attachment 8894755 test.html

================================================================= ==66387==ERROR: AddressSanitizer: heap-use-after-free on address 0x60b0000d8758 at pc 0x7f787015500b bp 0x7f783a3fdbd0 sp 0x7f783a3fdbc8 READ of size 4 at 0x60b0000d8758 thread T103 (MediaStreamGrph) #0 0x7f787015500a in mozilla::SystemClockDriver::WaitForNextIteration() /build/firefox/src/dom/media/GraphDriver.cpp:420:7 #1 0x7f78703e964b in mozilla::MediaStreamGraphImpl::UpdateMainThreadState() /build/firefox/src/dom/media/MediaStreamGraph.cpp:1439:20 #2 0x7f78703e99d0 in mozilla::MediaStreamGraphImpl::OneIteration(long) /build/firefox/src/dom/media/MediaStreamGraph.cpp:1471:10 #3 0x7f787015385b in mozilla::ThreadedDriver::RunThread() /build/firefox/src/dom/media/GraphDriver.cpp:340:35 #4 0x7f78701817cf in mozilla::MediaStreamGraphInitThreadRunnable::Run() /build/firefox/src/dom/media/GraphDriver.cpp:209:14 #5 0x7f7869ce88b6 in nsThread::ProcessNextEvent(bool, bool*) /build/firefox/src/xpcom/threads/nsThread.cpp:1446:14 #6 0x7f7869cf05a6 in NS_ProcessNextEvent(nsIThread*, bool) /build/firefox/src/xpcom/threads/nsThreadUtils.cpp:480:10 #7 0x7f786ae57e08 in mozilla::ipc::MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate*) /build/firefox/src/ipc/glue/MessagePump.cpp:339:20 #8 0x7f786ad93814 in RunInternal /build/firefox/src/ipc/chromium/src/base/message_loop.cc:326:10 #9 0x7f786ad93814 in RunHandler /build/firefox/src/ipc/chromium/src/base/message_loop.cc:319 #10 0x7f786ad93814 in MessageLoop::Run() /build/firefox/src/ipc/chromium/src/base/message_loop.cc:299 #11 0x7f7869cde85c in nsThread::ThreadFunc(void*) /build/firefox/src/xpcom/threads/nsThread.cpp:506:11 #12 0x7f78866d0d0a in _pt_root /build/firefox/src/nsprpub/pr/src/pthreads/ptthread.c:216:5 #13 0x7f788a029183 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8183) #14 0x7f7889129ffc in clone (/lib/x86_64-linux-gnu/libc.so.6+0xfdffc)

0x60b0000d8758 is located 40 bytes inside of 104-byte region [0x60b0000d8730,0x60b0000d8798) freed by thread T106 (MediaStreamGrph) here: #0 0x4e9550 in __interceptor_free /build/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:47 #1 0x7f7870181d5d in Release /build/firefox/src/dom/media/GraphDriver.h:112:3 #2 0x7f7870181d5d in Release /build/firefox/src/objdir-ff-asan/dist/include/mozilla/RefPtr.h:40 #3 0x7f7870181d5d in Release /build/firefox/src/objdir-ff-asan/dist/include/mozilla/RefPtr.h:395 #4 0x7f7870181d5d in ~RefPtr /build/firefox/src/objdir-ff-asan/dist/include/mozilla/RefPtr.h:78 #5 0x7f7870181d5d in ~MediaStreamGraphInitThreadRunnable /build/firefox/src/dom/media/GraphDriver.cpp:172 #6 0x7f7870181d5d in mozilla::MediaStreamGraphInitThreadRunnable::~MediaStreamGraphInitThreadRunnable() /build/firefox/src/dom/media/GraphDriver.cpp:172 #7 0x7f7869cf778e in mozilla::Runnable::Release() /build/firefox/src/xpcom/threads/nsThreadUtils.cpp:44:1 #8 0x7f7869ce8a8c in ~nsCOMPtr_base /build/firefox/src/objdir-ff-asan/dist/include/nsCOMPtr.h:294:7 #9 0x7f7869ce8a8c in nsThread::ProcessNextEvent(bool, bool*) /build/firefox/src/xpcom/threads/nsThread.cpp:1452 #10 0x7f7869cf05a6 in NS_ProcessNextEvent(nsIThread*, bool) /build/firefox/src/xpcom/threads/nsThreadUtils.cpp:480:10 #11 0x7f786ae57e08 in mozilla::ipc::MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate*) /build/firefox/src/ipc/glue/MessagePump.cpp:339:20 #12 0x7f786ad93814 in RunInternal /build/firefox/src/ipc/chromium/src/base/message_loop.cc:326:10 #13 0x7f786ad93814 in RunHandler /build/firefox/src/ipc/chromium/src/base/message_loop.cc:319 #14 0x7f786ad93814 in MessageLoop::Run() /build/firefox/src/ipc/chromium/src/base/message_loop.cc:299 #15 0x7f7869cde85c in nsThread::ThreadFunc(void*) /build/firefox/src/xpcom/threads/nsThread.cpp:506:11 #16 0x7f78866d0d0a in _pt_root /build/firefox/src/nsprpub/pr/src/pthreads/ptthread.c:216:5 #17 0x7f788a029183 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8183)

previously allocated by thread T102 (CubebOp~tion #1) here: #0 0x4e98b8 in malloc /build/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:67 #1 0x524b7d in moz_xmalloc /build/firefox/src/memory/mozalloc/mozalloc.cpp:83:17 #2 0x7f78701576ce in operator new /build/firefox/src/objdir-ff-asan/dist/include/mozilla/mozalloc.h:200:12 #3 0x7f78701576ce in mozilla::AudioCallbackDriver::Init() /build/firefox/src/dom/media/GraphDriver.cpp:732 #4 0x7f7870156577 in mozilla::AsyncCubebTask::Run() /build/firefox/src/dom/media/GraphDriver.cpp:526:21 #5 0x7f7869cf4c01 in nsThreadPool::Run() /build/firefox/src/xpcom/threads/nsThreadPool.cpp:225:14 #6 0x7f7869cf53c0 in non-virtual thunk to nsThreadPool::Run() /build/firefox/src/xpcom/threads/nsThreadPool.cpp #7 0x7f7869ce88b6 in nsThread::ProcessNextEvent(bool, bool*) /build/firefox/src/xpcom/threads/nsThread.cpp:1446:14 #8 0x7f7869cf05a6 in NS_ProcessNextEvent(nsIThread*, bool) /build/firefox/src/xpcom/threads/nsThreadUtils.cpp:480:10 #9 0x7f786ae57e08 in mozilla::ipc::MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate*) /build/firefox/src/ipc/glue/MessagePump.cpp:339:20 #10 0x7f786ad93814 in RunInternal /build/firefox/src/ipc/chromium/src/base/message_loop.cc:326:10 #11 0x7f786ad93814 in RunHandler /build/firefox/src/ipc/chromium/src/base/message_loop.cc:319 #12 0x7f786ad93814 in MessageLoop::Run() /build/firefox/src/ipc/chromium/src/base/message_loop.cc:299 #13 0x7f7869cde85c in nsThread::ThreadFunc(void*) /build/firefox/src/xpcom/threads/nsThread.cpp:506:11 #14 0x7f78866d0d0a in _pt_root /build/firefox/src/nsprpub/pr/src/pthreads/ptthread.c:216:5 #15 0x7f788a029183 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8183)

Thread T103 (MediaStreamGrph) created by T101 (threaded-ml) here: #0 0x43656d in __interceptor_pthread_create /build/llvm/projects/compiler-rt/lib/asan/asan_interceptors.cc:313 #1 0x7f78866cce0d in _PR_CreateThread /build/firefox/src/nsprpub/pr/src/pthreads/ptthread.c:457:14 #2 0x7f78866cc91a in PR_CreateThread /build/firefox/src/nsprpub/pr/src/pthreads/ptthread.c:548:12 #3 0x7f7869ce1676 in nsThread::Init(nsACString const&) /build/firefox/src/xpcom/threads/nsThread.cpp:688:8 #4 0x7f7869cef391 in nsThreadManager::NewNamedThread(nsACString const&, unsigned int, nsIThread**) /build/firefox/src/xpcom/threads/nsThreadManager.cpp:274:22 #5 0x7f7869cf354c in NS_NewNamedThread(nsACString const&, nsIThread**, nsIRunnable*, unsigned int) /build/firefox/src/xpcom/threads/nsThreadUtils.cpp:104:45 #6 0x7f78701520ae in NS_NewNamedThread<16> /build/firefox/src/objdir-ff-asan/dist/include/nsThreadUtils.h:72:10 #7 0x7f78701520ae in mozilla::ThreadedDriver::Start() /build/firefox/src/dom/media/GraphDriver.cpp:225 #8 0x7f787015febc in mozilla::AudioCallbackDriver::StateCallback(cubeb_state) /build/firefox/src/dom/media/GraphDriver.cpp:1078:17 #9 0x7f78793ca708 in cubeb_pulse::backend::stream::{{impl}}::state_change_callback /build/firefox/src/media/libcubeb/cubeb-pulse-rs/src/backend/stream.rs:651 #10 0x7f78793ca708 in cubeb_pulse::backend::stream::{{impl}}::new::check_error /build/firefox/src/media/libcubeb/cubeb-pulse-rs/src/backend/stream.rs:107 #11 0x7f78793ca708 in core::ops::Fn::call<fn(&pulse::stream::Stream, *mut std::os::raw::c_void),(&pulse::stream::Stream, *mut std::os::raw::c_void)> /checkout/src/libcore/ops.rs:2588 #12 0x7f78793ca708 in pulse::stream::Stream::set_state_callback::wrapped::h9463fe3761c37711 /build/firefox/src/media/libcubeb/cubeb-pulse-rs/pulse-rs/src/stream.rs:230 #13 0x7f78411cfc91 (/usr/lib/x86_64-linux-gnu/libpulse.so.0+0x28c91)

Thread T101 (threaded-ml) created by T0 (Web Content) here: #0 0x43656d in __interceptor_pthread_create /build/llvm/projects/compiler-rt/lib/asan/asan_interceptors.cc:313 #1 0x7f7840d7a74c in pa_thread_new (/usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-4.0.so+0x4574c)

Thread T106 (MediaStreamGrph) created by T102 (CubebOp~tion #1) here: #0 0x43656d in __interceptor_pthread_create /build/llvm/projects/compiler-rt/lib/asan/asan_interceptors.cc:313 #1 0x7f78866cce0d in _PR_CreateThread /build/firefox/src/nsprpub/pr/src/pthreads/ptthread.c:457:14 #2 0x7f78866cc91a in PR_CreateThread /build/firefox/src/nsprpub/pr/src/pthreads/ptthread.c:548:12 #3 0x7f7869ce1676 in nsThread::Init(nsACString const&) /build/firefox/src/xpcom/threads/nsThread.cpp:688:8 #4 0x7f7869cef391 in nsThreadManager::NewNamedThread(nsACString const&, unsigned int, nsIThread**) /build/firefox/src/xpcom/threads/nsThreadManager.cpp:274:22 #5 0x7f7869cf354c in NS_NewNamedThread(nsACString const&, nsIThread**, nsIRunnable*, unsigned int) /build/firefox/src/xpcom/threads/nsThreadUtils.cpp:104:45 #6 0x7f78701520ae in NS_NewNamedThread<16> /build/firefox/src/objdir-ff-asan/dist/include/nsThreadUtils.h:72:10 #7 0x7f78701520ae in mozilla::ThreadedDriver::Start() /build/firefox/src/dom/media/GraphDriver.cpp:225 #8 0x7f7870157ba2 in mozilla::AudioCallbackDriver::Init() /build/firefox/src/dom/media/GraphDriver.cpp:740:19 #9 0x7f7870156577 in mozilla::AsyncCubebTask::Run() /build/firefox/src/dom/media/GraphDriver.cpp:526:21 #10 0x7f7869cf4c01 in nsThreadPool::Run() /build/firefox/src/xpcom/threads/nsThreadPool.cpp:225:14 #11 0x7f7869cf53c0 in non-virtual thunk to nsThreadPool::Run() /build/firefox/src/xpcom/threads/nsThreadPool.cpp #12 0x7f7869ce88b6 in nsThread::ProcessNextEvent(bool, bool*) /build/firefox/src/xpcom/threads/nsThread.cpp:1446:14 #13 0x7f7869cf05a6 in NS_ProcessNextEvent(nsIThread*, bool) /build/firefox/src/xpcom/threads/nsThreadUtils.cpp:480:10 #14 0x7f786ae57e08 in mozilla::ipc::MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate*) /build/firefox/src/ipc/glue/MessagePump.cpp:339:20 #15 0x7f786ad93814 in RunInternal /build/firefox/src/ipc/chromium/src/base/message_loop.cc:326:10 #16 0x7f786ad93814 in RunHandler /build/firefox/src/ipc/chromium/src/base/message_loop.cc:319 #17 0x7f786ad93814 in MessageLoop::Run() /build/firefox/src/ipc/chromium/src/base/message_loop.cc:299 #18 0x7f7869cde85c in nsThread::ThreadFunc(void*) /build/firefox/src/xpcom/threads/nsThread.cpp:506:11 #19 0x7f78866d0d0a in _pt_root /build/firefox/src/nsprpub/pr/src/pthreads/ptthread.c:216:5 #20 0x7f788a029183 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8183)

Thread T102 (CubebOp~tion #1) created by T0 (Web Content) here: #0 0x43656d in __interceptor_pthread_create /build/llvm/projects/compiler-rt/lib/asan/asan_interceptors.cc:313 #1 0x7f78866cce0d in _PR_CreateThread /build/firefox/src/nsprpub/pr/src/pthreads/ptthread.c:457:14 #2 0x7f78866cc91a in PR_CreateThread /build/firefox/src/nsprpub/pr/src/pthreads/ptthread.c:548:12 #3 0x7f7869ce1676 in nsThread::Init(nsACString const&) /build/firefox/src/xpcom/threads/nsThread.cpp:688:8 #4 0x7f7869cef391 in nsThreadManager::NewNamedThread(nsACString const&, unsigned int, nsIThread**) /build/firefox/src/xpcom/threads/nsThreadManager.cpp:274:22 #5 0x7f7869cf2ca6 in NS_NewNamedThread /build/firefox/src/xpcom/threads/nsThreadUtils.cpp:104:45 #6 0x7f7869cf2ca6 in nsThreadPool::PutEvent(already_AddRefed<nsIRunnable>, unsigned int) /build/firefox/src/xpcom/threads/nsThreadPool.cpp:107 #7 0x7f7869cf5766 in nsThreadPool::Dispatch(already_AddRefed<nsIRunnable>, unsigned int) /build/firefox/src/xpcom/threads/nsThreadPool.cpp:274:5 #8 0x7f7869cbfd59 in mozilla::SharedThreadPool::Dispatch(already_AddRefed<nsIRunnable>, unsigned int) /build/firefox/src/objdir-ff-asan/dist/include/mozilla/SharedThreadPool.h:71:68 #9 0x7f787015b866 in Dispatch /build/firefox/src/objdir-ff-asan/dist/include/nsIEventTarget.h:37:14 #10 0x7f787015b866 in Dispatch /build/firefox/src/dom/media/GraphDriver.h:555 #11 0x7f787015b866 in mozilla::AudioCallbackDriver::Start() /build/firefox/src/dom/media/GraphDriver.cpp:802 #12 0x7f78703eb9e0 in mozilla::MediaStreamGraphImpl::RunInStableState(bool) /build/firefox/src/dom/media/MediaStreamGraph.cpp:1776:17 #13 0x7f787041a8bd in mozilla::(anonymous namespace)::MediaStreamGraphStableStateRunnable::Run() /build/firefox/src/dom/media/MediaStreamGraph.cpp:1631:15 #14 0x7f7869afcf06 in mozilla::CycleCollectedJSContext::ProcessStableStateQueue() /build/firefox/src/xpcom/base/CycleCollectedJSContext.cpp:309:12 #15 0x7f786ba5b329 in XPCJSContext::AfterProcessTask(unsigned int) /build/firefox/src/js/xpconnect/src/XPCJSContext.cpp:1010:30 #16 0x7f7869ce8f7c in nsThread::ProcessNextEvent(bool, bool*) /build/firefox/src/xpcom/threads/nsThread.cpp:1462:24 #17 0x7f7869cf05a6 in NS_ProcessNextEvent(nsIThread*, bool) /build/firefox/src/xpcom/threads/nsThreadUtils.cpp:480:10 #18 0x7f786ae565d9 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /build/firefox/src/ipc/glue/MessagePump.cpp:125:5 #19 0x7f786ad93814 in RunInternal /build/firefox/src/ipc/chromium/src/base/message_loop.cc:326:10 #20 0x7f786ad93814 in RunHandler /build/firefox/src/ipc/chromium/src/base/message_loop.cc:319 #21 0x7f786ad93814 in MessageLoop::Run() /build/firefox/src/ipc/chromium/src/base/message_loop.cc:299 #22 0x7f7871c6ef92 in nsBaseAppShell::Run() /build/firefox/src/widget/nsBaseAppShell.cpp:156:27 #23 0x7f7876dc9537 in XRE_RunAppShell() /build/firefox/src/toolkit/xre/nsEmbedFunctions.cpp:882:22 #24 0x7f786ad93814 in RunInternal /build/firefox/src/ipc/chromium/src/base/message_loop.cc:326:10 #25 0x7f786ad93814 in RunHandler /build/firefox/src/ipc/chromium/src/base/message_loop.cc:319 #26 0x7f786ad93814 in MessageLoop::Run() /build/firefox/src/ipc/chromium/src/base/message_loop.cc:299 #27 0x7f7876dc8eec in XRE_InitChildProcess(int, char**, XREChildData const*) /build/firefox/src/toolkit/xre/nsEmbedFunctions.cpp:699:34 #28 0x523945 in content_process_main /build/firefox/src/browser/app/../../ipc/contentproc/plugin-container.cpp:64:30 #29 0x523945 in main /build/firefox/src/browser/app/nsBrowserApp.cpp:285 #30 0x7f788904df44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)

SUMMARY: AddressSanitizer: heap-use-after-free /build/firefox/src/dom/media/GraphDriver.cpp:420:7 in mozilla::SystemClockDriver::WaitForNextIteration() Shadow bytes around the buggy address: 0x0c1680013090: fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa fa 0x0c16800130a0: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd 0x0c16800130b0: fd fa fa fa fa fa fa fa fa fa fd fd fd fd fd fd 0x0c16800130c0: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa 0x0c16800130d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa =>0x0c16800130e0: fa fa fa fa fa fa fd fd fd fd fd[fd]fd fd fd fd 0x0c16800130f0: fd fd fd fa fa fa fa fa fa fa fa fa fd fd fd fd 0x0c1680013100: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa 0x0c1680013110: fa fa fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c1680013120: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c1680013130: 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 ==66387==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 a race between the audio callback driver being released on one thread and the media stream graph thread still reading the driver during its iteration.

Impact

Could cause a crash or potentially exploitable memory corruption in the content process.

What the attacker needed

Crafted media content; audio output device present

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 memory but keeps using it, that is a use-after-free. Here, one part of Firefox released an audio driver object while another part was still reading from it, which can crash the browser or let an attacker corrupt 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 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.