Closed Bug 2075982 Opened 1 month ago Closed 1 month ago

Assertion failure and incorrect result during Ion rotate bailout recovery

Categories

(Core :: JavaScript Engine: JIT, defect, P3)

defect

Tracking

()

RESOLVED FIXED
159 Branch
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

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

  1. Warm up rotateRecovered with small integers and its false branch using the submitted shell JIT settings.
  2. Ion folds the paired shifts into a recoverable rotate.
  3. Call the function with 2147483647 and the previously untaken branch enabled, causing bailout recovery to reconstruct the addition as the double 2147483648.
  4. The rotate recovery's raw int32 extraction triggers the debug assertion; optimized execution instead returns 1 rather than 1073741825.

Steps to Reproduce

  1. Use clean /firefox revision 0a5c5bffebd796cedba281419efd2f8f3cc7c85d. No source patches, custom preferences, additional environment variables, or services are required.
  2. Call build_firefox with firefox_dir="/firefox" and mozconfig_path="/app/mozconfigs/mozconfig.js.linux.debug".
  3. Pass the contents of /tmp/tmpwn2xb88n/rotate-recovery.js:1 to js_shell_evaluator with js_binary="/firefox/obj-js-debug/dist/bin/js", flags=[], and timeout=60. The evaluator supplies --fuzzing-safe.
  4. Observe crashed=true, timed_out=false, exit code 1, and the matching isInt32() assertion. The complete independent crash log is /tmp/tmpwn2xb88n/verification/debug-run/log_stderr.txt:1.
  5. For optimized confirmation, build with /app/mozconfigs/mozconfig.linux.asan.fuzzing and run the same testcase using /firefox/obj-firefox-asan/dist/bin/js. It exits 3 with got 1, expected 1073741825; repeating with flags=["--no-ion"] exits 0.

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
Attached patch fix.patch — — Splinter Review
Attached file crash_stack.txt —
Attached file README.md —
Attached file log_stdout.txt —
Attached file rotate-recovery.js —
Attached file optimized-stderr.txt —

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.

Group: core-security → javascript-core-security

The severity field is not set for this bug.
:gtonietto, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(gtonietto)
Blocks: sm-security
Severity: -- → S3
Flags: needinfo?(gtonietto)
Priority: -- → P3

This is a bug in my patches for bug 2074467. It is not security sensitive. The proposed fix looks correct.

Group: javascript-core-security
Keywords: sec-other
Assignee: nobody → iireland
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Status: ASSIGNED → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 159 Branch
Flags: in-testsuite+
Keywords: regression
Regressed by: 2074467
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: