Skip to content
Memory corruption Disclosed report Advanced

Heap-use-after-free in UnhookTextRunFromFrames

A heap-use-after-free occurs in UnhookTextRunFromFrames when a text run is accessed after its memory has been freed. An attacker could potentially crash the browser by causing the expiration tracker to fire after the presentation shell is destroyed.

Abhishek Arya Follow

Originally disclosed on Mozilla

Critical View original
  • Fixed in 5 days
  • Paid in 48 days
  • Disclosed after 5 days

Created attachment 8575775 Testcase

Let the repro run for 30 secs and in a few refreshes, you will see a crash.

==7620==ERROR: AddressSanitizer: heap-use-after-free on address 0x6250002e5f38 at pc 0x7f9fdd6d4490 bp 0x7fff7c02cc00 sp 0x7fff7c02cbf8 READ of size 8 at 0x6250002e5f38 thread T0 (Web Content) #0 0x7f9fdd6d448f in GetTextRun /build/firefox/src/layout/generic/nsTextFrame.h:471:14 #1 0x7f9fdd6d448f in UnhookTextRunFromFrames(gfxTextRun*, nsTextFrame*) /build/firefox/src/layout/generic/nsTextFrame.cpp:474 #2 0x7f9fdd718d66 in FrameTextRunCache::NotifyExpired(gfxTextRun*) /build/firefox/src/layout/generic/nsTextFrame.cpp:567:5 #3 0x7f9fdd71d4a9 in AgeOneGeneration /build/firefox/src/objdir-ff-asan/layout/generic/../../dist/include/nsExpirationTracker.h:204:7 #4 0x7f9fdd71d4a9 in nsExpirationTracker<gfxTextRun, 3u>::TimerCallback(nsITimer*, void*) /build/firefox/src/objdir-ff-asan/layout/generic/../../dist/include/nsExpirationTracker.h:343 #5 0x7f9fd787a65f in nsTimerImpl::Fire() /build/firefox/src/xpcom/threads/nsTimerImpl.cpp:631:7 #6 0x7f9fd787b1f6 in nsTimerEvent::Run() /build/firefox/src/xpcom/threads/nsTimerImpl.cpp:724:3 #7 0x7f9fd78708d6 in nsThread::ProcessNextEvent(bool, bool*) /build/firefox/src/xpcom/threads/nsThread.cpp:855:7 #8 0x7f9fd78ca5b0 in NS_ProcessNextEvent(nsIThread*, bool) /build/firefox/src/xpcom/glue/nsThreadUtils.cpp:265:10 #9 0x7f9fd81518df in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /build/firefox/src/ipc/glue/MessagePump.cpp:140:5 #10 0x7f9fd80fe2a1 in RunInternal /build/firefox/src/ipc/chromium/src/base/message_loop.cc:233:3 #11 0x7f9fd80fe2a1 in RunHandler /build/firefox/src/ipc/chromium/src/base/message_loop.cc:226 #12 0x7f9fd80fe2a1 in MessageLoop::Run() /build/firefox/src/ipc/chromium/src/base/message_loop.cc:200 #13 0x7f9fdcb6ba4f in nsBaseAppShell::Run() /build/firefox/src/widget/nsBaseAppShell.cpp:164:3 #14 0x7f9fde77c6d3 in XRE_RunAppShell /build/firefox/src/toolkit/xre/nsEmbedFunctions.cpp:743:12 #15 0x7f9fd80fe2a1 in RunInternal /build/firefox/src/ipc/chromium/src/base/message_loop.cc:233:3 #16 0x7f9fd80fe2a1 in RunHandler /build/firefox/src/ipc/chromium/src/base/message_loop.cc:226 #17 0x7f9fd80fe2a1 in MessageLoop::Run() /build/firefox/src/ipc/chromium/src/base/message_loop.cc:200 #18 0x7f9fde77bb0c in XRE_InitChildProcess /build/firefox/src/toolkit/xre/nsEmbedFunctions.cpp:580:7 #19 0x4dc17e in content_process_main(int, char**) /build/firefox/src/ipc/app/../contentproc/plugin-container.cpp:211:19 #20 0x7f9fd4deaec4 in __libc_start_main #21 0x41c438 in _start

