Assertion failure: !cx->isExceptionPending(), at js/src/vm/Interpreter.cpp:501
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
People
(Reporter: decoder, Assigned: allstars.chh)
Details
(Keywords: ai-involved, sec-audit, testcase)
Attachments
(1 file)
|
3.37 KB,
application/javascript
|
Details |
Summary
js::AsyncModuleExecutionRejected (js/src/vm/Modules.cpp) guards its recursion over a module's [[AsyncParentModules]] with AutoCheckRecursionLimit and returns false when the native-stack limit is hit. The recursion.check(cx) it uses is the reporting variant, so on failure it calls ReportOverRecursed(cx), leaving a pending over-recursion exception on the context.
On the fulfilled-completion path, that false result is consumed by RejectExecutionWithPendingException, which only asserts that the context is throwing over-recursed and returns without clearing the pending exception. The exception then survives until the promise-reaction native AsyncModuleExecutionFulfilledHandler returns true. Returning true from a native while an exception is pending breaks a core engine invariant: the next native dispatched from the microtask queue trips MOZ_ASSERT_IF(!alreadyThrowing, !cx->isExceptionPending()) in CallJSNative.
This is a debug/ASan assertion (a plain MOZ_ASSERT, so opt builds do not abort), but it is a genuine invariant violation: in a release build a stale over-recursion exception leaks back into the job queue. Filed as sec-audit — the security impact beyond the asserted invariant violation is not demonstrated, and the condition is reached only via deep recursion (a resource-exhaustion condition).
Root cause
js/src/vm/Modules.cpp:2599-2605—AsyncModuleExecutionRejecteddoesAutoCheckRecursionLimit recursion(cx); if (!recursion.check(cx)) { return false; }.recursion.check()reports the over-recursion error, i.e. it sets a pending exception, then returnsfalse. Thefalseis propagated up the[[AsyncParentModules]]recursion (js/src/vm/Modules.cpp:2653-2659).js/src/vm/Modules.cpp:2444-2457—RejectExecutionWithPendingExceptionclears any current exception, callsAsyncModuleExecutionRejected, and on failure only doesMOZ_ASSERT(cx->isThrowingOverRecursed());(line 2455). It never callscx->clearPendingException(), so the over-recursion exception set insideAsyncModuleExecutionRejectedstays pending.js/src/vm/AsyncFunction.cpp:288-300—AsyncModuleExecutionFulfilledHandlercallsAsyncModuleExecutionFulfilled(cx, module)(which drives the above) and then unconditionallyargs.rval().setUndefined(); return true;, i.e. it returnstrueto the microtask runner with the exception still pending.js/src/vm/Interpreter.cpp:501—CallJSNativethen tripsMOZ_ASSERT_IF(!alreadyThrowing, !cx->isExceptionPending());on the next native dispatched from the queue.
How the recursion depth is reached
A single moduleLink/moduleEvaluate of a deep import chain is capped early by the guarded InnerModuleLinking recursion. To build a deep [[AsyncParentModules]] chain that AsyncModuleExecutionRejected must walk, the PoC links and evaluates each module individually, bottom-up, while the module it imports is still EvaluatingAsync. Each InnerModuleEvaluation stays shallow, but the async-parent chain ends up N levels deep:
m0 (top-level await) <- m1 (throws) <- m2 <- ... <- m{N-1}
Fulfilling m0 runs AsyncModuleExecutionFulfilled(m0); its step-12 loop executes m1, which throws, and the resulting AsyncModuleExecutionRejected(m1) recurses up the chain until it exceeds the recursion limit.
Reproduction
Testcase: poc.js (attached).
m-c-asan-debug/dist/bin/js --fuzzing-safe poc.js
The assertion fires deterministically. N = 20000 in the PoC is comfortably above the recursion-limit threshold of this build (~6.5k) and well below the depth at which the unguarded GatherAvailableModuleAncestors recursion would itself overflow (~60k), so the failure is reliably the exception-leak assert and not a stack overflow. No non-default prefs are required; the shell builtins (parseModule/registerModule/moduleLink/moduleEvaluate/drainJobQueue) only exercise real module-evaluation paths that are reachable in the browser via deep module graphs with top-level await.
Crash signature (debug ASan shell)
Assertion failure: !cx->isExceptionPending(), at js/src/vm/Interpreter.cpp:501
#0 MOZ_CrashSequence(void*, long)
#1 CallJSNative(JSContext*, bool (*)(...), js::CallReason, JS::CallArgs const&)
#2 js::InternalCallOrConstruct(...)
#3 js::Call(...)
#4 js::Call(...)
#5 PromiseReactionJob(JSContext*, JS::Handle<JSObject*>)
#6 JS::RunJSMicroTask(JSContext*, JS::Handle<JSObject*>)
#7 js::InternalJobQueue::runJobs(JSContext*)
#8 js::RunJobs(JSContext*)
#9 RunShellJobs(JSContext*)
#10 DrainJobQueue(JSContext*, unsigned int, JS::Value*)
Suggested fix
RejectExecutionWithPendingException should clear (and ignore) the pending exception when AsyncModuleExecutionRejected fails, mirroring how the microtask runner handles a rejected-reaction handler's false return:
if (!AsyncModuleExecutionRejected(cx, module, exception)) {
MOZ_ASSERT(cx->isThrowingOverRecursed());
cx->clearPendingException(); // do not leak the over-recursion exception back into the job queue
}
Equivalently, AsyncModuleExecutionRejected could clear the exception itself before returning false, or use the non-reporting checkDontReport so no exception is set.
Related observation
The fulfilled-side counterparts walk the module graph with no recursion guard: GatherAvailableModuleAncestors (js/src/vm/Modules.cpp, around its recursive self-call) and InnerModuleEvaluation. A sufficiently deep bottom-up-built chain overflows the stack there (a separate stack-overflow defect). Adding the missing AutoCheckRecursionLimit guards there is also advisable, but that is distinct from the exception-leak addressed here.
| Reporter | ||
Comment 1•6 months ago
|
||
Comment 2•6 months ago
|
||
NI Yoshi because this is related to overrecursion checks in modules code.
| Assignee | ||
Updated•6 months ago
|
| Assignee | ||
Comment 3•6 months ago
|
||
the same problem in 3. GatherAvailableModuleAncestor from https://bugzilla.mozilla.org/show_bug.cgi?id=2042305#c0
Updated•2 months ago
|
Description
•