diff options
| author | Christian Brauner <brauner@kernel.org> | 2026-09-10 17:48:02 +0200 |
|---|---|---|
| committer | Christian Brauner <brauner@kernel.org> | 2026-09-14 15:58:06 +0200 |
| commit | bf1b25dc344d77c8e4f3b48fe0662f82e9ba98ce (patch) | |
| tree | 3a3e53552cfdc59119e1006c8599a13bcbc704d0 | |
| parent | fb11a079b003554f2cc8b4a8205bf23a0d9beddf (diff) | |
| download | linux-next-bf1b25dc344d77c8e4f3b48fe0662f82e9ba98ce.tar.gz linux-next-bf1b25dc344d77c8e4f3b48fe0662f82e9ba98ce.zip | |
fs: remove unshare_files()
exec is the only caller left since commit 433967cab51e ("coredump: stop
unsharing the file descriptor table"). All it does is call unshare_fd()
with CLONE_FILES and install the copy. Kill the pointless helper and
open-code it.
No functional changes.
Link: https://patch.msgid.link/20260910-work-coredump-unlock-self-v4-4-a5c1800dc930@kernel.org
Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
| -rw-r--r-- | fs/exec.c | 5 | ||||
| -rw-r--r-- | include/linux/fdtable.h | 1 | ||||
| -rw-r--r-- | kernel/fork.c | 24 |
3 files changed, 4 insertions, 26 deletions
diff --git a/fs/exec.c b/fs/exec.c index d3081c8f7c10..977778f44cfc 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1124,6 +1124,7 @@ static struct file *bprm_identity_file(const struct linux_binprm *bprm) int begin_new_exec(struct linux_binprm * bprm) { struct task_struct *me = current; + struct files_struct *files = NULL; int retval; /* A pending PT_INTERP substitution this format cannot consume. */ @@ -1160,9 +1161,11 @@ int begin_new_exec(struct linux_binprm * bprm) io_uring_task_cancel(); /* Ensure the files table is not shared. */ - retval = unshare_files(); + retval = unshare_fd(CLONE_FILES, &files); if (retval) goto out; + if (files) + switch_files_struct(me, files); /* * We have to apply CLOEXEC before we change whether the process is diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h index 4ee1598848bb..666808a1caf5 100644 --- a/include/linux/fdtable.h +++ b/include/linux/fdtable.h @@ -101,7 +101,6 @@ struct task_struct; void put_files_struct(struct files_struct *fs); void switch_files_struct(struct task_struct *tsk, struct files_struct *files); -int unshare_files(void); int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp); struct fd_range { unsigned int from, to; diff --git a/kernel/fork.c b/kernel/fork.c index 9daf6e94bd5d..10be4a0ecb3f 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -3339,30 +3339,6 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags) return ksys_unshare(unshare_flags); } -/* - * Helper to unshare the files of the current task. - * We don't want to expose copy_files internals to - * the exec layer of the kernel. - */ - -int unshare_files(void) -{ - struct task_struct *task = current; - struct files_struct *old, *copy = NULL; - int error; - - error = unshare_fd(CLONE_FILES, ©); - if (error || !copy) - return error; - - old = task->files; - task_lock(task); - task->files = copy; - task_unlock(task); - put_files_struct(old); - return 0; -} - static int sysctl_max_threads(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { |
