Skip to content
DoS Disclosed report Advanced CVE-2024-2606

[WASM] MOZ_ASSERT(v.isMem() == result.onStack());

A crafted WebAssembly module triggers an assertion failure in the baseline compiler when compiling a br_on_cast instruction, causing a crash. The report does not claim any attacker impact beyond the crash.

P1umer Follow

Originally disclosed on Mozilla

  • Fixed in 20 days
  • Paid in 27 days
  • Disclosed after 20 days

Created attachment 9378912 poc0208.js

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Steps to reproduce:

OS : Linux ubuntu 5.11.10 #1 SMP Sat Oct 30 23:40:08 CST 2021 x86_64 x86_64 x86_64 GNU/Linux Commit : 719b4a8853b449674c018178f85b3667afe4f193 Build : ac_add_options --enable-project=js ac_add_options --disable-optimize ac_add_options --disable-unified-build ac_add_options --enable-debug ac_add_options --disable-jemalloc

Running: ./js --wasm-memory-control --wasm-compiler=baseline --wasm-exnref poc.js

Actual results:

Stopped reason: SIGSEGV
0x0000555559313036 in js::wasm::BaseCompiler::shuffleStackResultsBeforeBranch (this=0x7fffffff2be8, srcHeight=..., destHeight=..., type=...) at gecko-dev-latest/js/src/wasm/WasmBaselineCompile.cpp:1298
1298	      MOZ_ASSERT(v.isMem() == result.onStack());
gdb-peda$ bt
#0  0x0000555559313036 in js::wasm::BaseCompiler::shuffleStackResultsBeforeBranch(js::wasm::StackHeight, js::wasm::StackHeight, js::wasm::ResultType)
    (this=0x7fffffff2be8, srcHeight=..., destHeight=..., type=...) at gecko-dev-latest/js/src/wasm/WasmBaselineCompile.cpp:1298
#1  0x0000555559319a19 in js::wasm::BaseCompiler::jumpConditionalWithResults(js::wasm::BranchState*, js::wasm::RegRef, js::wasm::RefType, js::wasm::RefType, bool) (this=0x7fffffff2be8, b=0x7ffffffee658, object=..., sourceType=..., destType=..., onSuccess=0x0)
    at gecko-dev-latest/js/src/wasm/WasmBaselineCompile.cpp:3245
#2  0x000055555932e8a1 in js::wasm::BaseCompiler::emitBrOnCastCommon(bool, unsigned int, js::wasm::ResultType const&, js::wasm::RefType, js::wasm::RefType) (this=0x7fffffff2be8, onSuccess=0x0, labelRelativeDepth=0x0, labelType=..., sourceType=..., destType=...)
    at gecko-dev-latest/js/src/wasm/WasmBaselineCompile.cpp:8392
#3  0x000055555932ea8d in js::wasm::BaseCompiler::emitBrOnCast(bool) (this=0x7fffffff2be8, onSuccess=0x0)
    at gecko-dev-latest/js/src/wasm/WasmBaselineCompile.cpp:8418
#4  0x0000555559343057 in js::wasm::BaseCompiler::emitBody() (this=0x7fffffff2be8)
    at gecko-dev-latest/js/src/wasm/WasmBaselineCompile.cpp:10629
#5  0x000055555936831a in js::wasm::BaseCompiler::emitFunction() (this=0x7fffffff2be8)
    at gecko-dev-latest/js/src/wasm/WasmBaselineCompile.cpp:11740
#6  0x0000555559369669 in js::wasm::BaselineCompileFunctions(js::wasm::ModuleEnvironment const&, js::wasm::CompilerEnvironment const&, js::LifoAlloc&, mozilla::Vector<js::wasm::FuncCompileInput, 8ul, js::SystemAllocPolicy> const&, js::wasm::CompiledCode*, mozilla::UniquePtr<char [], JS::FreePolicy>*)
     (moduleEnv=..., compilerEnv=..., lifo=..., inputs=..., code=0x55555a0b1280, error=0x7fffffff5658)
    at gecko-dev-latest/js/src/wasm/WasmBaselineCompile.cpp:11917
#7  0x000055555943b9e4 in ExecuteCompileTask(js::wasm::CompileTask*, mozilla::UniquePtr<char [], JS::FreePolicy>*)
    (task=0x55555a0b0ed0, error=0x7fffffff5658) at gecko-dev-latest/js/src/wasm/WasmGenerator.cpp:735
#8  0x000055555943bbe4 in js::wasm::ModuleGenerator::locallyCompileCurrentTask() (this=0x7fffffff4560)
    at gecko-dev-latest/js/src/wasm/WasmGenerator.cpp:784
#9  0x000055555943c777 in js::wasm::ModuleGenerator::finishFuncDefs() (this=0x7fffffff4560)
    at gecko-dev-latest/js/src/wasm/WasmGenerator.cpp:915
#10 0x0000555559414106 in DecodeCodeSection<js::wasm::Decoder>(js::wasm::ModuleEnvironment const&, js::wasm::Decoder&, js::wasm::ModuleGenerator&)
    (env=..., d=..., mg=...) at gecko-dev-latest/js/src/wasm/WasmCompile.cpp:785
#11 0x0000555559413e32 in js::wasm::CompileBuffer(js::wasm::CompileArgs const&, js::wasm::ShareableBytes const&, mozilla::UniquePtr<char [], JS::FreePolicy>*, mozilla::Vector<mozilla::UniquePtr<char [], JS::FreePolicy>, 0ul, js::SystemAllocPolicy>*, JS::OptimizedEncodingListener*)
    (args=..., bytecode=..., error=0x7fffffff5658, warnings=0x7fffffff56a0, listener=0x0)
    at gecko-dev-latest/js/src/wasm/WasmCompile.cpp:807
#12 0x00005555594fe1ce in js::WasmModuleObject::construct(JSContext*, unsigned int, JS::Value*) (cx=0x555559f66060, argc=0x1, vp=0x55555a0731c8)
    at gecko-dev-latest/js/src/wasm/WasmJS.cpp:1494
#13 0x0000555557982f26 in CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&)
    (cx=0x555559f66060, native=0x5555594fddd0 <js::WasmModuleObject::construct(JSContext*, unsigned int, JS::Value*)>, reason=js::CallReason::Call, args=...) at gecko-dev-latest/js/src/vm/Interpreter.cpp:480
#14 0x00005555579940ea in CallJSNativeConstructor(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), JS::CallArgs const&)
    (cx=0x555559f66060, native=0x5555594fddd0 <js::WasmModuleObject::construct(JSContext*, unsigned int, JS::Value*)>, args=...)
    at gecko-dev-latest/js/src/vm/Interpreter.cpp:496
#15 0x000055555794a3ae in InternalConstruct(JSContext*, js::AnyConstructArgs const&, js::CallReason)
    (cx=0x555559f66060, args=..., reason=js::CallReason::Call) at gecko-dev-latest/js/src/vm/Interpreter.cpp:702
#16 0x0000555557949dc1 in js::ConstructFromStack(JSContext*, JS::CallArgs const&, js::CallReason)
    (cx=0x555559f66060, args=..., reason=js::CallReason::Call) at gecko-dev-latest/js/src/vm/Interpreter.cpp:749
#17 0x000055555795f13e in js::Interpret(JSContext*, js::RunState&) (cx=0x555559f66060, state=...)
    at gecko-dev-latest/js/src/vm/Interpreter.cpp:3046
#18 0x00005555579488ac in MaybeEnterInterpreterTrampoline(JSContext*, js::RunState&) (cx=0x555559f66060, state=...)
    at gecko-dev-latest/js/src/vm/Interpreter.cpp:394
