mirror of
https://github.com/torvalds/linux.git
synced 2026-10-28 01:26:02 +01:00
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 e780259b54 ("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>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
parent
c6516bea4b
commit
e07feeeb5b
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user