Skip to content
Memory corruption Disclosed report Advanced CVE-2017-5433

heap-use-after-free in nsSMILCompositor::GetFirstFuncToAffectSandwich

A heap-use-after-free occurs in Firefox's SMIL animation code when a crafted SVG animation element is activated via a hyperlink, causing the compositor to read freed memory. An attacker could potentially crash the browser or execute arbitrary code by luring a victim to a malicious page.

Nils Follow

Originally disclosed on Mozilla

Critical View original
  • Fixed in 7 days
  • Paid in 13 days
  • Disclosed after 7 days

The attached testcase (crash.html) crashes the latest ASAN build of Firefox (BuildID=20170313233726) as follows. The testcase requires the attached mini.svg.

================================================================= ==28440==ERROR: AddressSanitizer: heap-use-after-free on address 0x616000199dc8 at pc 0x7f8edf28b179 bp 0x7ffe8c450540 sp 0x7ffe8c450538 READ of size 8 at 0x616000199dc8 thread T0 (Web Content) #0 0x7f8edf28b178 in Equals /home/worker/workspace/build/src/dom/smil/nsSMILTargetIdentifier.h:75:38 #1 0x7f8edf28b178 in UpdateCachedTarget /home/worker/workspace/build/src/dom/smil/nsSMILAnimationFunction.cpp:336 #2 0x7f8edf28b178 in nsSMILCompositor::GetFirstFuncToAffectSandwich() /home/worker/workspace/build/src/dom/smil/nsSMILCompositor.cpp:168 #3 0x7f8edf27f4cd in nsSMILCompositor::ComposeAttribute(bool&) /home/worker/workspace/build/src/dom/smil/nsSMILCompositor.cpp:80:33 #4 0x7f8edf27d57d in nsSMILAnimationController::DoSample(bool) /home/worker/workspace/build/src/dom/smil/nsSMILAnimationController.cpp:453:5 #5 0x7f8edec24a21 in mozilla::dom::SVGAnimationElement::ActivateByHyperlink() /home/worker/workspace/build/src/dom/svg/SVGAnimationElement.cpp:404:7 #6 0x7f8edfefd6a9 in mozilla::PresShell::GoToAnchor(nsAString_internal const&, bool, unsigned int) /home/worker/workspace/build/src/layout/base/PresShell.cpp:3185:7 #7 0x7f8ee24d1ac6 in nsDocShell::ScrollToAnchor(bool, bool, nsACString_internal&, unsigned int) /home/worker/workspace/build/src/docshell/base/nsDocShell.cpp:11533:12 #8 0x7f8ee246bc3c in nsDocShell::InternalLoad(nsIURI*, nsIURI*, bool, nsIURI*, unsigned int, nsIPrincipal*, nsIPrincipal*, unsigned int, nsAString_internal const&, char const*, nsAString_internal const&, nsIInputStream*, nsIInputStream*, unsigned int, nsISHEntry*, bool, nsAString_internal const&, nsIDocShell*, nsIURI*, bool, nsIDocShell**, nsIRequest**) /home/worker/workspace/build/src/docshell/base/nsDocShell.cpp:10495:12 #9 0x7f8ee24642fe in nsDocShell::LoadURI(nsIURI*, nsIDocShellLoadInfo*, unsigned int, bool) /home/worker/workspace/build/src/docshell/base/nsDocShell.cpp:1573:10 #10 0x7f8edbe6caf5 in mozilla::dom::Location::SetURI(nsIURI*, bool) /home/worker/workspace/build/src/dom/base/Location.cpp:288:12 #11 0x7f8edbe6d655 in mozilla::dom::Location::SetHash(nsAString_internal const&) /home/worker/workspace/build/src/dom/base/Location.cpp:341:10 #12 0x7f8edc5fdaf5 in SetHash /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/dom/Location.h:209:14 #13 0x7f8edc5fdaf5 in mozilla::dom::LocationBinding::set_hash(JSContext*, JS::Handle<JSObject*>, mozilla::dom::Location*, JSJitSetterCallArgs) /home/worker/workspace/build/src/obj-firefox/dom/bindings/LocationBinding.cpp:703 #14 0x7f8edd9923e2 in mozilla::dom::GenericBindingSetter(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/dom/bindings/BindingUtils.cpp:2921:8 #15 0x7f8ee345d67f in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:282:15 #16 0x7f8ee345d67f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:448 #17 0x7f8ee345f3e4 in InternalCall /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:493:12 #18 0x7f8ee345f3e4 in Call /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:512 #19 0x7f8ee345f3e4 in js::CallSetter(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, JS::HandleJS::Value) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:641 #20 0x7f8ee408aaea in js::SetPropertyIgnoringNamedGetter(JSContext*, JS::Handle<JSObject*>, JS::Handle<jsid>, JS::HandleJS::Value, JS::HandleJS::Value, JS::HandleJS::PropertyDescriptor, JS::ObjectOpResult&) /home/worker/workspace/build/src/js/src/proxy/BaseProxyHandler.cpp:245:10 #21 0x7f8edd99dd79 in mozilla::dom::DOMProxyHandler::set(JSContext*, JS::Handle<JSObject*>, JS::Handle<jsid>, JS::HandleJS::Value, JS::HandleJS::Value, JS::ObjectOpResult&) const /home/worker/workspace/build/src/dom/bindings/DOMJSProxyHandler.cpp:258:10 #22 0x7f8ee40bb1f4 in js::Proxy::set(JSContext*, JS::Handle<JSObject*>, JS::Handle<jsid>, JS::HandleJS::Value, JS::HandleJS::Value, JS::ObjectOpResult&) /home/worker/workspace/build/src/js/src/proxy/Proxy.cpp:369:12 #23 0x7f8ee3fa53fa in JSObject::nonNativeSetProperty(JSContext*, JS::Handle<JSObject*>, JS::Handle<jsid>, JS::HandleJS::Value, JS::HandleJS::Value, JS::ObjectOpResult&) /home/worker/workspace/build/src/js/src/jsobj.cpp:1049:12 #24 0x7f8ee40dd25c in SetProperty /home/worker/workspace/build/src/js/src/vm/NativeObject.h:1458:16 #25 0x7f8ee40dd25c in js::Wrapper::set(JSContext*, JS::Handle<JSObject*>, JS::Handle<jsid>, JS::HandleJS::Value, JS::HandleJS::Value, JS::ObjectOpResult&) const /home/worker/workspace/build/src/js/src/proxy/Wrapper.cpp:152 #26 0x7f8ee40922be in js::CrossCompartmentWrapper::set(JSContext*, JS::Handle<JSObject*>, JS::Handle<jsid>, JS::HandleJS::Value, JS::HandleJS::Value, JS::ObjectOpResult&) const /home/worker/workspace/build/src/js/src/proxy/CrossCompartmentWrapper.cpp:238:5 #27 0x7f8ee40bb1f4 in js::Proxy::set(JSContext*, JS::Handle<JSObject*>, JS::Handle<jsid>, JS::HandleJS::Value, JS::HandleJS::Value, JS::ObjectOpResult&) /home/worker/workspace/build/src/js/src/proxy/Proxy.cpp:369:12 #28 0x7f8ee3fa53fa in JSObject::nonNativeSetProperty(JSContext*, JS::Handle<JSObject*>, JS::Handle<jsid>, JS::HandleJS::Value, JS::HandleJS::Value, JS::ObjectOpResult&) /home/worker/workspace/build/src/js/src/jsobj.cpp:1049:12 #29 0x7f8ee343cdcf in SetProperty /home/worker/workspace/build/src/js/src/vm/NativeObject.h:1458:16 #30 0x7f8ee343cdcf in SetPropertyOperation /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:243 #31 0x7f8ee343cdcf in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2747 #32 0x7f8ee34297ab in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:394:12 #33 0x7f8ee345d996 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:466:15 #34 0x7f8ee345e072 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:512:10 #35 0x7f8ee3e34d8c 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:2887:12 #36 0x7f8edd4117e2 in mozilla::dom::EventListener::HandleEvent(JSContext*, JS::HandleJS::Value, mozilla::dom::Event&, mozilla::ErrorResult&) /home/worker/workspace/build/src/obj-firefox/dom/bindings/EventListenerBinding.cpp:47:8 #37 0x7f8eddd96a8e in HandleEvent<mozilla::dom::EventTarget > /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/dom/EventListenerBinding.h:65:12 #38 0x7f8eddd96a8e in mozilla::EventListenerManager::HandleEventSubType(mozilla::EventListenerManager::Listener, nsIDOMEvent*, mozilla::dom::EventTarget*) /home/worker/workspace/build/src/dom/events/EventListenerManager.cpp:1119 #39 0x7f8eddd98a58 in mozilla::EventListenerManager::HandleEventInternal(nsPresContext*, mozilla::WidgetEvent*, nsIDOMEvent**, mozilla::dom::EventTarget*, nsEventStatus*) /home/worker/workspace/build/src/dom/events/EventListenerManager.cpp:1297:20 #40 0x7f8eddd83133 in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArraymozilla::EventTargetChainItem&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:465:5 #41 0x7f8eddd869f7 in mozilla::EventDispatcher::Dispatch(nsISupports*, nsPresContext*, mozilla::WidgetEvent*, nsIDOMEvent*, nsEventStatus*, mozilla::EventDispatchingCallback*, nsTArraymozilla::dom::EventTarget*) /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:822:9 #42 0x7f8edbcc09ce in nsGlobalWindow::PostHandleEvent(mozilla::EventChainPostVisitor&) /home/worker/workspace/build/src/dom/base/nsGlobalWindow.cpp:3812:7 #43 0x7f8eddd83245 in PostHandleEvent /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:416:3 #44 0x7f8eddd83245 in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArraymozilla::EventTargetChainItem&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback, mozilla::ELMCreationDetector&) /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:468 #45 0x7f8eddd83854 in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArraymozilla::EventTargetChainItem&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:518:5 #46 0x7f8eddd869f7 in mozilla::EventDispatcher::Dispatch(nsISupports*, nsPresContext*, mozilla::WidgetEvent*, nsIDOMEvent*, nsEventStatus*, mozilla::EventDispatchingCallback*, nsTArraymozilla::dom::EventTarget*) /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:822:9 #47 0x7f8edffe32a6 in nsDocumentViewer::LoadComplete(nsresult) /home/worker/workspace/build/src/layout/base/nsDocumentViewer.cpp:1043:7 #48 0x7f8ee24bd63a in nsDocShell::EndPageLoad(nsIWebProgress, nsIChannel*, nsresult) /home/worker/workspace/build/src/docshell/base/nsDocShell.cpp:7642:5 #49 0x7f8ee24b94e4 in nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /home/worker/workspace/build/src/docshell/base/nsDocShell.cpp:7436:7 #50 0x7f8ee24c0cff in non-virtual thunk to nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /home/worker/workspace/build/src/docshell/base/nsDocShell.cpp:7333:13 #51 0x7f8edafbcbc0 in nsDocLoader::DoFireOnStateChange(nsIWebProgress*, nsIRequest*, int&, nsresult) /home/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:1258:3 #52 0x7f8edafbbb58 in nsDocLoader::doStopDocumentLoad(nsIRequest*, nsresult) /home/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:842:5 #53 0x7f8edafb88b6 in nsDocLoader::DocLoaderIsEmpty(bool) /home/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:732:9 #54 0x7f8edafba9b4 in nsDocLoader::OnStopRequest(nsIRequest*, nsISupports*, nsresult) /home/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:614:5 #55 0x7f8edafbb56c in non-virtual thunk to nsDocLoader::OnStopRequest(nsIRequest*, nsISupports*, nsresult) /home/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:470:14 #56 0x7f8ed96dc25b in mozilla::net::nsLoadGroup::RemoveRequest(nsIRequest*, nsISupports*, nsresult) /home/worker/workspace/build/src/netwerk/base/nsLoadGroup.cpp:634:18 #57 0x7f8edc0216ab in nsDocument::DoUnblockOnload() /home/worker/workspace/build/src/dom/base/nsDocument.cpp:8863:7 #58 0x7f8edc02124b in nsDocument::UnblockOnload(bool) /home/worker/workspace/build/src/dom/base/nsDocument.cpp:8789:9 #59 0x7f8edbff727c in nsDocument::DispatchContentLoadedEvents() /home/worker/workspace/build/src/dom/base/nsDocument.cpp:5294:3 #60 0x7f8edc0c7192 in applyImpl<nsDocument, void (nsDocument::)()> /home/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:855:12 #61 0x7f8edc0c7192 in apply<nsDocument, void (nsDocument::)()> /home/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:861 #62 0x7f8edc0c7192 in mozilla::detail::RunnableMethodImpl<nsDocument*, void (nsDocument::)(), true, false>::Run() /home/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:890 #63 0x7f8ed94e7ab2 in mozilla::ValidatingDispatcher::Runnable::Run() /home/worker/workspace/build/src/xpcom/threads/Dispatcher.cpp:257:21 #64 0x7f8ed951c632 in nsThread::ProcessNextEvent(bool, bool) /home/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1264:7 #65 0x7f8ed9518ee0 in NS_ProcessNextEvent(nsIThread*, bool) /home/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:389:10 #66 0x7f8eda32ebff in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /home/worker/workspace/build/src/ipc/glue/MessagePump.cpp:96:21 #67 0x7f8eda2a02a8 in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:238:3 #68 0x7f8eda2a02a8 in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:231 #69 0x7f8eda2a02a8 in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:211 #70 0x7f8edf7aabaf in nsBaseAppShell::Run() /home/worker/workspace/build/src/widget/nsBaseAppShell.cpp:156:3 #71 0x7f8ee2fea477 in XRE_RunAppShell() /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:871:12 #72 0x7f8eda2a02a8 in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:238:3 #73 0x7f8eda2a02a8 in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:231 #74 0x7f8eda2a02a8 in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:211 #75 0x7f8ee2fe9e79 in XRE_InitChildProcess(int, char**, XREChildData const*) /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:695:7 #76 0x4e01b6 in content_process_main /home/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:64:19 #77 0x4e01b6 in main /home/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:286 #78 0x7f8ef4a1082f in __libc_start_main /build/glibc-t3gR2i/glibc-2.23/csu/../csu/libc-start.c:291 #79 0x41c3d8 in _start (/home/nils/fuzzer3/firefox/firefox+0x41c3d8)

