Skip to content

ffi: dlclose()/dlsym() check permissions that handle.close()/handle.getSymbol() don't #66425

Description

@trivikr

Version

main

Platform

macOS 26.7.0

Subsystem

ffi

What steps will reproduce the bug?

import ffi from 'node:ffi';

const a = ffi.dlopen(null);
const b = ffi.dlopen(null);
process.permission.drop('ffi');

b.lib.getSymbol('qsort');
console.log('lib.getSymbol(): ok');
b.lib.close();
console.log('lib.close(): ok');

try {
  ffi.dlsym(a.lib, 'qsort');
} catch (err) {
  console.log('ffi.dlsym():', err.code);
}
try {
  ffi.dlclose(a.lib);
} catch (err) {
  console.log('ffi.dlclose():', err.code);
}

Run with

node --no-warnings --permission --allow-ffi repro.js

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

The functions and the methods behave the same.

ffi.dlclose(handle) says

This is equivalent to calling handle.close().

ffi.dlsym(handle, symbol) says

This is equivalent to calling handle.getSymbol(symbol).

What do you see instead?

lib.getSymbol(): ok
lib.close(): ok
ffi.dlsym(): ERR_ACCESS_DENIED
ffi.dlclose(): ERR_ACCESS_DENIED

Additional information

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ffiIssues and PRs related to experimental Foreign Function Interface support.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions