memfd_secret hides pages from kernel access, but not from every process with the descriptor
memfd_secret() creates an anonymous RAM-based file whose pages are removed from the kernel's direct map. The mapping is available only to processes that hold the file descriptor. The interface is useful for secrets that must be protected against some memory-disclosure paths, but its security properties depend on how the descriptor, process tree, and crash handling are managed.
The Linux manual page describes the call as creating memory with stronger protection than ordinary anonymous mappings. The kernel itself normally cannot access those pages, so pointers into the region cannot be passed to system calls. Pages are locked in the same way as mlock, and the amount is limited by RLIMIT_MEMLOCK. The file starts at size zero and must be sized with ftruncate() before mapping.
The descriptor is the authority
A child created with fork() inherits a copy of the descriptor and refers to the same secret memory. The descriptor remains across execve() unless it was created with FD_CLOEXEC or explicitly made close-on-exec. A process that receives the descriptor through an unintended path has the same access. The useful policy is to create the region only in the component that needs it, set close-on-exec, limit descriptor inheritance, and close it as soon as the secret is no longer needed.
Debugging paths need a deliberate decision. The manual page notes that a sufficiently privileged kernel-side attack may need to walk page tables or spawn a privileged user-space process. A tracing or profiling configuration that leaves such authority available to unrelated users can reduce the practical value of the isolation. Do not assume that a secret mapping is automatically excluded from every diagnostic tool or crash workflow.
What the API does not provide
memfd_secret does not make a compromised process trustworthy. Code running with the mapping can still read it. It does not provide authentication, access control for the file descriptor beyond normal process and file permissions, or protection from a kernel or hardware attack outside its stated threat model. It also prevents hibernation while an active mapping exists and is subject to memory-locking limits.
The manual page states that the memory is not guaranteed to be inaccessible to the kernel under all circumstances. Product teams should use the call as one hardening layer and continue to minimize plaintext lifetime, restrict core dumps and process inspection, and isolate components that process high-value keys.
Deployment checks
Confirm the kernel supports the call and that the host enables the required facility. Inventory every fork, exec, and descriptor-passing path in the service. Test the close-on-exec flag by running the child with a minimal environment. Check the memory-lock limit and the behavior under memory pressure. Verify that a restart does not leave an old process holding the secret descriptor.
The strongest review question is not whether the system call exists. It is who can still obtain the descriptor or run code in the process. The mapping narrows a category of exposure. Operational ownership decides the rest.
References
[1] Linux manual page, memfd_secret(2). https://man7.org/linux/man-pages/man2/memfd_secret.2.html
[2] Linux manual page, memfd_create(2). https://man7.org/linux/man-pages/man2/memfd_create.2.html