#19 0x0000555557948492 in js::RunScript(JSContext*, js::RunState&) (cx=0x555559f66060, state=...)
    at gecko-dev-latest/js/src/vm/Interpreter.cpp:452
#20 0x000055555794b257 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, js::AbstractFramePtr, JS::MutableHandle<JS::Value>)
    (cx=0x555559f66060, script=0xc92dfd66060, envChainArg=(JSObject * const) 0xc92dfd3f038 [object LexicalEnvironment], evalInFrame=AbstractFramePtr ((js::InterpreterFrame *) 0x0) = {...}, result=$JS::UndefinedValue()) at gecko-dev-latest/js/src/vm/Interpreter.cpp:839
#21 0x000055555794b65c in js::Execute(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, JS::MutableHandle<JS::Value>)
    (cx=0x555559f66060, script=0xc92dfd66060, envChain=(JSObject * const) 0xc92dfd3f038 [object LexicalEnvironment], rval=$JS::UndefinedValue())
    at gecko-dev-latest/js/src/vm/Interpreter.cpp:871
#22 0x0000555557dca0df in ExecuteScript(JSContext*, JS::Handle<JSObject*>, JS::Handle<JSScript*>, JS::MutableHandle<JS::Value>)
    (cx=0x555559f66060, envChain=(JSObject * const) 0xc92dfd3f038 [object LexicalEnvironment], script=0xc92dfd66060, rval=$JS::UndefinedValue())
    at gecko-dev-latest/js/src/vm/CompilationAndEvaluation.cpp:494
#23 0x0000555557dca206 in JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>) (cx=0x555559f66060, scriptArg=0xc92dfd66060)
    at gecko-dev-latest/js/src/vm/CompilationAndEvaluation.cpp:518
#24 0x00005555577d0527 in RunFile(JSContext*, char const*, _IO_FILE*, CompileUtf8, bool, bool)
    (cx=0x555559f66060, filename=0x55555a07a5a0 "/tmp/crash3.js", file=0x555559ffe250, compileMethod=CompileUtf8::DontInflate, compileOnly=0x0, fullParse=0x0) at gecko-dev-latest/js/src/shell/js.cpp:1221
#25 0x00005555577cfba0 in Process(JSContext*, char const*, bool, FileKind)
    (cx=0x555559f66060, filename=0x55555a07a5a0 "/tmp/crash3.js", forceTTY=0x0, kind=FileScript)
    at gecko-dev-latest/js/src/shell/js.cpp:1801
#26 0x000055555779bb7b in ProcessArgs(JSContext*, js::cli::OptionParser*) (cx=0x555559f66060, op=0x7fffffffdec0)
    at gecko-dev-latest/js/src/shell/js.cpp:10905
#27 0x0000555557792c57 in Shell(JSContext*, js::cli::OptionParser*) (cx=0x555559f66060, op=0x7fffffffdec0)
    at gecko-dev-latest/js/src/shell/js.cpp:11167
#28 0x000055555778d969 in main(int, char**) (argc=0x5, argv=0x7fffffffe118) at gecko-dev-latest/js/src/shell/js.cpp:11571
#29 0x00007ffff7a48083 in __libc_start_main () at /lib/x86_64-linux-gnu/libc.so.6
#30 0x0000555557753b79 in _start ()

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

Impact

The crafted WebAssembly module causes a crash in the JavaScript shell; the report does not demonstrate any further impact.

What the attacker needed

Debug build of the JS shell; ability to run the shell with specific flags

How it was found

  1. Build the JavaScript shell with the specified debug options.
  2. Run the shell with the provided flags and the proof-of-concept script.
  3. Observe the assertion failure and crash.

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 is a way to run compiled code in the browser. The baseline compiler is a fast, simple compiler that turns WebAssembly into machine code. A specially crafted WebAssembly file made this compiler hit an internal check and crash, but the report does not show how this could be used by an attacker.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

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.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.