0x616000199dc8 is located 584 bytes inside of 616-byte region [0x616000199b80,0x616000199de8) freed by thread T0 (Web Content) here: #0 0x4b2b2b in __interceptor_free /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:38:3 #1 0x7f8ed93ba7c4 in SnowWhiteKiller::~SnowWhiteKiller() /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2664:9 #2 0x7f8ed93ba3b6 in nsCycleCollector::FreeSnowWhite(bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2839:3 #3 0x7f8ed93c1775 in nsCycleCollector::BeginCollection(ccType, nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3839:3 #4 0x7f8ed93c0f30 in nsCycleCollector::Collect(ccType, js::SliceBudget&, nsICycleCollectorListener*, bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3661:9 #5 0x7f8ed93c3e14 in nsCycleCollector_collect(nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:4157:3 #6 0x7f8edc105b30 in nsJSContext::CycleCollectNow(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1452:3 #7 0x7f8edbc5e1fd in nsDOMWindowUtils::CycleCollect(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsDOMWindowUtils.cpp:1339:3 #8 0x7f8ed9537d81 in NS_InvokeByIndex /home/worker/workspace/build/src/xpcom/reflect/xptcall/md/unix/xptcinvoke_asm_x86_64_unix.S:115 #9 0x7f8edadd2a87 in Invoke /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNative.cpp:2010:12 #10 0x7f8edadd2a87 in Call /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNative.cpp:1329 #11 0x7f8edadd2a87 in XPCWrappedNative::CallMethod(XPCCallContext&, XPCWrappedNative::CallMode) /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNative.cpp:1296 #12 0x7f8edadda3fb in XPC_WN_CallMethod(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNativeJSOps.cpp:983:12 #13 0x7f8ee345d67f in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:282:15 #14 0x7f8ee345d67f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:448 #15 0x7f8ee3444172 in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:499:12 #16 0x7f8ee3444172 in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2954 #17 0x7f8ee34297ab in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:394:12 #18 0x7f8ee345d996 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:466:15 #19 0x7f8ee345e072 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:512:10 #20 0x7f8ee3e32fd3 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:2828:12 #21 0x7f8edad11519 in xpc::FunctionForwarder(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/xpconnect/src/ExportHelpers.cpp:319:18 #22 0x7f8ee345d67f in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:282:15 #23 0x7f8ee345d67f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:448 #24 0x7f8ee3444172 in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:499:12 #25 0x7f8ee3444172 in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2954 #26 0x7f8ee34297ab in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:394:12 #27 0x7f8ee345d996 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:466:15 #28 0x7f8ee345e072 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:512:10 #29 0x7f8ee40dd89c 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 0x7f8ee409452e in js::CrossCompartmentWrapper::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) const /home/worker/workspace/build/src/js/src/proxy/CrossCompartmentWrapper.cpp:353:14 #31 0x7f8ee40bd309 in js::Proxy::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) /home/worker/workspace/build/src/js/src/proxy/Proxy.cpp:464:12 #32 0x7f8ee40bfc34 in js::proxy_Call(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/src/proxy/Proxy.cpp:716:12 #33 0x7f8ee345d727 in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:282:15 #34 0x7f8ee345d727 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:436 #35 0x7f8ee345e072 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:512:10 #36 0x7f8ee3e34d8c 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:2887:12

