Repository navigation
fix: use-after-free of a freed Realm by cppgc wrapper destructors at exit - #54267
Merged
Conversation
…exit Cherry-picks nodejs/node#65778 (landed upstream as nodejs/node@c909c63be3). Realm::RunCleanup() detaches the cppgc wrappers it tracks (vm.Script, vm contexts) through weak persistents, which the GC clears as soon as it finds a wrapper unreachable. With lazy/concurrent sweeping the wrapper's destructor can run much later, so one collected shortly before FreeEnvironment() and swept after it kept its Realm pointer, and ~CppgcMixin() wrote into the freed Realm. In Electron this showed up as an ASan heap-use-after-free in ~ContextifyScript during JavascriptEnvironment teardown at process exit. The Realm pointer now lives in the off-heap list node, which cleanup clears for every entry, so a late destructor sees no Realm instead of a freed one. Co-authored-by: Sam Attard <[email protected]>
2 tasks done
MarshallOfSound
approved these changes
Sep 24, 2026
MarshallOfSound
enabled auto-merge (squash)
September 24, 2026 00:36
MarshallOfSound
deleted the
trop/45-x-y-bp-fix-use-after-free-of-a-freed-realm-by-cppgc-wrapper-destructors-at-exit-1790209851353
branch
September 24, 2026 03:07
|
Release Notes Persisted
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #53560
See that PR for details.
Notes: Fixed a possible crash during process exit when
vm.Scriptorvmcontexts created in the main process had been garbage collected shortly before quitting.