irregexp parked-position drain optimization skips start positions when a backreference follows a captured greedy loop; /(\w+)\s+\1/.exec("hello ello") returns null
Categories
(Core :: JavaScript Engine, defect, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox160 | --- | fixed |
People
(Reporter: bugmon, Assigned: iain)
References
(Blocks 1 open bug)
Details
(Keywords: testcase)
Attachments
(3 files, 1 external file)
Found by a scan of commit 3806ed99457a0c47c9a4b68a08778a1d19c67983^..359ab0323379b0f997a21bb2703c0282f78ce739. 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.
LoopChoiceNode::ComputeSearchBodyParkedGrant (js/src/irregexp/imported/regexp-compiler.cc:4337) treats STORE_POSITION as a register-only action (ActionNode::IsRegisterOnlyAction, regexp-nodes.h:527), so a search-loop body whose greedy character-class run is wrapped in a capture group still receives the kParkedUniformPrefix grant even though the continuation's behavior depends on where the run started — breaking the uniform-prefix soundness argument at regexp-nodes.h:269 whenever a backreference to that capture follows. Under that grant Trace::Flush (regexp-compiler.cc:745) omits the PushCurrentPosition save of the attempt start, the drain restores only to the loop entry and the loop-exit backtrack lands at parked_reentry, so start positions inside the consumed run are never retried and /(\w+)\s+\1/.exec("hello ello") returns null instead of the spec-mandated ["ello ello","ello"] at index 1 (V8's d8 returns the correct result); the wrong answer reproduces in the interpreter, the regexp JIT, and debug and ASAN shells, with no memory-safety effect observed.
Exploit Chain
- A page executes a RegExp whose pattern begins with a captured greedy
+loop over a character class, whose continuation begins with a disjoint class and later contains a backreference, e.g. /(\w+)\s+\1/ or /(\d+)x\1/. - irregexp classifies the search-loop body as kParkedUniformPrefix (ComputeSearchBodyParkedGrant) because STORE_POSITION is treated as register-only and the trailing \w* loop is atomic (kDisjoint).
- Trace::Flush skips the PushCurrentPosition save; on continuation failure at start position 0 the drain restores only to the loop entry (position 1) and the loop-exit backtrack lands at parked_reentry, which advances and retries from position 2.
- Start position 1, where (\w+)="ello", \s+=" ", \1="ello" would match, is never attempted; exec returns null (observed) instead of the spec-mandated ["ello ello","ello"] at index 1 (returned by V8).
- Web content observing RegExp results gets wrong answers: missed matches (null) or matches at a later index than required, in every regexp execution tier.
Affected Code
- js/src/irregexp/imported/regexp-compiler.cc, line 4337-4381
- js/src/irregexp/imported/regexp-nodes.h, line 527-532
- js/src/irregexp/imported/regexp-nodes.h, line 269-275
- js/src/irregexp/imported/regexp-compiler.cc, line 745-780
Steps to Reproduce
- Build the SpiderMonkey debug shell from an unmodified tree with /app/mozconfigs/mozconfig.js.linux.debug (build_dir /firefox/obj-js-debug).
- Run js_shell_differential_evaluator with shell_a=/firefox/obj-js-debug/dist/bin/js (spidermonkey), shell_b=/app/tools/d8/d8 (v8), content=testcase.js.
- Observe differs=true: A=FAIL (exit 3, stderr 'Error: wrong result: null'), B=OK (exit 0).
- Re-run with flags_a=["--differential-testing"]; observe differs=true again with identical exit codes.
- Optionally confirm tier-independence: the shell prints null for /(\w+)\s+\1/.exec("hello ello") under --no-native-regexp, --regexp-warmup-threshold=0, and in /firefox/obj-firefox-asan/dist/bin/js; d8 prints ["ello ello","ello"] at index 1.
Security Impact
- Severity: Low
- Attacker capability: None demonstrated beyond incorrect RegExp results: RegExp.prototype.exec (and by extension test/match/replace/split) can return null or a later-index match where ECMAScript 22.2.7.2 RegExpBuiltinExec requires a match at an earlier index, for patterns with a captured greedy loop followed by a backreference. This is a correctness defect in the regexp compiler affecting all execution tiers; no memory-safety effect was observed (no ASAN report in the ASAN shell).
- Preconditions: None; any web content evaluating an affected RegExp in an unmodified default-configuration build triggers it.
The full analysis report is attached (analysis.md).
| Reporter | ||
Comment 1•2 months ago
|
||
| Reporter | ||
Comment 2•2 months ago
|
||
| Reporter | ||
Comment 3•2 months ago
|
||
Comment 4•2 months 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•2 months ago
|
Updated•2 months ago
|
| Assignee | ||
Comment 5•2 months ago
|
||
This is a bug in upstream V8. The report claims that V8 gets the right result, but I assume the model was testing with an older version where the bug hadn't been introduced. I opened this upstream issue.
| Assignee | ||
Comment 7•28 days ago
|
||
This is fixed by the irregexp update in bug 2083707.
Updated•28 days ago
|
Comment 9•27 days ago
|
||
| bugherder | ||
Updated•20 days ago
|
Description
•