previously allocated by thread T0 (Web Content) here: #0 0x4b2e4b in malloc /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:52:3 #1 0x4e11bd in moz_xmalloc /home/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:83:17 #2 0x7f8edec04339 in operator new /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:194:12 #3 0x7f8edec04339 in NS_NewSVGAnimateElement(nsIContent**, already_AddRefedmozilla::dom::NodeInfo&&) /home/worker/workspace/build/src/dom/svg/SVGAnimateElement.cpp:10 #4 0x7f8edec32156 in NS_NewSVGElement(mozilla::dom::Element**, already_AddRefedmozilla::dom::NodeInfo&&, mozilla::dom::FromParser) /home/worker/workspace/build/src/dom/svg/SVGElementFactory.cpp:130:19 #5 0x7f8edc12a6ee in NS_NewElement(mozilla::dom::Element**, already_AddRefedmozilla::dom::NodeInfo&&, mozilla::dom::FromParser, nsAString_internal const*) /home/worker/workspace/build/src/dom/base/nsNameSpaceManager.cpp:231:14 #6 0x7f8edf381810 in nsXMLContentSink::CreateElement(char16_t const**, unsigned int, mozilla::dom::NodeInfo*, unsigned int, nsIContent**, bool*, mozilla::dom::FromParser) /home/worker/workspace/build/src/dom/xml/nsXMLContentSink.cpp:472:8 #7 0x7f8edf3856f7 in nsXMLContentSink::HandleStartElement(char16_t const*, char16_t const**, unsigned int, unsigned int, bool) /home/worker/workspace/build/src/dom/xml/nsXMLContentSink.cpp:966:12 #8 0x7f8edb08f7de in nsExpatDriver::HandleStartElement(char16_t const*, char16_t const**) /home/worker/workspace/build/src/parser/htmlparser/nsExpatDriver.cpp:380:19 #9 0x7f8ee0f96fd1 in doContent /home/worker/workspace/build/src/parser/expat/lib/xmlparse.c:2468:11 #10 0x7f8ee0f87fcd in contentProcessor /home/worker/workspace/build/src/parser/expat/lib/xmlparse.c:2098:27 #11 0x7f8ee0f87fcd in doProlog /home/worker/workspace/build/src/parser/expat/lib/xmlparse.c:4078 #12 0x7f8ee0f7de91 in prologProcessor /home/worker/workspace/build/src/parser/expat/lib/xmlparse.c:3812:10 #13 0x7f8ee0f7de91 in prologInitProcessor /home/worker/workspace/build/src/parser/expat/lib/xmlparse.c:3629 #14 0x7f8ee0f7c062 in MOZ_XML_Parse /home/worker/workspace/build/src/parser/expat/lib/xmlparse.c:1530:17 #15 0x7f8edb0952be in nsExpatDriver::ParseBuffer(char16_t const*, unsigned int, bool, unsigned int*) /home/worker/workspace/build/src/parser/htmlparser/nsExpatDriver.cpp:1014:16 #16 0x7f8edb09639a in nsExpatDriver::ConsumeToken(nsScanner&, bool&) /home/worker/workspace/build/src/parser/htmlparser/nsExpatDriver.cpp:1112:5 #17 0x7f8edb0a366b in nsParser::Tokenize(bool) /home/worker/workspace/build/src/parser/htmlparser/nsParser.cpp:1532:16 #18 0x7f8edb09ef28 in nsParser::ResumeParse(bool, bool, bool) /home/worker/workspace/build/src/parser/htmlparser/nsParser.cpp:1053:41 #19 0x7f8edb0a47af in nsParser::OnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) /home/worker/workspace/build/src/parser/htmlparser/nsParser.cpp:1430:12 #20 0x7f8ed9688b72 in nsBaseChannel::OnDataAvailable(nsIRequest*, nsISupports*, nsIInputStream*, unsigned long, unsigned int) /home/worker/workspace/build/src/netwerk/base/nsBaseChannel.cpp:856:17 #21 0x7f8ed96d4613 in nsInputStreamPump::OnStateTransfer() /home/worker/workspace/build/src/netwerk/base/nsInputStreamPump.cpp:601:22 #22 0x7f8ed96d300a in nsInputStreamPump::OnInputStreamReady(nsIAsyncInputStream*) /home/worker/workspace/build/src/netwerk/base/nsInputStreamPump.cpp:429:25 #23 0x7f8ed94b9afd in nsInputStreamReadyEvent::Run() /home/worker/workspace/build/src/xpcom/io/nsStreamUtils.cpp:96:9 #24 0x7f8ed951c632 in nsThread::ProcessNextEvent(bool, bool*) /home/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1264:7 #25 0x7f8ed9518ee0 in NS_ProcessNextEvent(nsIThread*, bool) /home/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:389:10 #26 0x7f8eda32ebff in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /home/worker/workspace/build/src/ipc/glue/MessagePump.cpp:96:21 #27 0x7f8eda2a02a8 in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:238:3 #28 0x7f8eda2a02a8 in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:231 #29 0x7f8eda2a02a8 in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:211 #30 0x7f8edf7aabaf in nsBaseAppShell::Run() /home/worker/workspace/build/src/widget/nsBaseAppShell.cpp:156:3 #31 0x7f8ee2fea477 in XRE_RunAppShell() /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:871:12 #32 0x7f8eda2a02a8 in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:238:3 #33 0x7f8eda2a02a8 in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:231 #34 0x7f8eda2a02a8 in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:211 #35 0x7f8ee2fe9e79 in XRE_InitChildProcess(int, char**, XREChildData const*) /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:695:7 #36 0x4e01b6 in content_process_main /home/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:64:19 #37 0x4e01b6 in main /home/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:286

