Assertion failure: !cx->isExceptionPending() || cx->isThrowingOutOfMemory() || cx->isThrowingOverRecursed() in [@ js::AsyncModuleExecutionFulfilled] via Debugger onStep forced throw during top-level-await module execution
Categories
(Core :: JavaScript: Debugger API, defect, P3)
Tracking
()
People
(Reporter: bugmon, Unassigned)
References
(Blocks 2 open bugs)
Details
(5 keywords)
Attachments
(3 files)
|
1.01 KB,
text/plain
|
Details | |
|
963 bytes,
patch
|
Details | Diff | Splinter Review | |
|
5.09 KB,
text/plain
|
Details |
js::AsyncModuleExecutionFulfilled (js/src/vm/Modules.cpp) runs when an async (top-level-await) module's execution promise fulfills. In step 12.b, for each gathered ancestor module m with top-level await, it calls ExecuteAsyncModule(cx, m); on failure it asserts that the only possible pending exception is an out-of-memory or over-recursion error and then unconditionally clears the pending exception, instead of rejecting the module's evaluation with the pending exception as the spec (AsyncModuleExecutionRejected, step 12.b error path) requires.
That assumption is wrong: ExecuteAsyncModule synchronously executes the module body up to its first await, and arbitrary JS-visible exceptions can be raised during that synchronous prefix. The testcase attaches a Debugger to the global and uses a Debugger.Frame onStep handler that returns a { throw: ... } resumption value while the parent module's body is executing. When the awaited child module fulfills, AsyncModuleExecutionFulfilled(child) gathers the parent as an available ancestor and calls ExecuteAsyncModule(parent); the debugger-injected throw makes it fail with a pending exception that is neither OOM nor over-recursion, firing the MOZ_ASSERT in debug builds.
In release builds the code silently clears an arbitrary exception and leaves the parent module stranded in EvaluatingAsync state: its status never transitions to Evaluated, its evaluation error is never recorded, and its top-level capability promise is never settled. This desynchronizes the cyclic-module-record state machine, a security-sensitive engine invariant violation that downstream code (e.g. subsequent evaluation, GatherAvailableModuleAncestors, or promise settlement paths) relies on.
Build Info
- Branch: main
- Revision: d4a2cc2aa48ba5e56ce90680e90038843a7298c7
- Timestamp: 2026-07-01T00:30:50+00:00
Affected Code
File: js/src/vm/Modules.cpp, line 2582-2590
} else if (m->hasTopLevelAwait()) {
// Step 12.b. Else if m.[[HasTLA]] is true, then:
// Step 12.b.i. Perform ExecuteAsyncModule(m).
if (!ExecuteAsyncModule(cx, m)) {
MOZ_ASSERT(!cx->isExceptionPending() || cx->isThrowingOutOfMemory() ||
cx->isThrowingOverRecursed()); // <-- fires: debugger-injected exception is neither
cx->clearPendingException(); // <-- release builds: arbitrary exception swallowed,
} // module m stuck in EvaluatingAsync, never rejected
} else {
File: js/src/vm/Modules.cpp, line 2474-2488
// The correct handling (used elsewhere in this file and upstream for step 12.b):
static void RejectExecutionWithPendingException(JSContext* cx,
Handle<ModuleObject*> module) {
// If there is no exception pending then we have been interrupted or
// over-recursed and there is no exception to propagate.
Rooted<Value> exception(cx);
if (cx->isExceptionPending()) {
(void)cx->getPendingException(&exception);
cx->clearPendingException();
}
if (!AsyncModuleExecutionRejected(cx, module, exception)) {
MOZ_ASSERT(cx->isThrowingOverRecursed());
cx->clearPendingException();
}
}
The failure path for ExecuteAsyncModule in step 12.b of AsyncModuleExecutionFulfilled asserts an impossible-to-guarantee invariant (only OOM/over-recursion exceptions) and swallows the exception. Upstream mozilla-central instead calls RejectExecutionWithPendingException(cx, m) here, which forwards the error to AsyncModuleExecutionRejected. A Debugger onStep handler returning a throw resumption value during the module body's synchronous prefix produces an arbitrary pending exception on this path.
Exploit Chain
- Create a debuggee global (newGlobal) and attach a Debugger with an onEnterFrame hook that installs a Debugger.Frame onStep handler.
- In the debuggee, parse and register a top-level-await child module ('await new Promise(r => { globalThis.__pc = r; }); export let cv = 10;') and a parent module that imports it and also contains top-level await.
- moduleLink(parent) and moduleEvaluate(parent): child begins executing and suspends at its await; parent is a pending async ancestor of child (pendingAsyncDependencies reaches 0 only when child fulfills).
- Arm the onStep handler so that after a few steps in parent.js it returns the resumption value { throw: 'boom-from-debugger' }.
- Resolve the child's awaited promise (__pc(1)) and drain the job queue: the child's async-function promise fulfills, invoking AsyncModuleExecutionFulfilledHandler -> js::AsyncModuleExecutionFulfilled(child).
- GatherAvailableModuleAncestors collects the parent module; step 12.b calls ExecuteAsyncModule(parent), which synchronously executes parent.js up to its first await.
- The armed onStep handler forces a throw during that synchronous prefix; ExecuteAsyncModule returns false with the debugger-injected exception pending.
- MOZ_ASSERT(!cx->isExceptionPending() || OOM || over-recursed) fails -> controlled crash in debug builds. In release builds the exception is silently cleared and the parent module is left permanently in EvaluatingAsync with an unsettled top-level capability, violating the module state-machine invariant.
Steps to Reproduce
- Build the SpiderMonkey debug shell: build_firefox(firefox_dir=/firefox, mozconfig_path=/app/mozconfigs/mozconfig.js.linux.debug) -> build_dir /firefox/obj-js-debug
- Run the testcase via js_shell_evaluator with js_binary=/firefox/obj-js-debug/dist/bin/js (the tool runs with --fuzzing-safe): the testcase from /tmp/tmpz7ie8ly8/testcase.js (Debugger onStep forced-throw over a parent/child top-level-await module pair, then resolve the child's promise and drainJobQueue).
- Observe: 'Assertion failure: !cx->isExceptionPending() || cx->isThrowingOutOfMemory() || cx->isThrowingOverRecursed(), at js/src/vm/Modules.cpp:2588' followed by UBSan SEGV report in js::AsyncModuleExecutionFulfilled.
Security Impact
- Severity: Moderate
- Attacker capability: Script (with a Debugger attached to the executing global, e.g. DevTools-privileged contexts or the JS shell) can violate the cyclic-module-record state-machine invariant: an arbitrary exception raised while an async module's dependent starts executing is asserted away. Debug builds crash deterministically (DoS / fuzzing blocker). In release builds the exception is silently swallowed and the module is left permanently in EvaluatingAsync with an unsettled top-level capability promise, corrupting engine module state that downstream code assumes consistent; no memory corruption was demonstrated.
- Preconditions: Requires driving module evaluation of top-level-await modules while a Debugger onStep/onEnterFrame hook can force a throw resumption during module execution (JS shell with parseModule/moduleEvaluate and Debugger, or privileged/DevTools debugger contexts in the browser). Reproduces in the fuzzing-safe shell with no special flags.
ASAN Report
[33430] Assertion failure: !cx->isExceptionPending() || cx->isThrowingOutOfMemory() || cx->isThrowingOverRecursed(), at js/src/vm/Modules.cpp:2588
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==33430==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x55f5a0a76082 bp 0x7fffd8b6a4a0 sp 0x7fffd8b6a3c0 T33430)
==33430==The signal is caused by a WRITE memory access.
==33430==Hint: address points to the zero page.
#0 0x55f5a0a76082 in MOZ_CrashSequence(void*, long) /firefox/obj-js-debug/dist/include/mozilla/Assertions.h:261:3
#1 0x55f5a0a76082 in js::AsyncModuleExecutionFulfilled(JSContext*, JS::Handle<js::ModuleObject*>) /firefox/obj-js-debug/js/src/vm/./../../../../js/src/vm/Modules.cpp:2587:9
#2 0x55f5a06ca045 in AsyncModuleExecutionFulfilledHandler(JSContext*, unsigned int, JS::Value*) /firefox/obj-js-debug/js/src/vm/./../../../../js/src/vm/AsyncFunction.cpp:297:3
#3 0x55f5a067a634 in CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&) /firefox/js/src/vm/Interpreter.cpp:498:13
#4 0x55f5a0655855 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /firefox/js/src/vm/Interpreter.cpp:594:12
#5 0x55f5a065673c in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) /firefox/js/src/vm/Interpreter.cpp:693:8
#6 0x55f59f30bb91 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, JS::Handle<JS::Value>, JS::MutableHandle<JS::Value>) /firefox/js/src/vm/Interpreter.h:118:10
#7 0x55f59f3b4989 in PromiseReactionJob(JSContext*, JS::Handle<JSObject*>) /firefox/obj-js-debug/js/src/builtin/./../../../../js/src/builtin/Promise.cpp:2723:10
#8 0x55f59f3b4989 in JS::RunJSMicroTask(JSContext*, JS::Handle<JSObject*>) /firefox/obj-js-debug/js/src/builtin/./../../../../js/src/builtin/Promise.cpp:8502:12
#9 0x55f5a09c56ba in js::InternalJobQueue::runJobs(JSContext*) /firefox/obj-js-debug/js/src/vm/./../../../../js/src/vm/JSContext.cpp:896:14
#10 0x55f5a09c5133 in js::RunJobs(JSContext*) /firefox/obj-js-debug/js/src/vm/./../../../../js/src/vm/JSContext.cpp:837:17
#11 0x55f59f18cd27 in RunShellJobs(JSContext*) /firefox/obj-js-debug/js/src/shell/./../../../../js/src/shell/js.cpp:1496:5
#12 0x55f59f18426d in DrainJobQueue(JSContext*, unsigned int, JS::Value*) /firefox/obj-js-debug/js/src/shell/./../../../../js/src/shell/js.cpp:1525:3
#13 0x55f5a067a634 in CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&) /firefox/js/src/vm/Interpreter.cpp:498:13
#14 0x55f5a0655855 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /firefox/js/src/vm/Interpreter.cpp:594:12
#15 0x55f5a06656c7 in js::CallFromStack(JSContext*, JS::CallArgs const&, js::CallReason) /firefox/js/src/vm/Interpreter.cpp:666:10
#16 0x55f5a06656c7 in js::Interpret(JSContext*, js::RunState&) /firefox/js/src/vm/Interpreter.cpp:3280:16
#17 0x55f5a06552a6 in MaybeEnterInterpreterTrampoline(JSContext*, js::RunState&) /firefox/js/src/vm/Interpreter.cpp:392:10
#18 0x55f5a0654eea in js::RunScript(JSContext*, js::RunState&) /firefox/js/src/vm/Interpreter.cpp:468:13
#19 0x55f5a0657d30 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, js::AbstractFramePtr, JS::MutableHandle<JS::Value>) /firefox/js/src/vm/Interpreter.cpp:858:10
#20 0x55f5a065818e in js::Execute(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, JS::MutableHandle<JS::Value>) /firefox/js/src/vm/Interpreter.cpp:888:10
#21 0x55f5a0917931 in ExecuteScript(JSContext*, JS::Handle<JSObject*>, JS::Handle<JSScript*>, JS::MutableHandle<JS::Value>) /firefox/obj-js-debug/js/src/vm/./../../../../js/src/vm/CompilationAndEvaluation.cpp:544:10
#22 0x55f5a0917b18 in JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>) /firefox/obj-js-debug/js/src/vm/./../../../../js/src/vm/CompilationAndEvaluation.cpp:568:10
#23 0x55f59f19f06d in RunFile(JSContext*, char const*, _IO_FILE*, CompileUtf8, bool, bool) /firefox/obj-js-debug/js/src/shell/./../../../../js/src/shell/js.cpp:1412:10
#24 0x55f59f19e58b in Process(JSContext*, char const*, bool, FileKind) /firefox/obj-js-debug/js/src/shell/./../../../../js/src/shell/js.cpp
#25 0x55f59f1579db in ProcessArgs(JSContext*, js::cli::OptionParser*) /firefox/obj-js-debug/js/src/shell/./../../../../js/src/shell/js.cpp:12137:10
#26 0x55f59f1579db in Shell(JSContext*, js::cli::OptionParser*) /firefox/obj-js-debug/js/src/shell/./../../../../js/src/shell/js.cpp:12389:12
#27 0x55f59f14fef3 in main /firefox/obj-js-debug/js/src/shell/./../../../../js/src/shell/js.cpp:12801:12
SUMMARY: UndefinedBehaviorSanitizer: SEGV /firefox/obj-js-debug/dist/include/mozilla/Assertions.h:261:3 in MOZ_CrashSequence(void*, long)
==33430==ABORTING
| Reporter | ||
Comment 1•4 months ago
|
||
| Reporter | ||
Comment 2•4 months ago
|
||
| Reporter | ||
Comment 3•4 months ago
|
||
| Reporter | ||
Comment 4•4 months ago
|
||
| Reporter | ||
Comment 5•4 months ago
|
||
| Reporter | ||
Comment 6•4 months ago
|
||
| Reporter | ||
Comment 7•4 months ago
|
||
Updated•4 months ago
|
Updated•4 months ago
|
Comment 9•2 months ago
|
||
Fixed by bug 2042756.
Updated•1 month ago
|
Description
•