0x6250002e5f38 is located 7736 bytes inside of 8192-byte region [0x6250002e4100,0x6250002e6100) freed by thread T0 (Web Content) here: #0 0x4b4b00 in __interceptor_free asan_rtl #1 0x7f9fe46ef660 in FreeArenaList /build/firefox/src/nsprpub/lib/ds/plarena.c:277:13 #2 0x7f9fdd1ab55f in nsPresArena::~nsPresArena() /build/firefox/src/layout/base/nsPresArena.cpp:42:3 #3 0x7f9fdd42258d in PresShell::~PresShell() /build/firefox/src/layout/base/nsPresShell.cpp:811:1 #4 0x7f9fdd41f021 in PresShell::Release() /build/firefox/src/layout/base/nsPresShell.cpp:805:1 #5 0x7f9fdd38bb6b in operator= /build/firefox/src/objdir-ff-asan/layout/base/../../dist/include/nsCOMPtr.h:546:5 #6 0x7f9fdd38bb6b in nsDocumentViewer::DestroyPresShell() /build/firefox/src/layout/base/nsDocumentViewer.cpp:4430 #7 0x7f9fdd37b1ac in nsDocumentViewer::Destroy() /build/firefox/src/layout/base/nsDocumentViewer.cpp:1673:5 #8 0x7f9fdd38d96c in nsDocumentViewer::Show() /build/firefox/src/layout/base/nsDocumentViewer.cpp:1991:5 #9 0x7f9fdd415ed9 in nsPresContext::EnsureVisible() /build/firefox/src/layout/base/nsPresContext.cpp:2005:27 #10 0x7f9fdd441e81 in PresShell::UnsuppressAndInvalidate() /build/firefox/src/layout/base/nsPresShell.cpp:3978:40 #11 0x7f9fdd383f12 in nsDocumentViewer::LoadComplete(nsresult) /build/firefox/src/layout/base/nsDocumentViewer.cpp:1032:7 #12 0x7f9fddfbf664 in nsDocShell::EndPageLoad(nsIWebProgress*, nsIChannel*, nsresult) /build/firefox/src/docshell/base/nsDocShell.cpp:7507:5 #13 0x7f9fddfbbb47 in nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /build/firefox/src/docshell/base/nsDocShell.cpp:7324:7 #14 0x7f9fddfc298f in non-virtual thunk to nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /build/firefox/src/docshell/base/nsDocShell.cpp:7221:13 #15 0x7f9fd8f38d34 in nsDocLoader::DoFireOnStateChange(nsIWebProgress*, nsIRequest*, int&, nsresult) /build/firefox/src/uriloader/base/nsDocLoader.cpp:1263:3 #16 0x7f9fd8f38052 in nsDocLoader::doStopDocumentLoad(nsIRequest*, nsresult) /build/firefox/src/uriloader/base/nsDocLoader.cpp:844:5 #17 0x7f9fd8f352cd in nsDocLoader::DocLoaderIsEmpty(bool) /build/firefox/src/uriloader/base/nsDocLoader.cpp:734:9 #18 0x7f9fd8f372a6 in nsDocLoader::OnStopRequest(nsIRequest*, nsISupports*, nsresult) /build/firefox/src/uriloader/base/nsDocLoader.cpp:618:5 #19 0x7f9fd8f37c9c in non-virtual thunk to nsDocLoader::OnStopRequest(nsIRequest*, nsISupports*, nsresult) /build/firefox/src/uriloader/base/nsDocLoader.cpp:479:14 #20 0x7f9fd7a12a72 in nsLoadGroup::RemoveRequest(nsIRequest*, nsISupports*, nsresult) /build/firefox/src/netwerk/base/nsLoadGroup.cpp:663:18 #21 0x7f9fd9b29485 in nsDocument::DoUnblockOnload() /build/firefox/src/dom/base/nsDocument.cpp:9120:7 #22 0x7f9fd9b28e73 in nsDocument::UnblockOnload(bool) /build/firefox/src/dom/base/nsDocument.cpp:9048:9 #23 0x7f9fd9afba89 in nsDocument::DispatchContentLoadedEvents() /build/firefox/src/dom/base/nsDocument.cpp:5205:3 #24 0x7f9fd9b712f0 in apply<nsDocument, void (nsDocument::)()> /build/firefox/src/objdir-ff-asan/dom/base/../../dist/include/nsThreadUtils.h:573:5 #25 0x7f9fd9b712f0 in nsRunnableMethodImpl<void (nsDocument::)(), true>::Run() /build/firefox/src/objdir-ff-asan/dom/base/../../dist/include/nsThreadUtils.h:665 #26 0x7f9fd78708d6 in nsThread::ProcessNextEvent(bool, bool*) /build/firefox/src/xpcom/threads/nsThread.cpp:855:7 #27 0x7f9fd78ca5b0 in NS_ProcessNextEvent(nsIThread*, bool) /build/firefox/src/xpcom/glue/nsThreadUtils.cpp:265:10 #28 0x7f9fd81518fe in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /build/firefox/src/ipc/glue/MessagePump.cpp:99:21 #29 0x7f9fd80fe2a1 in RunInternal /build/firefox/src/ipc/chromium/src/base/message_loop.cc:233:3 #30 0x7f9fd80fe2a1 in RunHandler /build/firefox/src/ipc/chromium/src/base/message_loop.cc:226 #31 0x7f9fd80fe2a1 in MessageLoop::Run() /build/firefox/src/ipc/chromium/src/base/message_loop.cc:200 #32 0x7f9fdcb6ba4f in nsBaseAppShell::Run() /build/firefox/src/widget/nsBaseAppShell.cpp:164:3 #33 0x7f9fde77c6d3 in XRE_RunAppShell /build/firefox/src/toolkit/xre/nsEmbedFunctions.cpp:743:12

