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=1796441276; b=CDCJNVptW/p6ueAOw+x0IX5Hfo/qWpptOoeBOlceVPj2KYEuALECQMVlSSfZ9K0VcghX EzMuzXys2LxJn45ilrfkZ8CcQKVIADwHp4+Umx5OHhR9LNZ7lrTVOi/Dt5cWYLDms5Wp8 w1oJglLgWNQK7duh6n6kFpOVcBGYpAaLRvw4fEqMU02S0C+ZzhIQcnMIlIBmLYRbuWyzh DBE6Xo990Le0YrNlWTD7xSh8j4nJwVL0S0H8ynI5ZcBWTph5seMhMFu7RDSbj8AWLa21t +3YwDoHwhcGJv0EZ3Q6XetxdtOur6APVT/v+ir5Io2GyyHvGuldmjAiVJsk4oRciIZA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796441276; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=hUAdmZPXQ1i6wSm7YWqFraWaY1QnH/jWLSAzcGJAeoA=; b=KJZid+tfkS1MXcMNNJTRkAlraPhIw9NuyLzvFp0GjJg1PmZjVYqfYXwiKTmP4627Z4xG 8PvqujwPosfhAv0pUMm68eQ+eBYy7pbDGtjLmzl8hEKbk/BkTXxq3DI2ZyktNXQ60REhk iNIhCMqAiu89Ercyu4h6ea8TBpTDO0sHZ+vRHO82o/GqJq4ukRN4yZEkWaP9HbfNFCY+T 2QpX0EeRqH+flVtd92poPLxLoBul7Xz0Q+/MWr21xmOt2PhIKNR4z9ApHrwyQgL5iydve N8Lo/HvF3A/kOnNATdpb1d0FPaRHGrVjonB821dcrH+60WinRvuZ/CQv5GcZN/OfB/w== 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=S+3FTxXJ; 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 38B38606A6AC; Sat, 5 Dec 2026 03:27:55 +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=S+3FTxXJ Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 19A121F00A24; Sat, 5 Dec 2026 03:27:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796441275; bh=hUAdmZPXQ1i6wSm7YWqFraWaY1QnH/jWLSAzcGJAeoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=S+3FTxXJ2R7/unU/f+J7gLY7nHuLeXNv3pIEhHf7JQ9BYzd9yGOtvc4tQnTPKSb0+ BFRouQpLEYPBnv2zrYWBCSmvn5KGjkfrUsxOZW19UbaIh68kS5FDEDgis0SO9T0IQi BJHJAfK/okzn1MJ80XZPyyAfxy2897RFXlUQkQ56BDA3YKd0lc2zPwtPfFFhr9q0Dd dZB2yrRsLs2pFgikyg8ppUb/hmDoObzv5JvnNuApQyPL+FEQl9qFT5wU+Pj1xWfsRF +7849N/d5NSAeYniecBKxUTvD3wjPKBEp9ZSKzAHxtfdY4pimFj90DQU2beHyMAdsF 0A0DoaqwS68Gg== 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 v10 17/28] signal: Support run fds in pidfd_send_signal() Date: Sat, 5 Dec 2026 05:26:22 +0200 Message-ID: <20261205032633.1702772-18-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261205032633.1702772-1-jarkko@kernel.org> References: <20261205032633.1702772-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 a run from userspace via /proc is racy against concurrent fork() calls. Teach pidfd_send_signal() to dispatch run file descriptors to runfd_send_signal() when info is NULL and flags is 0. Require an ancestor active PID namespace, walk the run'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/runfd.h | 10 ++++++++ kernel/runfd.c | 59 +++++++++++++++++++++++++++++++++++++++++++ kernel/signal.c | 4 +++ 3 files changed, 73 insertions(+) diff --git a/include/linux/runfd.h b/include/linux/runfd.h index eb2e8db5844f..b22790fdefd9 100644 --- a/include/linux/runfd.h +++ b/include/linux/runfd.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 runfd_copy(struct pid *pid, struct run *run); void runfd_exit(struct pid_namespace *pid_ns, struct task_struct *tsk); long runfd_waitid(int upid, struct waitid_info *infop, int options, struct rusage *ru); +int runfd_send_signal(struct file *file, int sig, + struct siginfo __user *info, unsigned int flags); #else static inline void runfd_put(struct run *c) { @@ -103,6 +106,13 @@ static inline long runfd_waitid(int upid, struct waitid_info *infop, { return -EINVAL; } + +static inline int runfd_send_signal(struct file *file, int sig, + struct siginfo __user *info, + unsigned int flags) +{ + return -EBADF; +} #endif /* CONFIG_RUNFD */ #endif /* _LINUX_RUNFD_H */ diff --git a/kernel/runfd.c b/kernel/runfd.c index 52a07a108705..81ce523c79c6 100644 --- a/kernel/runfd.c +++ b/kernel/runfd.c @@ -298,6 +298,65 @@ long runfd_waitid(int upid, struct waitid_info *infop, int options, return ret; } +/** + * DOC: pidfd_send_signal + * + * ``pidfd_send_signal(run_fd, sig, NULL, 0)`` delivers ``sig`` (or ``0`` for + * a permission and existence probe) once to each member thread group in a + * running run. ``info`` must be ``NULL``, ``flags`` must be ``0``, and the + * caller must run in an ancestor active PID namespace. + */ +int runfd_send_signal(struct file *file, int sig, + struct siginfo __user *info, unsigned int flags) +{ + struct run *run = file->private_data; + struct pid_namespace *pid_ns = run->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(run->state) != RUNFD_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 runfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct run *run = file->private_data; diff --git a/kernel/signal.c b/kernel/signal.c index dd770e68faee..edc72d870a3b 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 (runfd_is_file(fd_file(f))) + return runfd_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