From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796094704; b=DNgpedcPR+GrTQtNHtZAkMzFWqJMEVCATjIWBcyoxlLQsEs5+ae3rE1fdI4uR0yxw39+ Wg0Y84braBh8S+PJentBl3VrseqWiMpeLlHnmvb8AyPxmcnNSyr0XnZZwfYxDIC5nxOxr 9wvGxm2efNkPIr1N1QyX8k7tfq6+qU2OWjLSxa8WxxD8SvNphSiPeXll6kMzS0PowZyrO 2QNTogm1nCvIBfyF57vP5U0WBcLXgcJFh8uhPb5tjqWkV75dPb0yPhdwvF5OAH8qX6/YY 3CpYsiDDTzbysRyc1myDWPaJcjMBp2603upipRgPpPgH2VnssxGf2zy7Eu8nG4mnvYQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796094704; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=UGc3BH9f0cYtD19NY3UL10ARHL4wMnFIlPYkhavKkRo=; b=nAuBs7RuFJqYYtkriNUhFvE1agAAXZaacBVQo5PRY8dLC/iY8SXHpX7JqTQR9MhoVrrB rHZ+8/gTw88EPKqgDbZxVw0JORg82NpEbNQkUiKEvEraBmcXNpaGGfdDf/giSRRTl1i6s tLOBwh+hbjRt8x7uWLgih23EgidSFKzAPBjoIYkGs8heabYPT87dmFta0fhH9VdEp8Xl2 X8B97UQTHis34+J5lZybYWq6V194A4n9Q2A8/1OkLMMJawzIC35JMnzv+et7jm+jEyDjZ ais7P4EsL1MFRCaZqa+2rAPzEan+juJj25D3SC7rlRxVYB1OiuKgdjgxrVyxO+/LbzQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=brDc6tkz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id 0CA7D606A327; Tue, 1 Dec 2026 03:11:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=brDc6tkz Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 341571F00A18; Tue, 1 Dec 2026 03:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796094703; bh=UGc3BH9f0cYtD19NY3UL10ARHL4wMnFIlPYkhavKkRo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=brDc6tkzmFsmRbKB2baKnDJClYNgguZ/qemdORCiVObcQU55x7CDo102C89VgEc5i cqzaHvlxnFri+2YBZ1ZrXEOt4j7Q9+8EQW/kcL5TbZ9MA+AHWWz/w7yvCxtbg/UTDA bJTZOEVgeoc5TkwNO6oLlSDsw9cRCQPqaKK1BIge2APdxzgMDMt7sYwZHbGt8B4hG4 NXDkJ8/7LiStEEMsqOf7AO1Jk6DH2hnH0Co9mTgJOgLh14/T3UmpFIa0KlGlU8eD5N 87qLOO3ybf+Osg++5mgBogqtiWRuNInstjXNNmizUGyxB9OSNlM0J8xnGn5RIAW5Dx hSDImfunS/zeg== From: Jarkko Sakkinen To: fsdevel@vger.kernel.org Cc: Jarkko Sakkinen , bpf@vger.kernel.org, containers@lists.linux.dev, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, Aleksa Sarai , Alexander Mikhalitsyn , Alexander Viro , Alexei Starovoitov , Andrew Morton , Andrii Nakryiko , Andy Lutomirski , Arnd Bergmann , Baolin Wang , Ben Segall , Christian Brauner , Daniel Borkmann , David Hildenbrand , David Howells , David Woodhouse , Davidlohr Bueso , Dietmar Eggemann , Eduard Zingerman , Emil Tsalapatis , Eric Biggers , Georgia Garcia , Giuseppe Scrivano , =?UTF-8?q?G=C3=BCnther=20Noack?= , Hugh Dickins , Ihor Solodrai , Ingo Molnar , James Morris , Jan Kara , Jason Gunthorpe , Jeff Layton , Jiri Olsa , John Johansen , Jonathan Corbet , Josef Bacik , Juri Lelli , Kees Cook , K Prateek Nayak , KP Singh , Kumar Kartikeya Dwivedi , Lennart Poettering , "Liam R. Howlett" , Manfred Spraul , Martin KaFai Lau , Matt Bobrowski , Mel Gorman , Michal Hocko , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Mike Rapoport , Neal Gompa , Oleg Nesterov , Paul Moore , Pavel Tikhomirov , Peter Zijlstra , Randy Dunlap , "Serge E. Hallyn" , Serge Hallyn , Shuah Khan , Song Liu , Stephen Smalley , Steven Rostedt , Valentin Schneider , Vincent Guittot , Yonghong Song , Zygmunt Krynicki Subject: [RFC PATCH v9 18/29] signal: Support nsexec fds in pidfd_send_signal() Date: Tue, 1 Dec 2026 05:09:50 +0200 Message-ID: <20261201031002.593830-19-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201031002.593830-1-jarkko@kernel.org> References: <20261201031002.593830-1-jarkko@kernel.org> X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Signaling every process inside an nsexec from userspace via /proc is racy against concurrent fork() calls. Teach pidfd_send_signal() to dispatch nsexec file descriptors to nsexec_send_signal() when info is NULL and flags is 0. Require an ancestor active PID namespace, walk the nsexec's PID namespace IDR under tasklist_lock, and deliver a validated signal once to each thread group including in-flight forks by member processes, aggregating per-process delivery results. Signed-off-by: Jarkko Sakkinen --- include/linux/nsexec.h | 10 +++++++ kernel/nsexec.c | 59 ++++++++++++++++++++++++++++++++++++++++++ kernel/signal.c | 4 +++ 3 files changed, 73 insertions(+) diff --git a/include/linux/nsexec.h b/include/linux/nsexec.h index e6d772482d1f..6eee61c30f3c 100644 --- a/include/linux/nsexec.h +++ b/include/linux/nsexec.h @@ -20,6 +20,7 @@ struct nsproxy; struct pid; struct pid_namespace; struct rusage; +struct siginfo; struct task_struct; struct user_namespace; struct waitid_info; @@ -79,6 +80,8 @@ void nsexec_copy(struct pid *pid, struct nsexec *nsexec); void nsexec_exit(struct pid_namespace *pid_ns, struct task_struct *tsk); long nsexec_waitid(int upid, struct waitid_info *infop, int options, struct rusage *ru); +int nsexec_send_signal(struct file *file, int sig, + struct siginfo __user *info, unsigned int flags); #else static inline void nsexec_put(struct nsexec *c) { @@ -103,6 +106,13 @@ static inline long nsexec_waitid(int upid, struct waitid_info *infop, { return -EINVAL; } + +static inline int nsexec_send_signal(struct file *file, int sig, + struct siginfo __user *info, + unsigned int flags) +{ + return -EBADF; +} #endif /* CONFIG_NSEXEC */ #endif /* _LINUX_NSEXEC_H */ diff --git a/kernel/nsexec.c b/kernel/nsexec.c index 1df16f70b456..895cc8c3429d 100644 --- a/kernel/nsexec.c +++ b/kernel/nsexec.c @@ -297,6 +297,65 @@ long nsexec_waitid(int upid, struct waitid_info *infop, int options, return ret; } +/** + * DOC: pidfd_send_signal + * + * ``pidfd_send_signal(nsexec_fd, sig, NULL, 0)`` delivers ``sig`` (or ``0`` for + * a permission and existence probe) once to each member thread group in a + * running nsexec. ``info`` must be ``NULL``, ``flags`` must be ``0``, and the + * caller must run in an ancestor active PID namespace. + */ +int nsexec_send_signal(struct file *file, int sig, + struct siginfo __user *info, unsigned int flags) +{ + struct nsexec *nsexec = file->private_data; + struct pid_namespace *pid_ns = nsexec->ns->pid_ns_for_children; + bool any_success = false; + bool any_other = false; + bool any_perm = false; + int other_err = 0; + struct pid *pid; + int nr; + + if (info || flags || sig < 0 || !valid_signal(sig)) + return -EINVAL; + if (!pidns_is_ancestor(pid_ns, task_active_pid_ns(current))) + return -EXDEV; + if (READ_ONCE(nsexec->state) != NSEXEC_RUNNING) + return -ESRCH; + + scoped_guard(rcu) { + read_lock(&tasklist_lock); + idr_for_each_entry(&pid_ns->idr, pid, nr) { + struct task_struct *task = pid_task(pid, PIDTYPE_TGID); + int err; + + if (!task) + continue; + + err = group_send_sig_info(sig, SEND_SIG_NOINFO, task, + PIDTYPE_MAX); + if (!err) { + any_success = true; + } else if (err == -EPERM) { + any_perm = true; + } else if (err != -ESRCH && !any_other) { + any_other = true; + other_err = err; + } + } + read_unlock(&tasklist_lock); + } + + if (any_success) + return 0; + if (any_other) + return other_err; + if (any_perm) + return -EPERM; + return -ESRCH; +} + static long nsexec_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct nsexec *nsexec = file->private_data; diff --git a/kernel/signal.c b/kernel/signal.c index dd770e68faee..217e99c6ac63 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -4181,6 +4182,9 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, if (fd_empty(f)) return -EBADF; + if (nsexec_is_file(fd_file(f))) + return nsexec_send_signal(fd_file(f), sig, info, flags); + /* Is this a pidfd? */ pid = pidfd_to_pid(fd_file(f)); if (IS_ERR(pid)) -- 2.47.3