All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jarkko Sakkinen" <jarkko@kernel.org>
Cc: linux-mm@kvack.org, linux-security-module@vger.kernel.org,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Andy Lutomirski" <luto@amacapital.net>,
	"Ben Segall" <bsegall@google.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"David Hildenbrand" <david@kernel.org>,
	"David Howells" <dhowells@redhat.com>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
	"Ingo Molnar" <mingo@redhat.com>, "Jan Kara" <jack@suse.cz>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"John Johansen" <john.johansen@canonical.com>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Kees Cook" <kees@kernel.org>,
	"K Prateek Nayak" <kprateek.nayak@amd.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Manfred Spraul" <manfred@colorfullife.com>,
	"Mel Gorman" <mgorman@suse.de>, "Michal Hocko" <mhocko@suse.com>,
	"Mike Rapoport" <rppt@kernel.org>, "Neal Gompa" <neal@gompa.dev>,
	"Paul Moore" <paul@paul-moore.com>,
	"Pavel Tikhomirov" <ptikhomirov@virtuozzo.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Serge Hallyn" <sergeh@kernel.org>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Valentin Schneider" <vschneid@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Zygmunt Krynicki" <zygmunt.krynicki@canonical.com>
Subject: Re: [RFC PATCH v2 06/13] rootns: Add rootns_kill() system call
Date: Wed, 18 Nov 2026 23:15:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-222160@kernel.org> (raw)
In-Reply-To: <20261117231352.3816603-7-jarkko@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] rootns: fork() race in rootns_kill_members() missing
  tasklist_lock
- [High] rootns: missing PID namespace ancestry check in
  rootns_kill_members()
--

commit ea67311730397795196206953e1b7e54d487cc13
Author: Jarkko Sakkinen <jarkko@kernel.org>

rootns: Add rootns_kill() system call

This commit adds the rootns_kill() system call to walk a root namespace's
PID namespace IDR and deliver a signal to each member thread group.

> diff --git a/kernel/rootns.c b/kernel/rootns.c
> index 83ab759a31ecd..90a070dbf4a82 100644
> --- a/kernel/rootns.c
> +++ b/kernel/rootns.c
[ ... ]
> @@ -389,3 +390,67 @@ COMPAT_SYSCALL_DEFINE4(rootns_wait, int, rootnsfd,
>  	return ret;
>  }
>  #endif
> +
> +static int rootns_kill_members(struct rootns *rootns, int sig)
> +{
> +	struct pid_namespace *pid_ns = rootns->ns->pid_ns_for_children;

[Severity: High]
Does rootns_kill_members() need to check that the caller's active PID
namespace is an ancestor of pid_ns before delivering signals?

kill_pid(pid, sig, 0) passes SEND_SIG_NOINFO to send_signal_locked():

kernel/signal.c:send_signal_locked() {
    ...
	if (info == SEND_SIG_NOINFO) {
		/* Force if sent from an ancestor pid namespace */
		force = !task_pid_nr_ns(current, task_active_pid_ns(t));
	}
    ...
}

Without a PID namespace ancestry check (like access_pidfd_pidns() in
sys_pidfd_send_signal()), a holder of rootnsfd in a sibling or disjoint
PID namespace has task_pid_nr_ns(current, task_active_pid_ns(t)) == 0.
That sets force = true and bypasses SIGNAL_UNKILLABLE in
sig_task_ignored(), allowing a non-ancestor process to kill or stop the
PID namespace init with SIGKILL or SIGSTOP.  A caller in a descendant PID
namespace created inside the rootns can also signal tasks upward in its
ancestor pid_ns, while a caller inside pid_ns itself has force = false so
SIGKILL and SIGSTOP are ignored on the rootns init process.

> +	bool any_success = false;
> +	bool any_other = false;
> +	bool any_perm = false;
> +	int other_err = 0;
> +	struct pid *pid;
> +	int nr;
> +
> +	if (READ_ONCE(rootns->state) != ROOTNS_RUNNING)
> +		return -ESRCH;
> +
> +	scoped_guard(rcu) {
> +		idr_for_each_entry(&pid_ns->idr, pid, nr) {
> +			int err;
> +
> +			if (!pid_task(pid, PIDTYPE_TGID))
> +				continue;
> +
> +			err = kill_pid(pid, sig, 0);

[Severity: High]
Can a concurrent fork() still escape signal delivery in
rootns_kill_members()?

CPU0                              CPU1
copy_process()
  /* queues delayed.node on
   * current->signal->multiprocess
   */
  alloc_pid()
    /* inserts child pid into
     * pid_ns->idr (tasks[] empty)
     */
                                  rootns_kill_members()
                                    idr_for_each_entry(&pid_ns->idr, ...)
                                      /* child pid: pid_task(..., PIDTYPE_TGID)
                                       * is NULL -> skipped
                                       */
                                      /* parent pid: kill_pid() passes
                                       * PIDTYPE_TGID
                                       */
                                        __send_signal_locked()
                                          /* type > PIDTYPE_TGID is false;
                                           * delayed.signal not updated
                                           */
  write_lock_irq(&tasklist_lock)
  p->signal->shared_pending.signal =
    delayed.signal;
  attach_pid(p, PIDTYPE_TGID)
  attach_pid(p, PIDTYPE_PID)
  write_unlock_irq(&tasklist_lock)
                                  /* child never receives sig */

__send_signal_locked() only records signals into t->signal->multiprocess
for in-flight forks when type > PIDTYPE_TGID, whereas kill_pid() uses
PIDTYPE_TGID.  For any signal that does not make fatal_signal_pending()
true on the parent (such as SIGSTOP, SIGHUP, SIGINT, or a caught or
blocked SIGTERM), the child finishes copy_process() without receiving the
signal.

Because pid_ns->idr is walked without read_lock(&tasklist_lock), a parent
at a higher IDR index can also allocate a lower, already-visited IDR index
for its child (after PID wrap-around or via clone3() set_tid) and finish
attaching the child before the scan reaches the parent, escaping even
SIGKILL.  In addition, copy_process() calls attach_pid(p, PIDTYPE_TGID)
before attach_pid(p, PIDTYPE_PID) under tasklist_lock, so unlocked readers
can see pid_task(pid, PIDTYPE_TGID) != NULL while kill_pid() still sees
pid_task(pid, PIDTYPE_PID) == NULL and returns -ESRCH.

Holding read_lock(&tasklist_lock) and signaling via group_send_sig_info()
with PIDTYPE_MAX (as zap_pid_ns_processes() and kill_something_info() do)
would serialize against copy_process() and populate delayed.signal for
ongoing forks.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=6

  reply	other threads:[~2026-11-18 23:15 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
2026-11-17 23:13 ` [RFC PATCH v2 01/13] nsproxy: Pass nsproxy to create_new_namespaces() Jarkko Sakkinen
2026-11-18 23:15   ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 02/13] rootns: Add core infrastructure for root namespaces Jarkko Sakkinen
2026-11-18 23:15   ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 03/13] rootns: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
2026-11-18 23:15   ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 04/13] rootns: Add rootns_create() system call Jarkko Sakkinen
2026-11-18 23:15   ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 05/13] rootns: Add rootns_wait() " Jarkko Sakkinen
2026-11-18 23:15   ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 06/13] rootns: Add rootns_kill() " Jarkko Sakkinen
2026-11-18 23:15   ` sashiko-bot [this message]
2026-11-17 23:13 ` [RFC PATCH v2 07/13] fork: Support CLONE_INTO_ROOTNS in clone3() Jarkko Sakkinen
2026-11-18 23:15   ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 08/13] fs: Support FSCONFIG_SET_ROOTNS in fsconfig() Jarkko Sakkinen
2026-11-18 23:15   ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 09/13] fs: Support installing rootns mount trees via move_mount() Jarkko Sakkinen
2026-11-18 23:15   ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 10/13] arch: Wire up rootns system calls Jarkko Sakkinen
2026-11-18 23:15   ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 11/13] docs: Document root namespace uAPI Jarkko Sakkinen
2026-11-18 23:15   ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 12/13] selftests/rootns: Add root namespace test suite Jarkko Sakkinen
2026-11-18 23:15   ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 13/13] MAINTAINERS: Add entry for ROOT NAMESPACE Jarkko Sakkinen
2026-11-18 14:47 ` [RFC PATCH v2 00/13] Namespace for namespace roots Josef Bacik
2026-11-18 15:28   ` Jarkko Sakkinen
2026-11-18 15:39     ` Jarkko Sakkinen
2026-11-18 15:46       ` Jarkko Sakkinen
2026-11-18 16:59 ` Andy Lutomirski
2026-11-18 17:04   ` Jarkko Sakkinen
2026-11-18 17:08     ` Jarkko Sakkinen
2026-11-18 17:30       ` Jarkko Sakkinen
2026-11-18 17:46       ` Andy Lutomirski
2026-11-18 18:23         ` Jarkko Sakkinen
2026-11-19 17:30         ` Josef Bacik
2026-11-19 17:43           ` Jarkko Sakkinen
2026-11-19 17:51             ` Jarkko Sakkinen
2026-11-19 22:50           ` Andy Lutomirski
2026-11-19 23:27             ` Andy Lutomirski
2026-11-20 12:32               ` Alexander Mikhalitsyn
2026-11-20 13:13                 ` Jarkko Sakkinen
2026-11-20 13:24                   ` Alexander Mikhalitsyn
2026-11-20 13:57                     ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-222160@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=bsegall@google.com \
    --cc=corbet@lwn.net \
    --cc=dave@stgolabs.net \
    --cc=david@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=jack@suse.cz \
    --cc=jarkko@kernel.org \
    --cc=john.johansen@canonical.com \
    --cc=juri.lelli@redhat.com \
    --cc=kees@kernel.org \
    --cc=kprateek.nayak@amd.com \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=luto@amacapital.net \
    --cc=manfred@colorfullife.com \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=neal@gompa.dev \
    --cc=paul@paul-moore.com \
    --cc=peterz@infradead.org \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=rdunlap@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sergeh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vschneid@redhat.com \
    --cc=zygmunt.krynicki@canonical.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.