Skip to content
Memory corruption Disclosed report Advanced

DOM - Use After Free in HasFlag()

A use-after-free in Firefox's HasFlag() function could be triggered by opening a crafted HTML file, causing the browser to crash. The report does not claim any further impact beyond the crash.

Looben Yang Follow

Originally disclosed on Mozilla

  • Fixed in 9 days
  • Paid in 9 days
  • Disclosed after 9 days

Created attachment 8927551 UAF_HasFlag_PoC.html

Reproduction test case: UAF_HasFlag_PoC.html

Steps to reproduce: 1. Open UAF_HasFlag_PoC.html in Firefox browser. 2. Firefox crashes by using freed memory in HasFlag().

Firefox version: 58.0a1 (2017-11-10) (64-bit) OS: Ubuntu 16.04 LTS

Stack trace:

================================================================= ==12169==ERROR: AddressSanitizer: heap-use-after-free on address 0x60e000087358 at pc 0x7febb2d6e7ef bp 0x7ffdfb1b7e70 sp 0x7ffdfb1b7e68 READ of size 4 at 0x60e000087358 thread T0 (file:// Content) #0 0x7febb2d6e7ee in HasFlag /builds/worker/workspace/build/src/dom/base/nsWrapperCache.h:264:15 #1 0x7febb2d6e7ee in HasProperties /builds/worker/workspace/build/src/dom/base/nsINode.h:902 #2 0x7febb2d6e7ee in nsINode::GetProperty(unsigned short, nsAtom*, nsresult*) const /builds/worker/workspace/build/src/dom/base/nsINode.cpp:164 #3 0x7febb2a97d1d in GetProperty /builds/worker/workspace/build/src/dom/base/nsINode.h:768:12 #4 0x7febb2a97d1d in mozilla::dom::Element::UnregisterIntersectionObserver(mozilla::dom::DOMIntersectionObserver*) /builds/worker/workspace/build/src/dom/base/Element.cpp:4340 #5 0x7febb286f75e in mozilla::dom::DOMIntersectionObserver::Disconnect() /builds/worker/workspace/build/src/dom/base/DOMIntersectionObserver.cpp:221:13 #6 0x7febb286f4e9 in mozilla::dom::DOMIntersectionObserver::cycleCollection::Unlink(void*) /builds/worker/workspace/build/src/dom/base/DOMIntersectionObserver.cpp:47:8 #7 0x7febafd5a170 in nsCycleCollector::CollectWhite() /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3401:26 #8 0x7febafd5cf6a in nsCycleCollector::Collect(ccType, js::SliceBudget&, nsICycleCollectorListener*, bool) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3769:24 #9 0x7febafd6112b in nsCycleCollector_collectSlice(js::SliceBudget&, bool) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:4330:21 #10 0x7febb2d9861c in nsJSContext::RunCycleCollectorSlice(mozilla::TimeStamp) /builds/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1561:3 #11 0x7febb2d9900f in ICCRunnerFired(mozilla::TimeStamp) /builds/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1620:3 #12 0x7febafe7b99d in operator() /builds/worker/workspace/build/src/clang/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.4/../../../../include/c++/4.9.4/functional:2440:14 #13 0x7febafe7b99d in mozilla::IdleTaskRunner::Run() /builds/worker/workspace/build/src/xpcom/threads/IdleTaskRunner.cpp:62 #14 0x7febafe7c59d in mozilla::TimedOut(nsITimer*, void*) /builds/worker/workspace/build/src/xpcom/threads/IdleTaskRunner.cpp:84:13 #15 0x7febafeda676 in nsTimerImpl::Fire(int) /builds/worker/workspace/build/src/xpcom/threads/nsTimerImpl.cpp:701:7 #16 0x7febafeac346 in nsTimerEvent::Run() /builds/worker/workspace/build/src/xpcom/threads/TimerThread.cpp:286:11 #17 0x7febafe95ce1 in mozilla::SchedulerGroup::Runnable::Run() /builds/worker/workspace/build/src/xpcom/threads/SchedulerGroup.cpp:396:25 #18 0x7febafebb284 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1037:14 #19 0x7febafed58c8 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:513:10 #20 0x7febb0c8b9b6 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:125:5 #21 0x7febb0bebd3b in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #22 0x7febb0bebd3b in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #23 0x7febb0bebd3b in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #24 0x7febb67775ef in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:159:27 #25 0x7febbaa94187 in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:877:22 #26 0x7febb0bebd3b in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #27 0x7febb0bebd3b in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #28 0x7febb0bebd3b in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #29 0x7febbaa93b3a in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:703:34 #30 0x4ec2de in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:63:30 #31 0x4ec2de in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:280 #32 0x7febcdadf82f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291 #33 0x41dbc8 in _start (/home/thecoder/FirefoxBuilds/firefox/firefox+0x41dbc8)

0x60e000087358 is located 24 bytes inside of 152-byte region [0x60e000087340,0x60e0000873d8) freed by thread T0 (file:// Content) here: #0 0x4bc0fb in __interceptor_free /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:47:3 #1 0x7febafd562a7 in SnowWhiteKiller::~SnowWhiteKiller() /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2729:25 #2 0x7febafd60ad4 in FreeSnowWhite /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2917:3 #3 0x7febafd60ad4 in nsCycleCollector_doDeferredDeletion() /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:4293 #4 0x7febb169a143 in AsyncFreeSnowWhite::Run() /builds/worker/workspace/build/src/js/xpconnect/src/XPCJSRuntime.cpp:124:34 #5 0x7febafedc9cf in IdleRunnableWrapper::Run() /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:339:22 #6 0x7febafebb284 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1037:14 #7 0x7febafed58c8 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:513:10 #8 0x7febb0c8b9c1 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:97:21 #9 0x7febb0bebd3b in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #10 0x7febb0bebd3b in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #11 0x7febb0bebd3b in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #12 0x7febb67775ef in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:159:27 #13 0x7febbaa94187 in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:877:22 #14 0x7febb0bebd3b in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #15 0x7febb0bebd3b in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #16 0x7febb0bebd3b in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #17 0x7febbaa93b3a in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:703:34 #18 0x4ec2de in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:63:30 #19 0x4ec2de in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:280 #20 0x7febcdadf82f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291

previously allocated by thread T0 (file:// Content) here: #0 0x4bc44c in malloc /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:64:3 #1 0x4ed85d in moz_xmalloc /builds/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:84:17 #2 0x7febb5049f43 in operator new /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:206:12 #3 0x7febb5049f43 in NS_NewHTMLSharedElement(already_AddRefedmozilla::dom::NodeInfo&&, mozilla::dom::FromParser) /builds/worker/workspace/build/src/dom/html/HTMLSharedElement.cpp:23 #4 0x7febb1cacbff in nsHtml5TreeOperation::CreateHTMLElement(nsAtom*, nsHtml5HtmlAttributes*, mozilla::dom::FromParser, nsNodeInfoManager*, nsHtml5DocumentBuilder*, nsGenericHTMLElement* ()(already_AddRefedmozilla::dom::NodeInfo&&, mozilla::dom::FromParser)) /builds/worker/workspace/build/src/parser/html/nsHtml5TreeOperation.cpp:460:20 #5 0x7febb1cbaf21 in nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor, nsIContent**, bool*, bool*) /builds/worker/workspace/build/src/parser/html/nsHtml5TreeOperation.cpp:872:17 #6 0x7febb1cb7976 in nsHtml5TreeOpExecutor::RunFlushLoop() /builds/worker/workspace/build/src/parser/html/nsHtml5TreeOpExecutor.cpp:492:29 #7 0x7febb1cc2d3b in nsHtml5ExecutorFlusher::Run() /builds/worker/workspace/build/src/parser/html/nsHtml5StreamParser.cpp:130:20 #8 0x7febafe95ce1 in mozilla::SchedulerGroup::Runnable::Run() /builds/worker/workspace/build/src/xpcom/threads/SchedulerGroup.cpp:396:25 #9 0x7febafebb284 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1037:14 #10 0x7febafed58c8 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:513:10 #11 0x7febb0c8b9c1 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:97:21 #12 0x7febb0bebd3b in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #13 0x7febb0bebd3b in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #14 0x7febb0bebd3b in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #15 0x7febb67775ef in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:159:27 #16 0x7febbaa94187 in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:877:22 #17 0x7febb0bebd3b in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #18 0x7febb0bebd3b in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #19 0x7febb0bebd3b in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #20 0x7febbaa93b3a in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:703:34 #21 0x4ec2de in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:63:30 #22 0x4ec2de in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:280 #23 0x7febcdadf82f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291

SUMMARY: AddressSanitizer: heap-use-after-free /builds/worker/workspace/build/src/dom/base/nsWrapperCache.h:264:15 in HasFlag Shadow bytes around the buggy address: 0x0c1c80008e10: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd 0x0c1c80008e20: fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa fa 0x0c1c80008e30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c1c80008e40: 00 00 00 00 fa fa fa fa fa fa fa fa fd fd fd fd 0x0c1c80008e50: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa =>0x0c1c80008e60: fa fa fa fa fa fa fa fa fd fd fd[fd]fd fd fd fd 0x0c1c80008e70: fd fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa 0x0c1c80008e80: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00 0x0c1c80008e90: 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa 0x0c1c80008ea0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c1c80008eb0: 00 00 00 00 fa fa fa fa fa fa fa fa 00 00 00 00 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 ==12169==ABORTING

The original report as published on Mozilla's Bugzilla, by Looben Yang. 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 cycle collector frees an element while an intersection observer still holds a reference, so a later call reads the freed object.

What the attacker needed

Victim opens a crafted HTML file; Firefox 58.0a1 on Ubuntu 16.04

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.

A use-after-free happens when a program keeps using a piece of memory after it has been freed. Here, opening a special web page made Firefox read memory that had already been released, which caused the browser to crash. The report only shows a crash, not theft of data or 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 Looben Yang

View all

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