Skip to content

ffi: reject fast calls after library close - #64860

Open
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:ffi-closed-lib-cal-sigsegv-3
Open

ffi: reject fast calls after library close#64860
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:ffi-closed-lib-cal-sigsegv-3

Conversation

@trivikr

@trivikr trivikr commented Jul 31, 2026

Copy link
Copy Markdown
Member

Fixes: #64854

Optimized FFI Fast API calls bypass DynamicLibrary::InvokeFunction() and enter the generated trampoline directly. After DynamicLibrary::close() unloads the library, optimized code could call the stale symbol address and crash with SIGSEGV.

This adds a closed-state check to the AArch64 and SysV x64 fast trampolines. The hot path continues to the native symbol when the library is open. The cold path schedules ERR_FFI_LIBRARY_CLOSED and returns without entering the unloaded library.


Assisted-by: codex:gpt-5.6-sol

@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++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jul 31, 2026
Optimized Fast API calls bypass InvokeFunction and can jump directly to
a symbol after DynamicLibrary::close() unloads its library.

Check the function's closed state in the AArch64 and SysV x64
trampolines before entering the target. If the library is closed,
schedule ERR_FFI_LIBRARY_CLOSED and return without calling the symbol.

Keep the JavaScript guard on platforms without a native trampoline guard
and for signatures that already require argument conversion or
validation. This keeps raw scalar fast calls close to their original
performance on supported platforms.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: codex:gpt-5.6-sol
@trivikr
trivikr force-pushed the ffi-closed-lib-cal-sigsegv-3 branch from 8e91308 to 3b1b100 Compare July 31, 2026 04:27
@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 31, 2026
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.69892% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.16%. Comparing base (c8e2a82) to head (3b1b100).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/ffi/platforms/arm64.cc 89.47% 0 Missing and 2 partials ⚠️
lib/internal/ffi/fast-api.js 96.96% 1 Missing ⚠️
src/ffi/fast.cc 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #64860   +/-   ##
=======================================
  Coverage   90.16%   90.16%           
=======================================
  Files         746      746           
  Lines      242760   242845   +85     
  Branches    45765    45774    +9     
=======================================
+ Hits       218875   218972   +97     
+ Misses      15375    15355   -20     
- Partials     8510     8518    +8     
Files with missing lines Coverage Δ
lib/ffi.js 95.23% <100.00%> (+0.31%) ⬆️
lib/internal/errors.js 97.90% <100.00%> (+<0.01%) ⬆️
src/ffi/fast.h 100.00% <100.00%> (ø)
src/node_ffi.cc 70.45% <100.00%> (-0.18%) ⬇️
lib/internal/ffi/fast-api.js 92.32% <96.96%> (+1.25%) ⬆️
src/ffi/fast.cc 68.91% <91.66%> (+1.15%) ⬆️
src/ffi/platforms/arm64.cc 85.40% <89.47%> (+0.88%) ⬆️

... and 29 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.

@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 31, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ffi: closed library still callable via fast path, SIGSEGV instead of ERR_FFI_LIBRARY_CLOSED

3 participants