From: Christian Brauner <brauner@kernel.org>
To: Jann Horn <jannh@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
linux-fsdevel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
linux-perf-users@vger.kernel.org, bpf@vger.kernel.org,
selinux@vger.kernel.org, Kees Cook <kees@kernel.org>,
linux-mm@kvack.org, linux-security-module@vger.kernel.org,
apparmor@lists.ubuntu.com, David Hildenbrand <david@kernel.org>,
"Christian Brauner (Amutable)" <brauner@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH RFC 01/19] proc: copy namespace link after dropping exec_update_lock
Date: Tue, 24 Nov 2026 23:58:24 +0100 [thread overview]
Message-ID: <20261124-work-exec-update_lock-v1-1-e489035395b8@kernel.org> (raw)
In-Reply-To: <20261124-work-exec-update_lock-v1-0-e489035395b8@kernel.org>
proc_ns_readlink() copies the name of the namespace to userspace under
exec_update_lock. If that faults the lock is held for as long as the
fault takes. With a buffer in a mapping of a file on a FUSE filesystem
or in a range registered with userfaultfd it's the caller who decides
how long that is:
locks held by ns-reader/230:
#0: (&sig->exec_update_lock){++++}-{4:4}, at: proc_ns_readlink+0x180/0x340
In the meantime an exec of the task waits for exec_update_lock past the
point of no return. And everyone else who needs the exec_update_lock of
the task queues up behind the exec. So a read of /proc/<pid>/stat hangs
as well:
task:exec-task state:D pid:229
Call Trace:
__schedule+0x1691/0x4b00
schedule+0xe0/0x2e0
schedule_preempt_disabled+0x11/0x20
rwsem_down_write_slowpath+0x472/0x1820
down_write_killable+0x1ba/0x240
begin_new_exec+0xa4b/0x2df0
load_elf_binary+0x340/0x4af0
bprm_execve+0x772/0x1400
do_execveat_common.isra.0+0x3d9/0x540
__x64_sys_execve+0x8c/0xc0
do_syscall_64+0x110/0x600
entry_SYSCALL_64_after_hwframe+0x77/0x7f
task:stat-reader state:D pid:231
Call Trace:
__schedule+0x1691/0x4b00
schedule+0xe0/0x2e0
schedule_preempt_disabled+0x11/0x20
rwsem_down_read_slowpath+0x5cc/0x10c0
down_read_killable+0xf1/0x5f0
do_task_stat+0x13b/0x2870
proc_single_show+0x110/0x1d0
seq_read_iter+0x2e4/0x1280
seq_read+0x29b/0x550
vfs_read+0x171/0xb20
ksys_read+0x111/0x250
do_syscall_64+0x110/0x600
entry_SYSCALL_64_after_hwframe+0x77/0x7f
All it takes is being allowed to read the namespace links of the task.
The name is formatted into a buffer on the stack anyway. So drop the
lock before it's copied out.
Fixes: 6650527444da ("proc: protect ptrace_may_access() with exec_update_lock (part 1)")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
fs/proc/namespaces.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c
index ea6ec61a0430b..4c91ccbed21ef 100644
--- a/fs/proc/namespaces.c
+++ b/fs/proc/namespaces.c
@@ -92,12 +92,11 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl
goto out_put_task;
res = -EACCES;
- if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) {
+ if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS))
res = ns_get_name(name, sizeof(name), task, ns_ops);
- if (res >= 0)
- res = readlink_copy(buffer, buflen, name, strlen(name));
- }
up_read(&task->signal->exec_update_lock);
+ if (res >= 0)
+ res = readlink_copy(buffer, buflen, name, strlen(name));
out_put_task:
put_task_struct(task);
return res;
--
2.53.0
next prev parent reply other threads:[~2026-11-24 22:59 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 22:58 [PATCH RFC 00/19] exec: move sleeping work out of exec_update_lock Christian Brauner
2026-11-24 22:58 ` Christian Brauner [this message]
2026-11-24 22:58 ` [PATCH RFC 02/19] kcmp: look up epoll target without exec_update_lock held Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 03/19] perf: copy counter values after dropping ctx->mutex Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 04/19] perf: copy ioctl arguments without ctx->mutex held Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 05/19] selinux: close inherited files that can't be replaced Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 06/19] exec: move unshare_sighand() before exec_mmap() Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 07/19] selftests/exec: test exec with a task sleeping in a page fault Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 08/19] selftests/exec: test exec with a shared signal table Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 09/19] lsm: add security_bprm_revalidate_files() Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 10/19] bpf: mark bprm_revalidate_files as sleepable Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 11/19] selinux: revalidate inherited files before taking exec_update_lock Christian Brauner
2026-11-24 23:49 ` bot+bpf-ci
2026-12-02 0:09 ` Paul Moore
2026-11-24 22:58 ` [PATCH RFC 12/19] apparmor: " Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 13/19] exec: drop exec_update_lock after the credentials are committed Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 14/19] exec: switch time namespace after dropping exec_update_lock Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 15/19] exec: don't take the mmap lock of the old mm Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 16/19] exit: don't take the mmap lock in exit_mm() Christian Brauner
2026-11-24 22:58 ` [PATCH RFC 17/19] proc: look up map_files vma without exec_update_lock held Christian Brauner
2026-11-24 23:09 ` sashiko-bot
2026-11-24 22:58 ` [PATCH RFC 18/19] vfork: wake up the parent once the child has left the mm Christian Brauner
2026-11-24 23:49 ` bot+bpf-ci
2026-11-24 22:58 ` [PATCH RFC 19/19] selftests/exec: test when a vfork() parent is woken up Christian Brauner
2026-11-24 23:15 ` [PATCH RFC 00/19] exec: move sleeping work out of exec_update_lock sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124-work-exec-update_lock-v1-1-e489035395b8@kernel.org \
--to=brauner@kernel.org \
--cc=acme@kernel.org \
--cc=apparmor@lists.ubuntu.com \
--cc=bpf@vger.kernel.org \
--cc=david@kernel.org \
--cc=jannh@google.com \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=selinux@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.