SUMMARY: AddressSanitizer: heap-use-after-free /home/worker/workspace/build/src/dom/smil/nsSMILTargetIdentifier.h:75:38 in Equals Shadow bytes around the buggy address: 0x0c2c8002b360: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c2c8002b370: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c2c8002b380: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c2c8002b390: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c2c8002b3a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd =>0x0c2c8002b3b0: fd fd fd fd fd fd fd fd fd[fd]fd fd fd fa fa fa 0x0c2c8002b3c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c2c8002b3d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c2c8002b3e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c2c8002b3f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c2c8002b400: 00 00 00 00 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 ==28440==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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

This is a Mozilla bug report about a heap-use-after-free in Firefox's SMIL animation code, specifically in nsSMILCompositor::GetFirstFuncToAffectSandwich. SMIL (Synchronized Multimedia Integration Language) is the XML-based mechanism that lets SVG documents animate their own attributes and elements. Firefox implements it in dom/smil, and the animation controller samples active animation functions and composes their results onto the target element's attributes.

The crash was found in the Web Content process of an ASAN build of Firefox, BuildID 20170313233726. The report was disclosed on 21 March 2017 and is rated critical, with the weakness classified as use after free.

Setup

The researcher used an AddressSanitizer build of Firefox, identified as the latest ASAN build at the time, with BuildID 20170313233726. Two files are needed to reproduce: a testcase called crash.html and a companion SVG file called mini.svg. The report does not include the contents of either file, so the exact markup that triggers the bug is not shown here.

