Closed Bug 2041999 Opened 6 months ago Closed 2 months ago

[WASM][WasmSmith] Assertion failure !gIsWasmSmith || !error at testWasm.cpp:289 (Validation Mismatch)

Categories

(Core :: JavaScript: WebAssembly, defect, P3)

defect

Tracking

()

RESOLVED FIXED
158 Branch
Tracking Status
firefox158 --- fixed

People

(Reporter: uncleruc2075, Assigned: uncleruc2075)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 1 external file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36

Steps to reproduce:

  1. Use a SpiderMonkey build with WasmSmith fuzzer support enabled.
  2. Run the fuzz-tests binary with the WasmSmith target using the attached 12-byte crash file:

Actual results:

The process crashed due to an assertion failure in the fuzzer harness:
Assertion failure: !gIsWasmSmith || !error, at checkouts/gecko/js/src/fuzz-tests/testWasm.cpp:289

This indicates that the CompileModule function returned a validation error for a module generated by wasm-smith. Since wasm-smith is intended to generate only valid WebAssembly modules, this
assertion failure reveals a "Validation Mismatch" between the generator and the SpiderMonkey engine.

What should have happened? (expected results)
WebAssembly modules generated by wasm-smith should be considered valid by the SpiderMonkey engine and should not trigger validation errors or assertion failures in the fuzzer harness.

Expected results:

WebAssembly modules generated by wasm-smith should be considered valid by the SpiderMonkey engine and should not trigger validation errors or assertion failures in the fuzzer harness.

FUZZER=WasmSmith ./fuzz-tests crash-d5d73b76950621acd2928c573383cb68c84ab795

Component: JavaScript Engine → JavaScript: WebAssembly

This error occurs quite frequently and prevents the fuzzing process from working properly.

Blocks: sm-security
Severity: -- → S3
Priority: -- → P3

I ran the fuzzer on that file and extracted the wasm module. This is what we have:

ryanhunt@Ryans-MacBook-Pro wasmsmith-crash % wasm-tools print out.wasm
(module
  (import "" "" (memory (;0;) i64 280376103141120))
)
ryanhunt@Ryans-MacBook-Pro wasmsmith-crash % ./mach run
Creating the 'common' site at /Users/ryanhunt/.mozbuild/srcdirs/wasmsmith-crash-01e9c25d76d4/_virtualenvs/common
 0:00.41 /Users/ryanhunt/src/firefox/wasmsmith-crash/obj-shell/dist/bin/js
js> let b = wasmTextToBinary(`(module
  (import "" "" (memory (;0;) i64 280376103141120))
)`);
js> WebAssembly.validate(b);
false

It looks like we're failing to validate a really big wasm memory. The issue is that we restrict a memory max bytes to be within MAX_SAFE_INTEGER during validation [1].

It's ambiguous if this is correct or not, and this PR will move this from a validation error to an instantiation error [2]. But this is not a serious validation issue. We could change the Config we pass to wasm-smith to workaround this issue [3].

[1] https://searchfox.org/firefox-main/rev/a49121972a6140a227e2d0d585afbce3f9e5e11a/js/src/wasm/WasmMemory.h#187-199
[2] https://github.com/WebAssembly/spec/pull/2089
[3] https://docs.rs/wasm-smith/0.250.0/wasm_smith/struct.Config.html#structfield.max_memory64_bytes

Assignee: nobody → uncleruc2075
Attachment #9642334 - Attachment description: WIP: Bug 2041999 - Limit wasm-smith memory64 sizes → Bug 2041999 - Limit wasm-smith memory64 sizes
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 158 Branch
QA Whiteboard: [qa-triage-done-c159/b158]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: