@@ -43,6 +43,10 @@ Major new features:
open file, so it can be used for filesystems without a backing block
device such as tmpfs.
+* On Linux, the memfd_secret function has been added to <sys/mman.h>. It
+ creates a memory file descriptor whose memory is only accessible to the
+ processes which map it, and is removed from the kernel direct map.
+
Deprecated and removed features, and other changes affecting compatibility:
* The posix_spawn_file_actions_addchdir and posix_spawn_file_actions_addfchdir
@@ -81,6 +81,7 @@ sysdep_routines += \
inotify_init \
lxstat \
lxstat64 \
+ memfd_secret \
mlock2 \
mremap \
open_by_handle_at \
@@ -214,6 +215,7 @@ tests += \
tst-linux-mremap1 \
tst-membarrier \
tst-memfd_create \
+ tst-memfd_secret \
tst-misalign-clone \
tst-mlock2 \
tst-mount \
@@ -351,6 +351,7 @@ libc {
listmount;
listxattrat;
membarrier;
+ memfd_secret;
open_tree_attr;
quotactl_fd;
removexattrat;
@@ -2782,6 +2782,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -3129,6 +3129,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2543,6 +2543,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2835,6 +2835,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2832,6 +2832,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -53,6 +53,11 @@ __BEGIN_DECLS
FLAGS is a combination of the MFD_* constants. */
int memfd_create (const char *__name, unsigned int __flags) __THROW;
+/* Create a new memory file descriptor whose memory is only accessible to
+ the processes which map it, and is removed from the kernel direct map.
+ FLAGS is zero or O_CLOEXEC. */
+int memfd_secret (unsigned int __flags) __THROW;
+
/* Lock pages from ADDR (inclusive) to ADDR + LENGTH (exclusive) into
memory. FLAGS is a combination of the MLOCK_* flags above. */
int mlock2 (const void *__addr, size_t __length, unsigned int __flags) __THROW
@@ -2819,6 +2819,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2856,6 +2856,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -3039,6 +3039,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2294,6 +2294,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2303,6 +2303,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2815,6 +2815,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2982,6 +2982,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
new file mode 100644
@@ -0,0 +1,34 @@
+/* Create a file descriptor for secret memory. Linux implementation.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <sys/mman.h>
+#include <sysdep.h>
+
+int
+memfd_secret (unsigned int flags)
+{
+ /* The system call is only defined for the architectures which support
+ removing pages from the kernel direct map. */
+#ifdef __NR_memfd_secret
+ return INLINE_SYSCALL_CALL (memfd_secret, flags);
+#else
+ __set_errno (ENOSYS);
+ return -1;
+#endif
+}
@@ -2868,6 +2868,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2865,6 +2865,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2945,6 +2945,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2943,6 +2943,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2951,6 +2951,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2853,6 +2853,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2293,6 +2293,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -3172,6 +3172,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -3217,6 +3217,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2926,6 +2926,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -3002,6 +3002,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2546,6 +2546,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2746,6 +2746,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2963,6 +2963,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2862,6 +2862,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2859,6 +2859,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -3193,6 +3193,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2829,6 +2829,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
new file mode 100644
@@ -0,0 +1,67 @@
+/* Basic tests for Linux memfd_secret.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <support/check.h>
+#include <support/xunistd.h>
+
+static int
+do_test (void)
+{
+ int fd = memfd_secret (0);
+ if (fd == -1 && errno == ENOSYS)
+ FAIL_UNSUPPORTED ("memfd_secret is not supported by the system");
+ TEST_VERIFY_EXIT (fd != -1);
+
+ long int pagesize = sysconf (_SC_PAGESIZE);
+ xftruncate (fd, pagesize);
+ char *p = xmmap (NULL, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd);
+ static const char secret[] = "secret";
+ memcpy (p, secret, sizeof (secret));
+ TEST_COMPARE_STRING (p, secret);
+
+ /* The memory can only be accessed through a shared mapping. */
+ {
+ char buf[sizeof (secret)];
+ TEST_COMPARE (read (fd, buf, sizeof (buf)), -1);
+ TEST_COMPARE (errno, EINVAL);
+ }
+ TEST_VERIFY (mmap (NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd,
+ 0) == MAP_FAILED);
+ TEST_COMPARE (errno, EINVAL);
+
+ xmunmap (p, pagesize);
+ xclose (fd);
+
+ fd = memfd_secret (O_CLOEXEC);
+ TEST_VERIFY_EXIT (fd != -1);
+ TEST_COMPARE (fcntl (fd, F_GETFD), FD_CLOEXEC);
+ xclose (fd);
+
+ /* O_CLOEXEC is the only supported flag. */
+ TEST_COMPARE (memfd_secret (O_NONBLOCK), -1);
+ TEST_COMPARE (errno, EINVAL);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
@@ -2778,6 +2778,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F
@@ -2797,6 +2797,7 @@ GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
GLIBC_2.45 membarrier F
+GLIBC_2.45 memfd_secret F
GLIBC_2.45 open_tree_attr F
GLIBC_2.45 posix_spawn_file_actions_addchdir F
GLIBC_2.45 posix_spawn_file_actions_addfchdir F