Assertion failure and incorrect result during Ion rotate bailout recovery
Categories
(Core :: JavaScript Engine: JIT, defect, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox-esr153 | --- | unaffected |
| firefox157 | --- | unaffected |
| firefox158 | --- | unaffected |
| firefox159 | --- | fixed |
People
(Reporter: bugmon, Assigned: iain)
References
(Blocks 1 open bug, Regression)
Details
(Keywords: assertion, regression, testcase)
Attachments
(6 files, 1 external file)
RRotate::recover extracts its recovered operand as an int32-tagged JS::Value instead of applying integer conversion (js/src/jit/Recover.cpp:297). RAdd::recover can supply the double 2147483648 when reconstructing 2147483647 + 1 (js/src/jit/Recover.cpp:352). The direct payload accessor asserts in the debug build and produces an incorrect rotate result in the optimized build.
A JavaScript-shell caller can abort an assertion-enabled SpiderMonkey process and obtain an incorrect optimized result by triggering an Ion bailout while a folded rotate depends on an addition outside the signed-int32 range. The submitted testcase produces 1 instead of 1073741825 in the optimized ASAN shell, while the no-Ion control passes. No memory corruption or cross-process effect was demonstrated.
This finding was discovered by a scan of commit 191e6cdfb5cfce225e435f3ef7e427500b36df91^..8d9e3313812a5c83170f0e1addbfaeeb7afc6fa8. The scan that produced this finding was directed at the changes landed by that commit, which may or may not be its actual cause. Please judge independently whether they are really connected.
Build Info
- Branch: main
- Revision: 0a5c5bffebd796cedba281419efd2f8f3cc7c85d
- Timestamp: 2026-09-25T04:35:53+00:00
Affected Code
File: js/src/jit/Recover.cpp, line 296
bool RRotate::recover(JSContext* cx, SnapshotIterator& iter) const {
uint32_t input = uint32_t(iter.read().toInt32());
int32_t c = iter.read().toInt32();
MOZ_ASSERT(c >= 1 && c <= 31);
uint32_t result = isLeftRotate_ ? ((input << c) | (input >> (32 - c)))
: ((input >> c) | (input << (32 - c)));
iter.storeInstructionResult(Int32Value(int32_t(result)));
return true;
}
File: js/public/Value.h, line 937
int32_t toInt32() const {
MOZ_ASSERT(isInt32());
return int32_t(asBits_);
}
MBitOr::foldsTo recognizes the paired shifts and creates MRotate (js/src/jit/MIR.cpp:2816). Int32 rotates are recoverable on bailout (js/src/jit/MIR.h:9528). Recovery reconstructs JavaScript values, not necessarily their optimized MIR representations: RAdd::recover calls js::AddValues and stores its result. RRotate::recover must therefore convert the recovered numeric input rather than assume its value tag.
Exploit Chain
- Warm up
rotateRecoveredwith small integers and its false branch using the submitted shell JIT settings. - Ion folds the paired shifts into a recoverable rotate.
- Call the function with
2147483647and the previously untaken branch enabled, causing bailout recovery to reconstruct the addition as the double2147483648. - The rotate recovery's raw int32 extraction triggers the debug assertion; optimized execution instead returns
1rather than1073741825.
Steps to Reproduce
- Use clean
/firefoxrevision0a5c5bffebd796cedba281419efd2f8f3cc7c85d. No source patches, custom preferences, additional environment variables, or services are required. - Call
build_firefoxwithfirefox_dir="/firefox"andmozconfig_path="/app/mozconfigs/mozconfig.js.linux.debug". - Pass the contents of
/tmp/tmpwn2xb88n/rotate-recovery.js:1tojs_shell_evaluatorwithjs_binary="/firefox/obj-js-debug/dist/bin/js",flags=[], andtimeout=60. The evaluator supplies--fuzzing-safe. - Observe
crashed=true,timed_out=false, exit code1, and the matchingisInt32()assertion. The complete independent crash log is/tmp/tmpwn2xb88n/verification/debug-run/log_stderr.txt:1. - For optimized confirmation, build with
/app/mozconfigs/mozconfig.linux.asan.fuzzingand run the same testcase using/firefox/obj-firefox-asan/dist/bin/js. It exits3withgot 1, expected 1073741825; repeating withflags=["--no-ion"]exits0.
Security Impact
- Severity: Low
- Attacker capability: Trigger an engine assertion in debug SpiderMonkey and produce an incorrect arithmetic result in optimized SpiderMonkey. Memory corruption and arbitrary code execution are not demonstrated.
- Preconditions: Attacker-controlled JavaScript executes with Ion enabled and reaches bailout recovery for the folded rotate. The reproduction uses supported shell JIT-option APIs.
ASAN Report
[5622] Assertion failure: isInt32(), at /firefox/obj-js-debug/dist/include/js/Value.h:938
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==5622==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x558ff47324be bp 0x7eb2b64c20f0 sp 0x7eb2b64c20a0 T5622)
#0 0x558ff47324be in MOZ_CrashSequence(void*, long) /firefox/obj-js-debug/dist/include/mozilla/Assertions.h:261:3
#1 0x558ff47324be in JS::Value::toInt32() const /firefox/obj-js-debug/dist/include/js/Value.h:938:5
#2 0x558ff47324be in js::jit::RRotate::recover(JSContext*, js::jit::SnapshotIterator&) const /firefox/obj-js-debug/js/src/jit/./../../../../js/src/jit/Recover.cpp:297:41
#3 0x558ff4e6e761 in js::jit::SnapshotIterator::computeInstructionResults(JSContext*, js::jit::RInstructionResults*) const /firefox/obj-js-debug/js/src/jit/./../../../../js/src/jit/JitFrames.cpp:2324:29
#4 0x558ff4e6c3e0 in js::jit::SnapshotIterator::initInstructionResults(js::jit::MaybeReadFallback&) /firefox/obj-js-debug/js/src/jit/./../../../../js/src/jit/JitFrames.cpp:2277:12
#5 0x558ff45a6b02 in js::jit::BailoutIonToBaseline(JSContext*, js::jit::JitActivation*, js::jit::JSJitFrameIter const&, js::jit::BaselineBailoutInfo**, js::jit::ExceptionBailoutInfo const*, js::jit::BailoutReason) /firefox/obj-js-debug/js/src/jit/./../../../../js/src/jit/BaselineBailouts.cpp:1669:17
#6 0x558ff45a60ce in js::jit::Bailout(js::jit::BailoutStack*, js::jit::BaselineBailoutInfo**) /firefox/obj-js-debug/js/src/jit/./../../../../js/src/jit/Bailouts.cpp:144:7
#7 0x36d359dc6401 ([anon:js-executable-memory]+0x401)
SUMMARY: UndefinedBehaviorSanitizer: SEGV /firefox/obj-js-debug/dist/include/mozilla/Assertions.h:261:3 in MOZ_CrashSequence(void*, long)
==5622==ABORTING
| Reporter | ||
Comment 1•1 month ago
|
||
| Reporter | ||
Comment 2•1 month ago
|
||
| Reporter | ||
Comment 3•1 month ago
|
||
| Reporter | ||
Comment 4•1 month ago
|
||
| Reporter | ||
Comment 5•1 month ago
|
||
| Reporter | ||
Comment 6•1 month ago
|
||
Comment 7•1 month ago
|
||
This bug was filed automatically by an AI-powered security testing tool. The analysis, testcase, and any suggested patches were generated by an AI model and have NOT been verified by a human.
Please review all details carefully before triaging. The issue was confirmed by an independent verifier, but for non-ASAN issues, the verifier has been made less strict. Additionally, the root cause analysis and suggested fix may contain errors.
Updated•1 month ago
|
Comment 8•1 month ago
|
||
The severity field is not set for this bug.
:gtonietto, could you have a look please?
For more information, please visit BugBot documentation.
Updated•1 month ago
|
| Assignee | ||
Comment 9•1 month ago
|
||
This is a bug in my patches for bug 2074467. It is not security sensitive. The proposed fix looks correct.
| Assignee | ||
Comment 10•1 month ago
|
||
Updated•1 month ago
|
Comment 11•1 month ago
|
||
Comment 12•1 month ago
|
||
| bugherder | ||
Updated•1 month ago
|
Description
•