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 14B9B606A680 for ; Sat, 28 Nov 2026 23:59:48 +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 kanga.kvack.org (Postfix) id 4480E6B05CB; Sat, 28 Nov 2026 18:59:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F84A6B05CC; Sat, 28 Nov 2026 18:59:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C0136B05CD; Sat, 28 Nov 2026 18:59:35 -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 E8A126B05CB for ; Sat, 28 Nov 2026 18:59:34 -0500 (EST) Received: from smtpin19.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 76D41A845B for ; Sat, 28 Nov 2026 23:59:34 +0000 (UTC) X-FDA: 85486197468.19.A846EA8 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf31.hostedemail.com (Postfix) with ESMTP id DF00620006 for ; Sat, 28 Nov 2026 23:59:32 +0000 (UTC) Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=U7lCSymv; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf31.hostedemail.com: domain of jarkko@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=jarkko@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1795910373; b=NHjvoFMToXJuZ5IWs02TP5lRrntvKSrScU0036e8A6HxndXhdBdVvyjySXE81WTG61ALTF MOr5L3Sfcm3pERKd+4nqZpfox7KWVViCvtkxJt7LW1MeXQBZ4ruWwtQXWJzQdbwgzr6ieA OjTFjpRGJxkSyzETzhTunQbtv0KZ6Sg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1795910373; 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=4XebnWOjKUyrPC8sl57b/1+sm523Qj8JR0Rek0zFSMw=; b=7qO+ynXj/sLbGyu6fWiXzqLOkJMJeHmbfeJ09dF2IEE9tsxsvZZcN9lmJ28zcgRkCIZIEX vMpinMVWdwLsnWuzZ0SR3zNAdUgNCpK0Gv/T+mTQal6HrWNZZhX5sNbJ4U2XL6sjCJ083B ViMPzwK/ACzAVffz+KUvOYfaxd5fUMs= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=U7lCSymv; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf31.hostedemail.com: domain of jarkko@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=jarkko@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with UTF8SMTP id 7942F6136F; Sat, 28 Nov 2026 23:59:32 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: DF00620006 X-Stat-Signature: qugwfdmodwqs95erkuq1ntknmrxitncf X-Spam-Status: No, score=-18.8 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-HE-Tag: 1795910372-76666 X-HE-Meta: U2FsdGVkX1/IanoHwtwKtF94wZhmIqXRGS92MSgkY5euX8Ly0kKP8xRJKKWUSwukxOktb4LF0CodCL+AGekWg/6REPP2pyTZh9Vytzi5JxIwAkej646Q+kwQimSv9psUhQxQHzNmdcCdxsXAV8Dl4tIUgG4vtFbgAL8xkAz9d7Ldy3/A38B96ArvIvq2OOjYkxemdWOtsftq62AUGqIDyEPOX0TkmmO+A7m8huFHZVupr51XoKUXnWzmJKVYPihXI0d5J33gvU1a59Iit8En1g/oEQzzurfW2ogQOid4KypoQxE49woHdxIyWaP3I+aPLaSvbWowT3ufyZ+qZuowEOsv5LEX1VQCSRuMe3E/uuXyZoE2JUdoCiBjIQ77tv+W+Z69fhCntDi2VxWplCFOO3yDiEr+4AwJNhexc8wgDKJaPmW8leclcUT/AGoZf9rfo8X7GzyqbrtpwjWW1LSOJ4mKlAL/QCL4HYMTHYkmaD8rAeta/iTtV7SIVgmhuAjPJ1j94VhjA1a0BPIQD/GyZXj86K6/bVfMpOe78oVCpVC3EpqrQVXpPGmQa06pzNyji4uHl4YY2rhz7RYCIP02MeVoeplgdvUdS1LM/W0rSptzPsQTqAKh+WYMEIAaJ5WOUx8MiQVhiKaUIKheCE2to/6SgH3SsVqRO3FAOrjrJ64PLtRLZGl5H0Stky62ICYDgKLM6y17sJ0Hadi3kAdWlHLahAUzOv+gsUXiF/UaCzUy0XMNBDELdhywONsbYYAdT3pzFLod9Pjei7W1T2jQ6lSbOVu3/NXvYMKzB4U3z2XO7HPaWYVUqFByoszcUsfpK0Sg+54sUpliZ8L8gam0zBZt2hnicCunWgMxgpqWfjuD4Eg6ChpuyYD1L9j0/rnwkq4CZZ3LNzXjG7lem0XoSfCw5cbRHpxLKm+JBu2yHFMq/VLi1aSTcds4ApnUvmbEgiVkzBY3ZNX0yrQJr9y nLiEu63c N6xtErszEsCSHEfbdFaDkwjW+xYPULD7l0j9OMXXt0kYrZ6w9iCWLJkOtv4XbAGqawJvbfoLTZQF8a83YPqVCF6QrsNgtdwBdnw7esF1+700BaIonBX4GBEj2Gh1Fo58Fw4b/k+bvCwoEJM1Syj+soz/02M0j+vRImrFl9paMqq6oYvdHsWdWuSqf3ks0SsuEnocD1Go3jAcwy+0c1mcXj05k1NU5dwNT7yjFHnSOIblxDr0qQRmUDdCvDSrlJlhwbafxrr051ZdoLgcmWVE4SbllB5LzrdVwO78QmckGZfmQ7MLraOGmd5mji/r+fld1B601jUKV1zp5IT/KaK/4yWy7eSndMhhY2HVB2Q3gm31pxsKNBo7p9Fz7f1E9WMmGdB9qWhlQBKS+OBYLFsYbYXKvo50g5coRGXqKTjHD0jpjShwdp7Sph5AWrm9nTAr+9xYzYeWof+AyC/wlatEZAskIJMED/9eFyN/z4lRWilDRjmmZ2Hi3G/n/aWfFNvlo7pjwxK/ff72zq7yM1XCNu5pFlUR56zxjVUh3 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 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