Skip to content
Memory corruption Disclosed report Advanced

[WASM] SEGV during WasmCall in Baseline Compiler

A crafted WebAssembly module causes a segmentation fault in the baseline compiler's WasmCall path when the exported function is invoked. The crash is a memory-safety fault (invalid write) that could potentially be exploited, though the report only demonstrates a denial of service.

P1umer Follow

Originally disclosed on Mozilla

  • Fixed in 7 days
  • Paid in 13 days
  • Disclosed after 7 days
Text
Created attachment 9388023
Reproducible poc

Steps to reproduce:

Git Commit : f909cd37c43c5d9f43b4def8a8064b88b8765533
Build :
ac_add_options --enable-project=js
ac_add_options --disable-optimize
ac_add_options --disable-unified-build
ac_add_options --disable-debug
ac_add_options --disable-jemalloc

Running the POC with --wasm-compiler=baseline


Actual results:

'''
Process 2520284 stopped
* thread #1, name = 'js', stop reason = signal SIGSEGV: invalid address (fault address: 0x3d8774d0095c)
    frame #0: 0x000034d04604a5fa
->  0x34d04604a5fa: movb   %al, (%rcx,%rbx)
    0x34d04604a5fd: testl  %ebx, %ebx
    0x34d04604a5ff: jg     0x34d04604a5f7
    0x34d04604a601: pushq  %rdx
Target 0: (js) stopped.
(lldb) register read/x rbx rcx
     rbx = 0x00000000fffffff4
     rcx = 0x00003d8674d00968
(lldb) bt
* thread #1, name = 'js', stop reason = signal SIGSEGV: invalid address (fault address: 0x3d8774d0095c)
  * frame #0: 0x000034d04604a5fa
    frame #1: 0x000034d04604b7b9
    frame #2: 0x000055555824b459 js`js::wasm::Instance::callExport(this=0x0000555559239230, cx=0x000055555912a0e0, funcIndex=0, args=CallArgs @ 0x000000002619e9c0, level=Spec) at WasmInstance.cpp:3196:10
    frame #3: 0x00005555582c6027 js`WasmCall(cx=0x000055555912a0e0, argc=0, vp=<unavailable>) at WasmJS.cpp:1842:19
    frame #4: 0x0000555556dc56c1 js`js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) [inlined] CallJSNative(cx=0x000055555912a0e0, native=<unavailable>, reason=<unavailable>, args=0x00007fffffffd7c0)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&) at Interpreter.cpp:480:13
    frame #5: 0x0000555556dc5567 js`js::InternalCallOrConstruct(cx=0x000055555912a0e0, args=0x00007fffffffd7c0, construct=NO_CONSTRUCT, reason=<unavailable>) at Interpreter.cpp:574:12
    frame #6: 0x0000555556ddc4af js`js::Interpret(JSContext*, js::RunState&) [inlined] InternalCall(cx=0x000055555912a0e0, args=0x00007fffffffd7c0) at Interpreter.cpp:641:10
    frame #7: 0x0000555556ddc4a5 js`js::Interpret(JSContext*, js::RunState&) [inlined] js::CallFromStack(cx=0x000055555912a0e0, args=0x00007fffffffd7c0) at Interpreter.cpp:646:10
    frame #8: 0x0000555556ddc4a5 js`js::Interpret(cx=0x000055555912a0e0, state=0x00007fffffffd8f0) at Interpreter.cpp:3061:16
    frame #9: 0x0000555556dc4b50 js`js::RunScript(JSContext*, js::RunState&) [inlined] MaybeEnterInterpreterTrampoline(cx=0x000055555912a0e0, state=0x00007fffffffd8f0) at Interpreter.cpp:394:10
    frame #10: 0x0000555556dc4b25 js`js::RunScript(cx=0x000055555912a0e0, state=0x00007fffffffd8f0) at Interpreter.cpp:452:13
    frame #11: 0x0000555556dc7ca0 js`js::ExecuteKernel(cx=<unavailable>, script=<unavailable>, envChainArg=<unavailable>, evalInFrame=(ptr_ = 0), result=<unavailable>) at Interpreter.cpp:839:13
    frame #12: 0x0000555556dc7ecc js`js::Execute(cx=<unavailable>, script=<unavailable>, envChain=<unavailable>, rval=<unavailable>) at Interpreter.cpp:871:10 [artificial]
    frame #13: 0x00005555570d354d js`ExecuteScript(cx=<unavailable>, envChain=<unavailable>, script=<unavailable>, rval=<unavailable>) at CompilationAndEvaluation.cpp:494:10 [artificial]
    frame #14: 0x00005555570d36df js`JS_ExecuteScript(cx=0x000055555912a0e0, scriptArg=JS::HandleScript @ scalar) at CompilationAndEvaluation.cpp:518:10
    frame #15: 0x0000555556d10b98 js`RunFile(cx=0x000055555912a0e0, filename="/tmp/crash.js", file=0x0000555559252f40, compileMethod=DontInflate, compileOnly=false, fullParse=false) at js.cpp:1200:10
    frame #16: 0x0000555556d10281 js`Process(cx=0x000055555912a0e0, filename="/tmp/crash.js", forceTTY=false, kind=FileScript) at js.cpp:1780:14
    frame #17: 0x0000555556ccbcb7 js`Shell(JSContext*, js::cli::OptionParser*) at js.cpp:10991:10
    frame #18: 0x0000555556ccbc15 js`Shell(cx=0x000055555912a0e0, op=0x00007fffffffdef8) at js.cpp:11250:12
    frame #19: 0x0000555556cc1391 js`main(argc=<unavailable>, argv=<unavailable>) at js.cpp:11758:12
    frame #20: 0x00007ffff7a48083 libc.so.6`__libc_start_main + 243
    frame #21: 0x0000555556ca3889 js`_start + 41
'''

The original report as published on Mozilla's Bugzilla, by P1umer. 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 missing bounds or type check in the baseline compiler's handling of a Wasm export call, leading to an out-of-bounds write.

Impact

An attacker could crash the JavaScript engine (denial of service) and potentially achieve code execution due to the memory corruption, though the report only demonstrates a crash.

What the attacker needed

Ability to run a crafted Wasm file; baseline Wasm compiler enabled

How it was found

  1. Build the JavaScript shell with the baseline Wasm compiler enabled.
  2. Run the provided proof-of-concept file with the baseline compiler flag.
  3. Observe the segmentation fault during the Wasm export call.

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.

WebAssembly (Wasm) is a fast, low-level code format that runs inside browsers and JavaScript engines. The baseline compiler is a quick, simple compiler used to run Wasm code. Here, a specially crafted Wasm file makes the engine write to a bad memory address, crashing the program; this is a memory-safety bug that could be more than just a crash.

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 P1umer

View all

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