[PATCH RFC POC 20/50] file: warn when the descriptor table is unshared with slots
flat view
COLD27d
From: Christian Brauner <brauner@kernel.org>
Date: 2026-09-15 11:34:05
Also in:
bpf, dri-devel, io-uring, kexec, kvm, linux-alpha, linux-arm-kernel, linux-arm-msm, linux-fsdevel, linux-gpio, linux-hyperv, linux-m68k, linux-mips, linux-mm, linux-sh, linux-um, linuxppc-dev, lkml, sparclinux, virtualization
Subsystem:
exec & binfmt api, elf, filesystems (vfs and infrastructure), memory management - core, scheduler, the rest · Maintainers:
Kees Cook, Alexander Viro, Christian Brauner, Andrew Morton, David Hildenbrand, Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot, Linus Torvalds
If the fdtable is unshared or the task exits we can't install
reservations. The reserved fd isn't reserved anymore. execve() would
leak the reservation into the child.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
fs/exec.c | 3 +++
kernel/fork.c | 2 ++
2 files changed, 5 insertions(+)
diff --git a/fs/exec.c b/fs/exec.c
index 745f6eb5279e..1aa0f7b99fc3 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1159,6 +1159,9 @@ int begin_new_exec(struct linux_binprm * bprm)
*/
io_uring_task_cancel();
+ /* A prepared descriptor would be installed into the new program. */
+ VFS_WARN_ON_ONCE(me->fd_slots.nr);
+
/* Ensure the files table is not shared. */
retval = unshare_files();
if (retval)
diff --git a/kernel/fork.c b/kernel/fork.c
index 59c5cfa3e482..bd0e1e85abb0 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -3217,6 +3217,8 @@ static int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp
if ((unshare_flags & CLONE_FILES) &&
(fd && atomic_read(&fd->count) > 1)) {
+ /* Prepared descriptors live in the table we are about to leave. */
+ VFS_WARN_ON_ONCE(current->fd_slots.nr);
fd = dup_fd(fd, NULL);
if (IS_ERR(fd))
return PTR_ERR(fd);
--
2.53.0