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=1795910373; b=PYrZGWenHH9qFayd43rYGzgn78FYkY9e56eCWEuQ8UYo3XAXDx+PpPESxEWN8KO0wZcu tkuEU79h0GPrmBmnxDjHW4nN17KAphOa8sJZx5uvmr8rPBowuhZ3ifKRDIRp4RF9471O8 wjz9yYGtrI1u7+qB9vub+7EkI8gxdIucZZPz8UlNxmlkEzkWsgWs1iRIvZN+buqdDIZ3p GtgoJuywiey0iGVYwhcsAhSEKy2FztTPeJwkkQjs1enWeKgVXhIEWsddjQ66xijbDRqW7 NQbglP2tjWdmRslRczBWGbFF8dqWD/BeXpAyTgKJdWimmcwN09m/E5AqBQ5lKyUBRJg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795910373; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=4XebnWOjKUyrPC8sl57b/1+sm523Qj8JR0Rek0zFSMw=; b=XKyLEJKhYqs6z140NnHsTIZQoPpJD+w7p5HJ6zBr8Asv4qXRDNb9VJ3RRlJrZ3iRBW6R au/AD32iJtyYdCRdg0c9yFU9cpG3Xr8ogJVaPQdXuggVF8Jjp9AU80IWMsAEkOjo5P82I JC38Zq6X54YJvlfD0yh4V78Y+mqsXqVS/tehfoBgKaqkYKCwSval2bHMBURvMeB7WM+2l /Kl7wYKDp7QQMXbTX2HmGPBlWJLvIWPtmz+F02u92SPjM8Y4URdpgyRqOKY9D8STBjk6T 0EnJOyzfkBfaCrVMSb7RS0YPpBAzPyl6zaGfB79ugjv0vBhMNfaWS4FGr/+aLqtKzyw== 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=U7lCSymv; 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 528EC606A32D; Sat, 28 Nov 2026 23:59:32 +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=U7lCSymv Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 75DFA1F0089A; Sat, 28 Nov 2026 23:59:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795910372; bh=4XebnWOjKUyrPC8sl57b/1+sm523Qj8JR0Rek0zFSMw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U7lCSymvfWNHALKEqu3wQN56PRehHCxaJEQTxH69OTw1woCcmlpHX6W1x67Fljin3 +CUPvKxYXb7bkoKj/u1Lzo1ryUaoU0k3iZadE4lbYYERDI1N8l3ZksYYfp/i5+VrAP zqFlPW60Ns+G3NhLrmmEvicB4hYMbIwwSzDjCij7IgyBj7cFxG7pC6JvA7ystplp6K K6ozU7jKUvjAFaMXtMrGa1F6BB8Bk4I74UFgnW8FnuIFkIQ8C1IFAusN5KuQ5MlK3Y BRd5JSDmI4xFAQTDh+sGcirechjywxlhbW0Sjc26oGblOAdweZKVwUXKza8fz+UFGl 1EemE4WlLZthw== 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-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 , Andy Lutomirski , Arnd Bergmann , Christian Brauner , David Howells , Eric Biggers , Georgia Garcia , Giuseppe Scrivano , Hugh Dickins , James Morris , Jan Kara , Jeff Layton , John Johansen , Jonathan Corbet , Josef Bacik , Kees Cook , KP Singh , Lennart Poettering , Matt Bobrowski , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Neal Gompa , Oleg Nesterov , Paul Moore , Pavel Tikhomirov , Serge Hallyn , Shuah Khan , Stephen Smalley , Zygmunt Krynicki Subject: [RFC PATCH v8 18/29] signal: Support userland fds in pidfd_send_signal() Date: Sun, 29 Nov 2026 01:57:57 +0200 Message-ID: <20261128235808.2369970-19-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261128235808.2369970-1-jarkko@kernel.org> References: <20261128235808.2369970-1-jarkko@kernel.org> X-Mailing-List: bpf@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 a userland from userspace via /proc is racy against concurrent fork() calls. Teach pidfd_send_signal() to dispatch userland file descriptors to userland_send_signal() when info is NULL and flags is 0. Require an ancestor active PID namespace, walk the userland'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/userland.h | 10 +++++++ kernel/signal.c | 4 +++ kernel/userland.c | 59 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/include/linux/userland.h b/include/linux/userland.h index 8605b6cbb68a..90c55490c579 100644 --- a/include/linux/userland.h +++ b/include/linux/userland.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 userland_copy(struct pid *pid, struct userland *userland); void userland_exit(struct pid_namespace *pid_ns, struct task_struct *tsk); long userland_waitid(int upid, struct waitid_info *infop, int options, struct rusage *ru); +int userland_send_signal(struct file *file, int sig, + struct siginfo __user *info, unsigned int flags); #else static inline void userland_put(struct userland *c) { @@ -103,6 +106,13 @@ static inline long userland_waitid(int upid, struct waitid_info *infop, { return -EINVAL; } + +static inline int userland_send_signal(struct file *file, int sig, + struct siginfo __user *info, + unsigned int flags) +{ + return -EBADF; +} #endif /* CONFIG_USERLAND */ #endif /* _LINUX_USERLAND_H */ diff --git a/kernel/signal.c b/kernel/signal.c index dd770e68faee..5b11e67dc98a 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 (userland_is_file(fd_file(f))) + return userland_send_signal(fd_file(f), sig, info, flags); + /* Is this a pidfd? */ pid = pidfd_to_pid(fd_file(f)); if (IS_ERR(pid)) diff --git a/kernel/userland.c b/kernel/userland.c index 3eaf45dca9e5..c82301b69f9b 100644 --- a/kernel/userland.c +++ b/kernel/userland.c @@ -296,6 +296,65 @@ long userland_waitid(int upid, struct waitid_info *infop, int options, return ret; } +/** + * DOC: pidfd_send_signal + * + * ``pidfd_send_signal(userland_fd, sig, NULL, 0)`` delivers ``sig`` (or ``0`` for + * a permission and existence probe) once to each member thread group in a + * running userland. ``info`` must be ``NULL``, ``flags`` must be ``0``, and the + * caller must run in an ancestor active PID namespace. + */ +int userland_send_signal(struct file *file, int sig, + struct siginfo __user *info, unsigned int flags) +{ + struct userland *userland = file->private_data; + struct pid_namespace *pid_ns = userland->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(userland->state) != USERLAND_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 userland_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct userland *userland = file->private_data; -- 2.47.3