[PATCH v2 19/25] linux: Add memfd_secret
Adhemerval Zanella
adhemerval.zanella@linaro.org
Tue Nov 10 15:10:03 GMT 2026
The memfd_secret system call (commit
1507f51255c9ff07d75909a84e7c0d7f3c4b2f49, Linux 5.14) creates a memory
file descriptor whose memory is only accessible to the processes which
map it (with MAP_SHARED). It is enabled by default since Linux 6.5.
int memfd_secret (unsigned int flags);
The only accepted flag is O_CLOEXEC.
The system call is only wired up for the architectures which support
removing pages from the direct map (currently aarch64, i386, loongarch,
riscv, s390, and x86_64). The wrapper fails with ENOSYS on archictures
that do not provided the syscall.
There is no widespread C user yet: the kernel selftests call it through
syscall, and Go provides a raw system call binding in
golang.org/x/sys/unix (MemfdSecret).
Checked on x86_64-linux-gnu.
---
NEWS | 4 ++
manual/llio.texi | 48 +++++++++++++
sysdeps/unix/sysv/linux/Makefile | 2 +
sysdeps/unix/sysv/linux/Versions | 1 +
sysdeps/unix/sysv/linux/aarch64/libc.abilist | 1 +
sysdeps/unix/sysv/linux/alpha/libc.abilist | 1 +
sysdeps/unix/sysv/linux/arc/libc.abilist | 1 +
sysdeps/unix/sysv/linux/arm/be/libc.abilist | 1 +
sysdeps/unix/sysv/linux/arm/le/libc.abilist | 1 +
sysdeps/unix/sysv/linux/bits/mman-shared.h | 5 ++
sysdeps/unix/sysv/linux/csky/libc.abilist | 1 +
sysdeps/unix/sysv/linux/hppa/libc.abilist | 1 +
sysdeps/unix/sysv/linux/i386/libc.abilist | 1 +
.../sysv/linux/loongarch/ilp32/libc.abilist | 1 +
.../sysv/linux/loongarch/lp64/libc.abilist | 1 +
.../sysv/linux/m68k/coldfire/libc.abilist | 1 +
.../unix/sysv/linux/m68k/m680x0/libc.abilist | 1 +
sysdeps/unix/sysv/linux/memfd_secret.c | 34 ++++++++++
.../sysv/linux/microblaze/be/libc.abilist | 1 +
.../sysv/linux/microblaze/le/libc.abilist | 1 +
.../sysv/linux/mips/mips32/fpu/libc.abilist | 1 +
.../sysv/linux/mips/mips32/nofpu/libc.abilist | 1 +
.../sysv/linux/mips/mips64/n32/libc.abilist | 1 +
.../sysv/linux/mips/mips64/n64/libc.abilist | 1 +
sysdeps/unix/sysv/linux/or1k/libc.abilist | 1 +
.../linux/powerpc/powerpc32/fpu/libc.abilist | 1 +
.../powerpc/powerpc32/nofpu/libc.abilist | 1 +
.../linux/powerpc/powerpc64/be/libc.abilist | 1 +
.../linux/powerpc/powerpc64/le/libc.abilist | 1 +
.../unix/sysv/linux/riscv/rv32/libc.abilist | 1 +
.../unix/sysv/linux/riscv/rv64/libc.abilist | 1 +
sysdeps/unix/sysv/linux/s390/libc.abilist | 1 +
sysdeps/unix/sysv/linux/sh/be/libc.abilist | 1 +
sysdeps/unix/sysv/linux/sh/le/libc.abilist | 1 +
.../sysv/linux/sparc/sparc32/libc.abilist | 1 +
.../sysv/linux/sparc/sparc64/libc.abilist | 1 +
sysdeps/unix/sysv/linux/tst-memfd_secret.c | 67 +++++++++++++++++++
.../unix/sysv/linux/x86_64/64/libc.abilist | 1 +
.../unix/sysv/linux/x86_64/x32/libc.abilist | 1 +
39 files changed, 193 insertions(+)
create mode 100644 sysdeps/unix/sysv/linux/memfd_secret.c
create mode 100644 sysdeps/unix/sysv/linux/tst-memfd_secret.c
diff --git a/NEWS b/NEWS
index 3e200976212..7c34fde99e9 100644
--- a/NEWS
+++ b/NEWS
@@ -44,6 +44,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
diff --git a/manual/llio.texi b/manual/llio.texi
index 90c6a53da74..2b078131c63 100644
--- a/manual/llio.texi
+++ b/manual/llio.texi
@@ -2363,6 +2363,54 @@ There is not enough memory for the operation.
@end table
@end deftypefun
+@deftypefun int memfd_secret (unsigned int @var{flags})
+@standards{Linux, sys/mman.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{@acsfd{}}}
+The @code{memfd_secret} function returns a file descriptor for secret
+memory, which can only be accessed through memory mappings of that
+descriptor. The kernel removes the pages backing it from its own page
+tables, so only the processes which map the descriptor can access the
+memory, and other processes and the kernel itself cannot.
+
+The descriptor initially refers to a zero-length file. The file size
+needs to be set with the @code{ftruncate} function before the memory can
+be accessed, and it cannot be changed afterwards. @xref{File Size}.
+The mappings must be created with
+@code{MAP_SHARED}, and they are not included in core dumps. The
+descriptor does not support the @code{read} and @code{write} functions.
+
+The secret memory counts towards the @code{RLIMIT_MEMLOCK} resource
+limit (@pxref{Limits on Resources}), and while it is in use the system
+cannot hibernate.
+
+The @var{flags} argument is either zero or @code{O_CLOEXEC}, which
+creates the descriptor with the close-on-exec flag set.
+
+@code{memfd_secret} returns a file descriptor on success, and @math{-1}
+on failure.
+
+The following @code{errno} error conditions are defined for this
+function:
+
+@table @code
+@item EINVAL
+The @var{flags} argument contains a flag other than @code{O_CLOEXEC}.
+
+@item ENOSYS
+Secret memory is not supported: the architecture does not provide it,
+or it was disabled when the system was booted.
+
+@item EMFILE
+The operation would exceed the file descriptor limit for this process.
+
+@item ENFILE
+The operation would exceed the system-wide file descriptor limit.
+
+@item ENOMEM
+There is not enough memory for the operation.
+@end table
+@end deftypefun
+
@node Waiting for I/O
@section Waiting for Input or Output
@cindex waiting for input or output
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index cbf1ee2d54e..d469462b998 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -81,6 +81,7 @@ sysdep_routines += \
inotify_init \
lxstat \
lxstat64 \
+ memfd_secret \
mlock2 \
mremap \
open_by_handle_at \
@@ -216,6 +217,7 @@ tests += \
tst-linux-mremap1 \
tst-membarrier \
tst-memfd_create \
+ tst-memfd_secret \
tst-misalign-clone \
tst-mlock2 \
tst-mount \
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index 540f4176518..108dd5c7051 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -351,6 +351,7 @@ libc {
listmount;
listxattrat;
membarrier;
+ memfd_secret;
open_tree_attr;
quotactl_fd;
removexattrat;
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
index edd6bf6727a..c493497096b 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist
index 53e4c941913..e34460e0c86 100644
--- a/sysdeps/unix/sysv/linux/alpha/libc.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/arc/libc.abilist b/sysdeps/unix/sysv/linux/arc/libc.abilist
index 239f4aba5b9..2b5d13aa865 100644
--- a/sysdeps/unix/sysv/linux/arc/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arc/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/arm/be/libc.abilist b/sysdeps/unix/sysv/linux/arm/be/libc.abilist
index 1b8bb2d3e82..9a74c61989d 100644
--- a/sysdeps/unix/sysv/linux/arm/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/be/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/arm/le/libc.abilist b/sysdeps/unix/sysv/linux/arm/le/libc.abilist
index 217edd14603..5972b66f721 100644
--- a/sysdeps/unix/sysv/linux/arm/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/le/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/bits/mman-shared.h b/sysdeps/unix/sysv/linux/bits/mman-shared.h
index ec75015e599..d1dd1a42819 100644
--- a/sysdeps/unix/sysv/linux/bits/mman-shared.h
+++ b/sysdeps/unix/sysv/linux/bits/mman-shared.h
@@ -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
diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist
index 13be3be06a1..1d78d78d613 100644
--- a/sysdeps/unix/sysv/linux/csky/libc.abilist
+++ b/sysdeps/unix/sysv/linux/csky/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist
index 9debda86178..20fe2a088cb 100644
--- a/sysdeps/unix/sysv/linux/hppa/libc.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist
index f0f5c3ff26c..586b61f85ea 100644
--- a/sysdeps/unix/sysv/linux/i386/libc.abilist
+++ b/sysdeps/unix/sysv/linux/i386/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/loongarch/ilp32/libc.abilist b/sysdeps/unix/sysv/linux/loongarch/ilp32/libc.abilist
index 71d25f335db..3031d0b4bb4 100644
--- a/sysdeps/unix/sysv/linux/loongarch/ilp32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/loongarch/ilp32/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist b/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist
index 452d22c079b..01430d7f5b8 100644
--- a/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
index eeb4fa02557..737cb0f4770 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
index a489b52a31a..27647e8c717 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/memfd_secret.c b/sysdeps/unix/sysv/linux/memfd_secret.c
new file mode 100644
index 00000000000..d2266225292
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/memfd_secret.c
@@ -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
+}
diff --git a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist
index f0f9fdbc9d5..c28caa5d997 100644
--- a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist
index 32d02d624bc..a8e433be31d 100644
--- a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
index 59309304baa..fb565485dcf 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
index c712f4363cc..0cd70c5cdd7 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
index 6e840a7e709..f3725c2db8a 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
index cfebec2aecc..8cfd4c4d271 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/or1k/libc.abilist b/sysdeps/unix/sysv/linux/or1k/libc.abilist
index 0b18fcde124..461544fa4a2 100644
--- a/sysdeps/unix/sysv/linux/or1k/libc.abilist
+++ b/sysdeps/unix/sysv/linux/or1k/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
index a4bab8d8aa5..ab941e04d64 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
index b70679a6c31..767c6c10f4f 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
index f68f241ddbc..adaa4f97503 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
index a18c22242df..395fdd45221 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist
index 51f239768a1..76dc8d4b355 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
index 6b2cbe0c2ad..789541d9942 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/s390/libc.abilist b/sysdeps/unix/sysv/linux/s390/libc.abilist
index 05140894570..30771601ba5 100644
--- a/sysdeps/unix/sysv/linux/s390/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/sh/be/libc.abilist b/sysdeps/unix/sysv/linux/sh/be/libc.abilist
index 57260232fc1..e809c8ece03 100644
--- a/sysdeps/unix/sysv/linux/sh/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/be/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/sh/le/libc.abilist b/sysdeps/unix/sysv/linux/sh/le/libc.abilist
index 1937d539834..c19d32c5d8d 100644
--- a/sysdeps/unix/sysv/linux/sh/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/le/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
index e9a0bfb406b..61ac84f3bc9 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
index 54a19c3dd90..a37d390e9ce 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/tst-memfd_secret.c b/sysdeps/unix/sysv/linux/tst-memfd_secret.c
new file mode 100644
index 00000000000..c130365381d
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-memfd_secret.c
@@ -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>
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
index 4c2ecc94673..7279964900b 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
index 166e6e1e782..f99ee146c71 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
@@ -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
--
2.53.0
More information about the Libc-alpha
mailing list