No accounts, roles or special configuration are described. The crash happens in the Web Content process, so it is reachable from ordinary page content.

Finding it

The researcher attached the testcase and reported that it crashes the ASAN build. The stack trace shows the fault is a read of size 8 from a heap region that had already been freed, at nsSMILTargetIdentifier.h:75:38 inside Equals. The read is reached through UpdateCachedTarget in nsSMILAnimationFunction.cpp:336, called from nsSMILCompositor::GetFirstFuncToAffectSandwich() at nsSMILCompositor.cpp:168, which is itself called from nsSMILCompositor::ComposeAttribute(bool&) at nsSMILCompositor.cpp:80:33.

That chain is the compositor walking its animation functions to decide which one affects the sandwich, and comparing target identifiers along the way. The identifier it compares against has already been freed, so the comparison dereferences stale memory.

Exploitation

The report gives the crash trace rather than a manual exploitation sequence. The steps below follow the call chain in the trace, from the trigger to the faulting read.

Step 1: Load the page and let the document finish loading

The outermost frames show the crash arriving during page load completion. nsDocLoader::OnStopRequest calls nsDocLoader::DocLoaderIsEmpty, which calls doStopDocumentLoad, then DoFireOnStateChange, then nsDocShell::OnStateChange, then nsDocShell::EndPageLoad, then nsDocumentViewer::LoadComplete. From there nsDocument::DispatchContentLoadedEvents runs through nsDocument::UnblockOnload and nsDocument::DoUnblockOnload, which removes the request from the load group and eventually dispatches the content-loaded events.

Step 2: A content-loaded event handler runs script

The event dispatch reaches mozilla::EventDispatcher::Dispatch, then mozilla::EventTargetChainItem::HandleEventTargetChain, then nsGlobalWindow::PostHandleEvent, and back into the event target chain. The handler is a JavaScript event listener: mozilla::EventListenerManager::HandleEventInternal calls HandleEventSubType, which calls mozilla::dom::EventListener::HandleEvent, which calls into the JS engine via JS::Call and js::Call.

Step 3: Script sets location.hash

Inside the handler, the interpreter executes a property set (SetPropertyOperation in js::Interpreter.cpp:2747). The set crosses compartment wrappers (js::CrossCompartmentWrapper::set, js::Wrapper::set, DOMProxyHandler::set, js::SetPropertyIgnoringNamedGetter) and lands on the Location binding: mozilla::dom::LocationBinding::set_hash, then mozilla::dom::Location::SetHash, then mozilla::dom::Location::SetURI.

Step 4: The hash change triggers a load and an anchor scroll

Location::SetURI calls nsDocShell::LoadURI, which calls nsDocShell::InternalLoad, which calls nsDocShell::ScrollToAnchor. Scrolling to the anchor calls mozilla::PresShell::GoToAnchor, which calls mozilla::dom::SVGAnimationElement::ActivateByHyperlink() at SVGAnimationElement.cpp:404:7. This is the point where an SVG animation element is activated as a result of the navigation to the fragment.

Step 5: The animation controller samples and composes

ActivateByHyperlink calls nsSMILAnimationController::DoSample(bool) at nsSMILAnimationController.cpp:453:5. Sampling calls nsSMILCompositor::ComposeAttribute(bool&) at nsSMILCompositor.cpp:80:33, which calls nsSMILCompositor::GetFirstFuncToAffectSandwich() at nsSMILCompositor.cpp:168. That function calls UpdateCachedTarget in nsSMILAnimationFunction.cpp:336, which compares target identifiers with Equals in nsSMILTargetIdentifier.h:75:38. The comparison reads 8 bytes from the freed region and ASAN aborts.

The ASAN header for the fault is:

Text
==28440==ERROR: AddressSanitizer: heap-use-after-free on address 0x616000199dc8 at pc 0x7f8edf28b179 bp 0x7ffe8c450540 sp 0x7ffe8c450538
READ of size 8 at 0x616000199dc8 thread T0 (Web Content)

The summary line names the faulting function and location:

Text
SUMMARY: AddressSanitizer: heap-use-after-free /home/worker/workspace/build/src/dom/smil/nsSMILTargetIdentifier.h:75:38 in Equals

Step 6: The freed object is an SVG animate element

The allocation stack shows the freed region was created as an SVG animation element. NS_NewSVGAnimateElement at SVGAnimateElement.cpp:10 allocates it through operator new and moz_xmalloc, reached from NS_NewSVGElement and NS_NewElement while the XML content sink parses a start tag (nsXMLContentSink::CreateElement, nsXMLContentSink::HandleStartElement, nsExpatDriver::HandleStartElement, and the Expat parser). In other words, the object was an <animate> element created from the parsed SVG markup.

The free stack shows it was released by the cycle collector: SnowWhiteKiller::~SnowWhiteKiller() at nsCycleCollector.cpp:2664:9, called from nsCycleCollector::FreeSnowWhite(bool), from nsCycleCollector::BeginCollection, from nsCycleCollector::Collect, from nsCycleCollector_collect, from nsJSContext::CycleCollectNow, from nsDOMWindowUtils::CycleCollect. That call was made from JavaScript through XPConnect (XPCWrappedNative::CallMethod, XPC_WN_CallMethod), so the page itself invoked a cycle collection before the animation sampling ran.

The region is described as follows:

Text
0x616000199dc8 is located 584 bytes inside of 616-byte region [0x616000199b80,0x616000199de8)

So the sequence is: the SVG is parsed and an animate element is allocated; script triggers a cycle collection that frees it; then a location.hash assignment causes an anchor scroll that activates an SVG animation element and samples the animation controller, which still holds a reference to the freed target identifier and reads it.

Root cause

The compositor keeps a cached target identifier for each animation function and refreshes it in UpdateCachedTarget when composing. The comparison in nsSMILTargetIdentifier::Equals dereferences that cached identifier. When the underlying animate element has been collected by the cycle collector, the cached identifier points into freed memory, and the comparison reads it. The animation controller's sampling path does not account for the target having been collected between the time the function was registered and the time the sample runs.

The report does not state which reference or ownership rule was violated, so the precise lifetime bug is not spelled out here. What the trace establishes is that the object was freed by the cycle collector before the compositor compared against it.

Impact

The crash occurs in the Web Content process, so it is reachable from ordinary page content. The report classifies it as a use after free, which in a browser engine is potentially exploitable for memory corruption, not merely a denial of service. The report itself does not demonstrate code execution or any sandbox escape, and it does not describe how reliably the freed region could be reallocated with attacker-controlled data.

Fix

What the trace implies is that the compositor must not compare against a target identifier whose element has been collected, either by holding a strong reference for the duration of the sample or by invalidating the cached target when the element is unlinked.

Variants to test

  1. Trigger a cycle collection from script at different points relative to SMIL sampling, for example before and after the animation begins, and check whether the same Equals read appears in the trace.
  2. Use different SVG animation elements (not only <animate>) as the target of the anchor activation, and see whether the freed object is still an animation element or a different SMIL type.
  3. Replace the location.hash assignment with other navigations that reach ScrollToAnchor, and check whether ActivateByHyperlink is still the frame that starts the sample.
  4. Vary the timing between the cycle collection and the anchor scroll, for example by deferring the hash change, to see how wide the window is.

A positive result in each case is an ASAN heap-use-after-free report whose top frame is nsSMILTargetIdentifier::Equals reached through GetFirstFuncToAffectSandwich.

Hunting notes

This kind of bug hides where an engine caches a pointer or identifier to a DOM object and later uses it after script has had a chance to run. In Firefox, the SMIL compositor and animation controller are good places to look, because sampling is driven by timers and navigation events rather than by the script that created the animation. The signal during recon is a crash whose free stack goes through the cycle collector (SnowWhiteKiller, FreeSnowWhite) while the use stack goes through a comparison or lookup on a cached identifier. That pairing, a script-triggered collection followed by an engine-internal sample, is what makes the report convincing: the page controls both halves of the lifetime. The researcher provided a testcase and a full ASAN trace with allocation, free and use stacks.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

A security researcher found a way to make Firefox crash by loading a web page. The crash is not a normal "the page froze" kind of crash: it is a memory-safety bug, which means the browser's internal memory handling goes wrong in a way that, in the worst case, could let an attacker run their own code on your computer.

The bug lives in a part of Firefox that handles SMIL. SMIL stands for Synchronized Multimedia Integration Language, and it is the mechanism that lets an SVG image (a vector drawing format used on the web) animate itself, for example making a shape move or change colour over time. Firefox implements this in a folder of its source code called dom/smil.

The specific fault is called a heap-use-after-free. To understand that phrase, you need two ideas:

  • The heap is the area of memory a program uses for objects it creates while running. When the browser builds a piece of a web page in memory, it usually puts it on the heap.
  • Use after free means the program throws an object away (frees the memory), and then later reads or writes that same memory as if the object were still there. The memory may already have been handed to something else, so the old data is stale or belongs to a different object. Reading it can crash the program, and if an attacker can control what now sits in that memory, it can sometimes be turned into code execution.

The crash happened in a function called nsSMILCompositor::GetFirstFuncToAffectSandwich. The name sounds odd, but a "sandwich" here is just Firefox's internal term for the stack of animation effects that get combined (composed) onto one element's attribute. The compositor is the piece of code that decides which animation wins.

The researcher tested against an ASAN build of Firefox. ASAN stands for AddressSanitizer, a tool built into a special version of the browser that watches every memory access and shouts loudly the moment a program touches memory it should not. Normal Firefox builds often just crash silently or misbehave; an ASAN build produces a detailed report that names the exact line of source code. The build used was identified as 20170313233726.

The report was disclosed on 21 March 2017 and is rated critical, with the weakness classified as use after free.

Setup

To reproduce the crash, the researcher needed two things:

  1. An ASAN build of Firefox, specifically the latest one at the time, with BuildID 20170313233726.
  2. Two files: a testcase called crash.html and a companion SVG file called mini.svg.

The report does not include the contents of either file, so the exact markup that triggers the bug is not shown here. What we do know is that the crash happens in the Web Content process. Firefox splits itself into several processes: the browser window and its menus run in one, and each web page runs in a separate, sandboxed process called the content process. A bug in the content process is reachable from ordinary page content.

No accounts, roles or special configuration are described. You do not need to be logged in or change any settings.

Finding it

