Skip to content

fix: use-after-free of a freed Realm by cppgc wrapper destructors at exit - #54267

Merged
MarshallOfSound merged 1 commit into
45-x-yfrom
trop/45-x-y-bp-fix-use-after-free-of-a-freed-realm-by-cppgc-wrapper-destructors-at-exit-1790209851353
Sep 24, 2026
Merged

MarshallOfSound merged 1 commit into
45-x-yfrom
trop/45-x-y-bp-fix-use-after-free-of-a-freed-realm-by-cppgc-wrapper-destructors-at-exit-1790209851353

Conversation

@trop

@trop trop Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Backport of #53560

See that PR for details.

Notes: Fixed a possible crash during process exit when vm.Script or vm contexts created in the main process had been garbage collected shortly before quitting.

…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]>
@trop
trop Bot requested a review from a team as a code owner September 24, 2026 00:31
@trop
trop Bot requested a review from MarshallOfSound September 24, 2026 00:31
@trop trop Bot added 45-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes labels Sep 24, 2026
@MarshallOfSound
MarshallOfSound enabled auto-merge (squash) September 24, 2026 00:36
@MarshallOfSound
MarshallOfSound merged commit a160771 into 45-x-y Sep 24, 2026
96 checks passed
@MarshallOfSound
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-clerk

release-clerk Bot commented Sep 24, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed a possible crash during process exit when vm.Script or vm contexts created in the main process had been garbage collected shortly before quitting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

45-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant