Skip to content
Memory corruption Disclosed report Advanced CVE-2018-18500

Heap write-after-free in Custom Elements / HTML5 Parser

A use-after-free occurs in the HTML5 stream parser when a microtask checkpoint during custom element creation allows JavaScript to navigate away, freeing the parser object. The subsequent write to freed memory can be used to corrupt a WebGLBuffer object, potentially leading to memory disclosure and further corruption.

yaniv.frank Follow

Originally disclosed on Mozilla

Critical View original
  • Fixed in 22 days
  • Paid in 42 days
  • Disclosed after 22 days
Text
Created attachment 9027785
ASAN log from mozilla-central linux64-asan-debug 20181126161820

While parsing an HTML5 stream, a microtask checkpoint is performed when a custom element is being created.
By using a mutation observer callback it's possible to run arbitrary javascript code inside this checkpoint, allowing us to cause the destruction of the currently running nsHtml5StreamParser object by navigating to another page.
When the checkpoint finishes, a write to freed heap memory (a 0x1000 sized allocation previously belonging to nsHtml5StreamParser) occurs.
The content being written to freed memory is a pointer to a newly created nsIContent object, and it is written at a controllable offset (determined by the number of elements in the stream).

In the attached POC, a WebGLBuffer object is allocated in place of the freed object and the bug is used to overwrite its mByteLength field, potentially allowing for further disclosure and corruption of memory. tested successfully on Firefox 63.0.3 - Windows 7.
$ python delay_http_server.py 8080 &
$ firefox http://127.0.0.1:8080/customelements_uaf_poc.html

The original report as published on Mozilla's Bugzilla, by yaniv.frank. 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 parser does not expect re-entrant JavaScript execution during a microtask checkpoint, so it continues to use its own object after navigation has freed it.

Impact

The write to freed memory could allow further disclosure and corruption of memory, though the report only demonstrates overwriting a WebGLBuffer field.

What the attacker needed

Victim visits a malicious page; JavaScript enabled; Firefox browser

How it was found

  1. Start a local HTTP server that delays responses.
  2. Open the proof-of-concept page in Firefox.
  3. The page uses a mutation observer to navigate away during a microtask checkpoint, freeing the parser.
  4. The parser then writes to the freed memory, corrupting a WebGLBuffer object.

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.

When a web page is loading, the browser uses a parser to read the HTML. A bug lets a script run at a moment when the parser is still in use, and that script can navigate to another page, which frees the parser's memory. The browser then writes to that freed memory, which can be abused to corrupt other data.

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