The researcher attached the testcase and reported that it crashes the ASAN build. The tool then produced a stack trace: a list of function calls, from the outermost (the browser's main loop) down to the exact line where the fault happened. Reading a stack trace is like reading a recipe backwards: the top frame is where the problem occurred, and each frame below it is the function that called it.

The trace shows the fault is a read of size 8 bytes from a heap region that had already been freed. The read happens at nsSMILTargetIdentifier.h:75:38, inside a function called Equals. That function is reached through UpdateCachedTarget in nsSMILAnimationFunction.cpp:336, which is called from nsSMILCompositor::GetFirstFuncToAffectSandwich() at nsSMILCompositor.cpp:168, which is itself called from nsSMILCompositor::ComposeAttribute(bool&) at nsSMILCompositor.cpp:80:33.

In plain terms, the compositor is walking through its list of animation functions to decide which one affects the sandwich, and along the way it compares target identifiers. A target identifier is a small record that says "this animation applies to that element". The identifier it compares against has already been freed, so the comparison reads stale memory.

Exploitation

The report gives the crash trace rather than a manual exploitation sequence. The steps below follow the call chain in the trace, from the trigger to the faulting read. Think of it as following a ball as it is passed from player to player: each numbered step is one pass.

Step 1: Load the page and let the document finish loading

The outermost frames show the crash arriving during page load completion. The browser's document loader finishes fetching the page and fires a series of notifications. The trace shows nsDocLoader::OnStopRequest calling nsDocLoader::DocLoaderIsEmpty, which calls doStopDocumentLoad, then DoFireOnStateChange, then nsDocShell::OnStateChange, then nsDocShell::EndPageLoad, then nsDocumentViewer::LoadComplete. From there nsDocument::DispatchContentLoadedEvents runs through nsDocument::UnblockOnload and nsDocument::DoUnblockOnload, which removes the request from the load group and eventually dispatches the content-loaded events.

The crash arrives during page load completion, when the page's own script runs.

Step 2: A content-loaded event handler runs script

The event dispatch reaches mozilla::EventDispatcher::Dispatch, then mozilla::EventTargetChainItem::HandleEventTargetChain, then nsGlobalWindow::PostHandleEvent, and back into the event target chain. The handler is a JavaScript event listener: mozilla::EventListenerManager::HandleEventInternal calls HandleEventSubType, which calls mozilla::dom::EventListener::HandleEvent, which calls into the JavaScript engine via JS::Call and js::Call.

In plain words: the page has registered a piece of JavaScript to run when the document finishes loading. The browser reaches that handler and starts executing the page's own code. This is the first half of the attack: the page controls what runs.

Step 3: Script sets location.hash

Inside the handler, the JavaScript interpreter executes a property set (SetPropertyOperation in js::Interpreter.cpp:2747). The set crosses compartment wrappers (js::CrossCompartmentWrapper::set, js::Wrapper::set, DOMProxyHandler::set, js::SetPropertyIgnoringNamedGetter) and lands on the Location binding: mozilla::dom::LocationBinding::set_hash, then mozilla::dom::Location::SetHash, then mozilla::dom::Location::SetURI.

A few concepts here:

  • location is the browser object that represents the current URL. Setting location.hash changes the part of the URL after the # symbol, the fragment identifier.
  • A compartment is a security boundary inside the JavaScript engine. Different origins (different websites) get different compartments so one site's code cannot directly touch another's objects. A wrapper is the thin layer that lets code in one compartment talk to an object in another, while enforcing the rules.
  • A binding is the automatically generated glue code that connects a JavaScript property like location.hash to the underlying C++ implementation in the browser.

So the page's script changes the URL fragment. That is a normal, allowed operation, but it has side effects inside the browser.

Step 4: The hash change triggers a load and an anchor scroll

Location::SetURI calls nsDocShell::LoadURI, which calls nsDocShell::InternalLoad, which calls nsDocShell::ScrollToAnchor. Scrolling to the anchor calls mozilla::PresShell::GoToAnchor, which calls mozilla::dom::SVGAnimationElement::ActivateByHyperlink() at SVGAnimationElement.cpp:404:7. This is the point where an SVG animation element is activated as a result of the navigation to the fragment.

An anchor is a named location inside a page, the thing a #section link jumps to. When the fragment changes, the browser scrolls to the matching element. If that element happens to be an SVG animation element, the browser also activates it. That activation is the bridge from the page's script into the animation machinery.

Step 5: The animation controller samples and composes

ActivateByHyperlink calls nsSMILAnimationController::DoSample(bool) at nsSMILAnimationController.cpp:453:5. Sampling means the animation controller looks at the current time and works out what each active animation should look like right now. Sampling calls nsSMILCompositor::ComposeAttribute(bool&) at nsSMILCompositor.cpp:80:33, which calls nsSMILCompositor::GetFirstFuncToAffectSandwich() at nsSMILCompositor.cpp:168. That function calls UpdateCachedTarget in nsSMILAnimationFunction.cpp:336, which compares target identifiers with Equals in nsSMILTargetIdentifier.h:75:38. The comparison reads 8 bytes from the freed region and ASAN aborts.

The ASAN header for the fault is:

Text
==28440==ERROR: AddressSanitizer: heap-use-after-free on address 0x616000199dc8 at pc 0x7f8edf28b179 bp 0x7ffe8c450540 sp 0x7ffe8c450538
READ of size 8 at 0x616000199dc8 thread T0 (Web Content)

Line by line:

  • ==28440==ERROR: AddressSanitizer: heap-use-after-free tells you the process number (28440) and the class of bug: a use after free on the heap.
  • on address 0x616000199dc8 is the memory address that was touched. The 0x prefix means the number is written in hexadecimal, a base-16 counting system programmers use for memory addresses.
  • at pc 0x7f8edf28b179 bp 0x7ffe8c450540 sp 0x7ffe8c450538 gives the program counter (the instruction being executed) and the base and stack pointers, which are bookkeeping values for the current function call.
  • READ of size 8 means the program tried to read 8 bytes, the size of a pointer on a 64-bit system.
  • thread T0 (Web Content) says this happened on the main thread of the Web Content process, the one running the page.

The summary line names the faulting function and location:

Text
SUMMARY: AddressSanitizer: heap-use-after-free /home/worker/workspace/build/src/dom/smil/nsSMILTargetIdentifier.h:75:38 in Equals

This is the one-line verdict: the bug is a heap-use-after-free, and the exact source file and line is nsSMILTargetIdentifier.h, line 75, column 38, inside the function Equals. If you were triaging this report, that line is where you would start reading the code.

Step 6: The freed object is an SVG animate element

The allocation stack shows the freed region was created as an SVG animation element. NS_NewSVGAnimateElement at SVGAnimateElement.cpp:10 allocates it through operator new and moz_xmalloc, reached from NS_NewSVGElement and NS_NewElement while the XML content sink parses a start tag (nsXMLContentSink::CreateElement, nsXMLContentSink::HandleStartElement, nsExpatDriver::HandleStartElement, and the Expat parser). In other words, the object was an <animate> element created from the parsed SVG markup.

Some terms:

  • The content sink is the part of the browser that turns parsed markup into live objects in memory.
  • Expat is a small, widely used XML parser library. It reads the raw text of an XML document and reports tags and attributes to the browser.
  • operator new and moz_xmalloc are the browser's memory allocation routines. They hand out a block of heap memory for a new object.

So the object that was later freed started life as an ordinary <animate> element, created while the browser was reading the SVG file.

The free stack shows it was released by the cycle collector: SnowWhiteKiller::~SnowWhiteKiller() at nsCycleCollector.cpp:2664:9, called from nsCycleCollector::FreeSnowWhite(bool), from nsCycleCollector::BeginCollection, from nsCycleCollector::Collect, from nsCycleCollector_collect, from nsJSContext::CycleCollectNow, from nsDOMWindowUtils::CycleCollect. That call was made from JavaScript through XPConnect (XPCWrappedNative::CallMethod, XPC_WN_CallMethod), so the page itself invoked a cycle collection before the animation sampling ran.

What is a cycle collector? In a browser, objects often point at each other in loops: object A holds a reference to B, and B holds one back to A. Simple reference counting (free an object when nothing points to it) can never free such a loop, because each object keeps the other alive. The cycle collector is the garbage collector that detects these loops and frees them. SnowWhiteKiller and FreeSnowWhite are the internal names for the part that actually releases the memory. XPConnect is the bridge that lets JavaScript call into browser internals, so a page can ask the browser to run a cycle collection.

The region is described as follows:

Text
0x616000199dc8 is located 584 bytes inside of 616-byte region [0x616000199b80,0x616000199de8)

This says the address that was read sits 584 bytes into a 616-byte block of memory that started at 0x616000199b80 and ended at 0x616000199de8. In other words, the read landed inside the block that had been freed, not just near it.

So the sequence is: the SVG is parsed and an animate element is allocated; script triggers a cycle collection that frees it; then a location.hash assignment causes an anchor scroll that activates an SVG animation element and samples the animation controller, which still holds a reference to the freed target identifier and reads it.

Root cause

The compositor keeps a cached target identifier for each animation function and refreshes it in UpdateCachedTarget when composing. "Cached" means the browser stores a copy so it does not have to look it up again every time. The comparison in nsSMILTargetIdentifier::Equals dereferences that cached identifier. "Dereference" means following a pointer to read the data it points at.

When the underlying animate element has been collected by the cycle collector, the cached identifier points into freed memory, and the comparison reads it. The animation controller's sampling path does not account for the target having been collected between the time the function was registered and the time the sample runs.

The report does not state which reference or ownership rule was violated, so the precise lifetime bug is not spelled out here. What the trace establishes is that the object was freed by the cycle collector before the compositor compared against it.

Impact

The crash occurs in the Web Content process, so a page can trigger it without any user interaction beyond loading the page and running its script. The report classifies it as a use after free, which in a browser engine is potentially exploitable for memory corruption, not merely a denial of service. A denial of service just crashes the browser; memory corruption is more serious because an attacker may be able to influence what the program does next.

The report itself does not demonstrate code execution or any sandbox escape, and it does not describe how reliably the freed region could be reallocated with attacker-controlled data.

Fix

What the trace implies is that the compositor must not compare against a target identifier whose element has been collected, either by holding a strong reference for the duration of the sample or by invalidating the cached target when the element is unlinked.

Variants to test

Once you understand a bug, a useful exercise is to ask what else might behave the same way. These are the variations the technical write-up suggests:

  1. Trigger a cycle collection from script at different points relative to SMIL sampling, for example before and after the animation begins, and check whether the same Equals read appears in the trace.
  2. Use different SVG animation elements (not only <animate>) as the target of the anchor activation, and see whether the freed object is still an animation element or a different SMIL type.
  3. Replace the location.hash assignment with other navigations that reach ScrollToAnchor, and check whether ActivateByHyperlink is still the frame that starts the sample.
  4. Vary the timing between the cycle collection and the anchor scroll, for example by deferring the hash change, to see how wide the window is.

A positive result in each case is an ASAN heap-use-after-free report whose top frame is nsSMILTargetIdentifier::Equals reached through GetFirstFuncToAffectSandwich.

Hunting notes

This kind of bug hides where an engine caches a pointer or identifier to a DOM object and later uses it after script has had a chance to run. In Firefox, the SMIL compositor and animation controller are good places to look, because sampling is driven by timers and navigation events rather than by the script that created the animation.

The signal during recon is a crash whose free stack goes through the cycle collector (SnowWhiteKiller, FreeSnowWhite) while the use stack goes through a comparison or lookup on a cached identifier. That pairing, a script-triggered collection followed by an engine-internal sample, is what makes the report convincing: the page controls both halves of the lifetime. The researcher provided a testcase and a full ASAN trace with allocation, free and use stacks.

Glossary

  • ASAN (AddressSanitizer): a debugging tool built into special browser builds that detects invalid memory accesses and prints a detailed report.
  • Anchor: a named location inside a page, reached by a URL fragment such as #section.
  • Binding: automatically generated glue code that connects a JavaScript property to the browser's internal C++ implementation.
  • BuildID: a timestamp-like identifier for a specific build of the browser.
  • Cached: stored for reuse so the program does not have to look it up again.
  • Compartment: a security boundary inside the JavaScript engine that keeps different origins' objects apart.
  • Content sink: the browser component that turns parsed markup into live objects in memory.
  • Cycle collector: the garbage collector that finds objects pointing at each other in loops and frees them.
  • Dereference: follow a pointer to read the data it points at.
  • DOM: the Document Object Model, the in-memory tree of elements that makes up a web page.
  • Expat: a small XML parser library used by the browser to read XML and SVG markup.
  • Fragment identifier: the part of a URL after #, used to jump to an anchor.
  • Heap: the area of memory a program uses for objects it creates while running.
  • Heap-use-after-free: reading or writing memory that has already been freed.
  • location: the browser object representing the current URL; location.hash is its fragment part.
  • Memory corruption: a bug where a program writes to or reads memory it should not, potentially letting an attacker change its behaviour.
  • Pointer: a value that holds the memory address of another object.
  • Process: an independent running copy of a program; Firefox uses separate processes for the browser and for web content.
  • Sandbox: a restricted environment that limits what a process is allowed to do.
  • SMIL: Synchronized Multimedia Integration Language, the mechanism that lets SVG documents animate themselves.
  • Stack trace: a list of function calls showing how the program reached the point where it crashed.
  • SVG: Scalable Vector Graphics, an XML-based image format used on the web.
  • Target identifier: a small record saying which element an animation applies to.
  • Use after free: see heap-use-after-free.
  • Web Content process: the sandboxed process in which a web page runs.
  • Wrapper: a thin layer that lets code in one compartment use an object in another while enforcing security rules.
  • XPConnect: the bridge that lets JavaScript call into the browser's internal C++ code.

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.