summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2026-09-10 17:48:07 +0200
committerChristian Brauner <brauner@kernel.org>2026-09-14 15:58:07 +0200
commit64cdb497e72755122c64cd47211e09e26fc75168 (patch)
tree97f4d86daa0d7d58fa00b8e90116496dd741cdb0
parent300dfcadf95036367094b7c2133171f000a88003 (diff)
downloadlinux-next-64cdb497e72755122c64cd47211e09e26fc75168.tar.gz
linux-next-64cdb497e72755122c64cd47211e09e26fc75168.zip
fs: make close_cloexec_files() synchronous
Punting file closing to task work during exec slows down exec significantly when its done with a bunch of file descriptors. We can do this in-band instead. Flush already runs synchronous. Jann moved close-on-exec in e780259b54e6 ("exec: do_close_on_exec() before taking exec_update_lock") outside of exec_update_lock. The only lock that's still held now is cred_guard_mutex. It's deprecated and has five takers (1) exec (2) ptrace_attach() (3) seccomp() with SECCOMP_FILTER_FLAG_TSYNC (4) writes to /proc/<pid>/attr/* (5) lsm_set_self_attr() Four of them take the task's own cred_guard_mutex. When close_cloexec_files() runs, de_thread() ensured that the calling task is the only one alive in its thread-group. That leaves ptrace() waiting on cred_guard_mutex of the tracee going through exec. exec already sleeps under cred_guard_mutex in de_thread() when it reads binary and interpreter. So while we add wait-time to an attaching ptracer no new lock dependency is added. vfork() als waits but that's a dup_fd() copy of the fdtable and rarely holds the last reference. If that's an issue we can always change that later. Link: https://lore.kernel.org/CAGudoHEsGP1P+sAWaw_tbh1NesJhSeww8869uzmaqtgk8F43=Q@mail.gmail.com Link: https://patch.msgid.link/20260910-work-coredump-unlock-self-v4-9-a5c1800dc930@kernel.org Reviewed-by: NeilBrown <neil@brown.name> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
-rw-r--r--fs/exec.c6
-rw-r--r--fs/file.c2
2 files changed, 4 insertions, 4 deletions
diff --git a/fs/exec.c b/fs/exec.c
index 1d9163155d16..075a744421e1 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1173,9 +1173,9 @@ int begin_new_exec(struct linux_binprm * bprm)
* trying to access the should-be-closed file descriptors of a process
* undergoing exec(2).
*
- * This can block on filesystem ->flush() handlers, including waiting
- * for FUSE daemons, so do it before exec_mmap takes the
- * exec_update_lock.
+ * This can block on filesystem ->flush() and ->release() handlers,
+ * including waiting for FUSE daemons, so do it before exec_mmap
+ * takes the exec_update_lock.
* This must happen after the point of no return, and after unsharing
* the FD table.
*/
diff --git a/fs/file.c b/fs/file.c
index b0490566719c..76e328edf630 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -928,7 +928,7 @@ void close_cloexec_files(struct files_struct *files)
rcu_assign_pointer(fdt->fd[fd], NULL);
__put_unused_fd(files, fd);
spin_unlock(&files->file_lock);
- filp_close(file, files);
+ filp_close_sync(file, files);
cond_resched();
spin_lock(&files->file_lock);
}