Closed Bug 2043301 Opened 6 months ago Closed 6 months ago

Crash [@ CyclicModuleResolveExport] with self-reexporting module chain

Categories

(Core :: JavaScript Engine, defect)

x86_64
Linux
defect

Tracking

()

RESOLVED DUPLICATE of bug 2042305

People

(Reporter: decoder, Unassigned)

Details

(Keywords: ai-involved, sec-high, testcase)

Attachments

(1 file)

Summary

Stack overflow crash in CyclicModuleResolveExport when resolving a long chain of indirect self-reexports within a single module. The resolveSet cycle guard only detects repeated (module, exportName) pairs, so a chain that changes the export name at every step bypasses it and recurses until native stack exhaustion.

Root Cause

CyclicModuleResolveExport (js/src/vm/Modules.cpp:978) recurses through ModuleResolveExportWithResolveSet (Modules.cpp:890) for each indirect export entry. The resolveSet prevents infinite loops when the same (module, exportName) pair is seen twice, but a self-reexport chain like:

export { x1 as x0 } from "M";
export { x2 as x1 } from "M";
...
export let x20000 = 1;

produces 20,000 distinct ("M", "xN") pairs, none of which repeat. Each step re-enters CyclicModuleResolveExport recursively. There is no AutoCheckRecursionLimit guard on this resolution path (Modules.cpp:1011), so the native stack is exhausted.

Reproduction

Tested with js shell build mozilla-central 20260521-b754e06486cf (ASan debug and ASan opt, Linux x86-64).

# From the firefox source directory:
m-c-asan-debug/dist/bin/js --fuzzing-safe poc.js
m-c-fuzzing-asan-opt/dist/bin/js --fuzzing-safe poc.js

Both crash with AddressSanitizer: stack-overflow. The --fuzzing-safe flag is not required for the bug; it only restricts shell APIs and does not enable any non-default feature.

Testcase: poc.js

Crash Signature

ERROR: AddressSanitizer: stack-overflow
#1 CyclicModuleResolveExport(...) js/src/vm/Modules.cpp:978:32
#2 ModuleResolveExportWithResolveSet(...) js/src/vm/Modules.cpp:890:10
#3 CyclicModuleResolveExport(...) js/src/vm/Modules.cpp:1011:16
#4 ModuleResolveExportWithResolveSet(...) js/src/vm/Modules.cpp:890:10
  (repeating)

Suggested Fix

Add an AutoCheckRecursionLimit check at the top of CyclicModuleResolveExport (or at the recursive call site at Modules.cpp:1011) so that deeply nested indirect export resolution is rejected with an InternalError: too much recursion before exhausting the native stack. Alternatively, convert the resolution to an iterative algorithm.

Group: javascript-core-security
Status: NEW → RESOLVED
Closed: 6 months ago
Duplicate of bug: 2042305
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: