From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A8D51606A684 for ; Sat, 5 Dec 2026 03:29:19 +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 kanga.kvack.org (Postfix) id 4A3976B05D1; Fri, 4 Dec 2026 22:27:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 47B0D6B05D2; Fri, 4 Dec 2026 22:27:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CD8D6B05D3; Fri, 4 Dec 2026 22:27:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D903B6B05D1 for ; Fri, 4 Dec 2026 22:27:58 -0500 (EST) Received: from smtpin17.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3CEEEA818C for ; Sat, 5 Dec 2026 03:27:58 +0000 (UTC) X-FDA: 85508495436.17.67CF613 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf14.hostedemail.com (Postfix) with ESMTP id 90F8A100005 for ; Sat, 5 Dec 2026 03:27:56 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=S+3FTxXJ; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of jarkko@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=jarkko@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796441276; b=L0/3KawpIKriut2rzajQOxjmyb84ILrnKbzs/FClJvzZFmhEs+76EzGj1NM2HVWLceRffy YmwhY+W8RHGgkI+2Jr9ltCZHMFH+nVBDekJcA7oQxC7qsk4DW3KFaIXkUl/CoWb4SpgMps pidbuzOrdtmMvyWKs1XEPELwBisdR+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796441276; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hUAdmZPXQ1i6wSm7YWqFraWaY1QnH/jWLSAzcGJAeoA=; b=WNQKVVVDqztw/hvpcug7Ur5NK2WkK084WsoeyMvzeLS3yBL60Cac7mwiRxq4+ZQ9AeHdp9 0zX3IFPbKvyTqOORnQV428hELwryeDw2ZwSzL+qcfzcVoep2VMVKz5lPMdtu/KRWP07Ja0 7rdwKpEzv3kUAiUAJsEksizXG6Ug278= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=S+3FTxXJ; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of jarkko@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=jarkko@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with UTF8SMTP id E080840C59; Sat, 5 Dec 2026 03:27:55 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: uzzprmgaisapdz4u5boiqcgpew873a1h X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 90F8A100005 X-HE-Tag: 1796441276-490280 X-HE-Meta: U2FsdGVkX1/4JfuWYVEf51We+ZFgxqmCjN/QfejfwVG2RQlB/CVKyXLtO6vG1zCmhcPhk9xoqgH1BbPa6z/uNIc2NUKY2SwUBkOQVmr23Bj5HWnfSOHEqh6y9MFJVf2+6xDEr19HP9p8VbkqrDqyKB7K5brVlf1Is4GvT8USxDh/DIwdSD3Kh0qEWSvyniCAxFnUp93BxtJDtE1ciVbLrzKLihQEH39vpZBy7ohs02esBR+WgfBzLLyQt0IZITzcQ8e0jWUofg52tXITtJAu+oFq2AP5OdKzvHzOykCbKBMzglvj0FyKmEpdTSR8M0eGeOGmmVjp8o2yIHeKYMP7Wq+S/GkYu2AVV+VO1JjDeX3vpb4bhGSB7sG2c0xPKtO4vNuwD7Ysk5FezClpjmLHRk0XXbwGOFie1k3+HrzKie7GbBkiafrMSMS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mjroKrQw/f4uGizWX5qH69d0/ Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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