previously allocated by thread T0 (Web Content) here: #0 0x4b4e18 in __interceptor_malloc asan_rtl #1 0x7f9fe46eeed8 in PL_ArenaAllocate /build/firefox/src/nsprpub/lib/ds/plarena.c:203:27 #2 0x7f9fdd1aba31 in nsPresArena::Allocate(unsigned int, unsigned long) /build/firefox/src/layout/base/nsPresArena.cpp:99:3 #3 0x7f9fdd15a609 in AllocateByObjectID /build/firefox/src/layout/style/../base/nsPresArena.h:93:12 #4 0x7f9fdd15a609 in AllocateByObjectID /build/firefox/src/layout/style/../base/nsIPresShell.h:254 #5 0x7f9fdd15a609 in operator new /build/firefox/src/layout/style/nsStyleContext.cpp:1024 #6 0x7f9fdd15a609 in NS_NewStyleContext(nsStyleContext*, nsIAtom*, nsCSSPseudoElements::Type, nsRuleNode*, bool) /build/firefox/src/layout/style/nsStyleContext.cpp:1051 #7 0x7f9fdd1637c3 in nsStyleSet::GetContext(nsStyleContext*, nsRuleNode*, nsRuleNode*, nsIAtom*, nsCSSPseudoElements::Type, mozilla::dom::Element*, unsigned int) /build/firefox/src/layout/style/nsStyleSet.cpp:856:14 #8 0x7f9fdd16d543 in nsStyleSet::ResolveAnonymousBoxStyle(nsIAtom*, nsStyleContext*) /build/firefox/src/layout/style/nsStyleSet.cpp:1872:10 #9 0x7f9fdd28cddd in nsCSSFrameConstructor::BeginBuildingScrollFrame(nsFrameConstructorState&, nsIContent*, nsStyleContext*, nsContainerFrame*, nsIAtom*, bool, nsContainerFrame*&) /build/firefox/src/layout/base/nsCSSFrameConstructor.cpp:4433:5 #10 0x7f9fdd2898cb in nsCSSFrameConstructor::SetUpDocElementContainingBlock(nsIContent*) /build/firefox/src/layout/base/nsCSSFrameConstructor.cpp:2872:25 #11 0x7f9fdd286472 in nsCSSFrameConstructor::ConstructDocElementFrame(mozilla::dom::Element*, nsILayoutHistoryState*) /build/firefox/src/layout/base/nsCSSFrameConstructor.cpp:2411:3 #12 0x7f9fdd2a7c40 in nsCSSFrameConstructor::ContentRangeInserted(nsIContent*, nsIContent*, nsIContent*, nsILayoutHistoryState*, bool) /build/firefox/src/layout/base/nsCSSFrameConstructor.cpp:7481:7 #13 0x7f9fdd429126 in PresShell::Initialize(int, int) /build/firefox/src/layout/base/nsPresShell.cpp:1911:7 #14 0x7f9fd9a5a08b in nsContentSink::StartLayout(bool) /build/firefox/src/dom/base/nsContentSink.cpp:1196:19 #15 0x7f9fd91097d3 in nsHtml5TreeOpExecutor::StartLayout() /build/firefox/src/parser/html/nsHtml5TreeOpExecutor.cpp:611:3 #16 0x7f9fd9116fb5 in nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor*, nsIContent**) /build/firefox/src/parser/html/nsHtml5TreeOperation.cpp:823:7 #17 0x7f9fd9107117 in nsHtml5TreeOpExecutor::RunFlushLoop() /build/firefox/src/parser/html/nsHtml5TreeOpExecutor.cpp:448:21 #18 0x7f9fd910c30b in nsHtml5ExecutorFlusher::Run() /build/firefox/src/parser/html/nsHtml5StreamParser.cpp:127:9 #19 0x7f9fd78708d6 in nsThread::ProcessNextEvent(bool, bool*) /build/firefox/src/xpcom/threads/nsThread.cpp:855:7 #20 0x7f9fd78ca5b0 in NS_ProcessNextEvent(nsIThread*, bool) /build/firefox/src/xpcom/glue/nsThreadUtils.cpp:265:10 #21 0x7f9fd81518df in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /build/firefox/src/ipc/glue/MessagePump.cpp:140:5 #22 0x7f9fd80fe2a1 in RunInternal /build/firefox/src/ipc/chromium/src/base/message_loop.cc:233:3 #23 0x7f9fd80fe2a1 in RunHandler /build/firefox/src/ipc/chromium/src/base/message_loop.cc:226 #24 0x7f9fd80fe2a1 in MessageLoop::Run() /build/firefox/src/ipc/chromium/src/base/message_loop.cc:200 #25 0x7f9fdcb6ba4f in nsBaseAppShell::Run() /build/firefox/src/widget/nsBaseAppShell.cpp:164:3 #26 0x7f9fde77c6d3 in XRE_RunAppShell /build/firefox/src/toolkit/xre/nsEmbedFunctions.cpp:743:12 #27 0x7f9fd80fe2a1 in RunInternal /build/firefox/src/ipc/chromium/src/base/message_loop.cc:233:3 #28 0x7f9fd80fe2a1 in RunHandler /build/firefox/src/ipc/chromium/src/base/message_loop.cc:226 #29 0x7f9fd80fe2a1 in MessageLoop::Run() /build/firefox/src/ipc/chromium/src/base/message_loop.cc:200 #30 0x7f9fde77bb0c in XRE_InitChildProcess /build/firefox/src/toolkit/xre/nsEmbedFunctions.cpp:580:7 #31 0x4dc17e in content_process_main(int, char**) /build/firefox/src/ipc/app/../contentproc/plugin-container.cpp:211:19 #32 0x7f9fd4deaec4 in __libc_start_main

Shadow bytes around the buggy address: 0x0c4a80054b90: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c4a80054ba0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c4a80054bb0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c4a80054bc0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c4a80054bd0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd =>0x0c4a80054be0: fd fd fd fd fd fd fd[fd]fd fd fd fd fd fd fd fd 0x0c4a80054bf0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c4a80054c00: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c4a80054c10: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c4a80054c20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c4a80054c30: 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 Heap right redzone: fb Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack partial redzone: f4 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 ==7620==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 condition where the text run expiration timer fires after the presentation shell (and its arena) has been destroyed, leading to use of freed memory.

Impact

A remote attacker could crash the browser process, potentially leading to denial of service.

What the attacker needed

Victim visits a malicious page

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's text rendering code. When a page is closed, some memory is freed, but a timer later tries to use that freed memory, causing a crash. An attacker could exploit this to crash the browser, but the report does not show 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.