-
-
Notifications
You must be signed in to change notification settings - Fork 37.2k
crypto.alloc() for encryption key memory management #18896
Copy link
Copy link
Closed
Labels
cryptoIssues and PRs related to the crypto subsystem.Issues and PRs related to the crypto subsystem.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.memoryIssues and PRs related to Node.js memory management or memory footprint.Issues and PRs related to Node.js memory management or memory footprint.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Description
Activity
Metadata
Metadata
Assignees
Labels
cryptoIssues and PRs related to the crypto subsystem.Issues and PRs related to the crypto subsystem.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.memoryIssues and PRs related to Node.js memory management or memory footprint.Issues and PRs related to Node.js memory management or memory footprint.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
@indutny and everyone working on the
cryptomodule:At present, using a
Bufferfor a crypto key exposes the key to core dumps, swapping, and forking. The user also has to remember to erase the key once done. Granted, core dumps and swapping can be disabled system wide, but some libraries such aslibsodiumtake care of this automatically, without the user having to know the fine details.Would you be open to a
crypto.alloc()method to allocate buffers for use as crypto keys and help with crypto memory management, this would:Set the platform equivalents of
MADV_DONTFORK,MADV_DONTDUMP, andmlockas far as possible.Automatically zero buffers at GC time before freeing, along the lines of https://github.com/jedisct1/libsodium/blob/be58b2e6664389d9c7993b55291402934b43b3ca/src/libsodium/sodium/utils.c#L78:L101
Hopefully do guarded heap allocations, but 1 and 2 would be enough for a start.