Skip to content

vfs: keep each loaded memfd image open until exit - #67068

Open
pipobscure wants to merge 1 commit into
nodejs:mainfrom
pipobscure:vfs-addon-memfd
Open

pipobscure wants to merge 1 commit into
nodejs:mainfrom
pipobscure:vfs-addon-memfd

Conversation

@pipobscure

Copy link
Copy Markdown
Contributor

On Linux an addon or FFI library inside a VFS is loaded from an anonymous memfd through /proc/self/fd/N, and the memfd was closed right after a successful load. The next image then got the same fd number, hence the same path, and the dynamic loader, which knows a loaded object by the path it was opened with, returned the object already loaded under that path instead of loading the new file. So the second of any two addons or libraries loaded from a VFS resolved to the first: an addon after an FFI library failed with "Module did not self-register", an FFI library after an addon had none of its own symbols, and two addons silently became the same one.

Keep a memfd open for the life of the process once it has been loaded, so no two images ever share a path; MFD_CLOEXEC keeps it out of child processes. A failed load still closes its memfd. The temp-file fallback is unaffected: each image there gets a fresh mkdtemp() directory, and Windows already keeps its images until exit.

On Linux an addon or FFI library inside a VFS is loaded from an
anonymous memfd through /proc/self/fd/N, and the memfd was closed
right after a successful load. The next image then got the same fd
number, hence the same path, and the dynamic loader, which knows a
loaded object by the path it was opened with, returned the object
already loaded under that path instead of loading the new file. So
the second of any two addons or libraries loaded from a VFS resolved
to the first: an addon after an FFI library failed with "Module did
not self-register", an FFI library after an addon had none of its
own symbols, and two addons silently became the same one.

Keep a memfd open for the life of the process once it has been
loaded, so no two images ever share a path; MFD_CLOEXEC keeps it out
of child processes. A failed load still closes its memfd. The
temp-file fallback is unaffected: each image there gets a fresh
mkdtemp() directory, and Windows already keeps its images until exit.

Signed-off-by: Philipp Dunkel <pip@pipobscure.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/ffi

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Oct 27, 2026
@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (98dbf60) to head (a839799).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67068      +/-   ##
==========================================
- Coverage   90.65%   90.65%   -0.01%     
==========================================
  Files         797      797              
  Lines      278268   278320      +52     
  Branches    53517    53535      +18     
==========================================
+ Hits       252261   252305      +44     
- Misses      16386    16397      +11     
+ Partials     9621     9618       -3     
Files with missing lines Coverage Δ
src/node_binding.cc 70.79% <100.00%> (ø)
src/node_binding.h 80.00% <ø> (ø)

... and 30 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pipobscure

Copy link
Copy Markdown
Contributor Author

@mcollina @jasnell @trivikr can one of you give this a request-ci and a review please

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants