[RFC PATCH 06/13] rootns: Add rootns_kill() system call

sashiko-bot at kernel.org sashiko-bot at kernel.org
Wed Nov 18 05:09:47 UTC 2026


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 af3e55bb2ee92ebb14699cd9c72b34e3ddb26ffe
Author: Jarkko Sakkinen <jarkko at 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 send a signal to every member thread group.

> diff --git a/kernel/rootns.c b/kernel/rootns.c
> index 8a1254db69df7..f59b2fe9910de 100644
> --- a/kernel/rootns.c
> +++ b/kernel/rootns.c

[ ... ]

> @@ -390,3 +391,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]
Should rootns_kill_members() verify that the caller's active PID namespace
is equal to or an ancestor of pid_ns before delivering signals?

Without an ancestry check, a caller holding rootnsfd in a sibling or
descendant PID namespace can signal processes outside its PID namespace
hierarchy.  Because kill_pid() 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));
	}
    ...
}

when current has no PID in task_active_pid_ns(t), send_signal_locked()
treats the signal as coming from an ancestor PID namespace and sets
force = true, bypassing SIGNAL_UNKILLABLE and allowing SIGKILL or SIGSTOP
to kill or stop the PID namespace 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 signals sent by rootns_kill_members()?

CPU0                              CPU1
copy_process()
  hlist_add_head(&delayed.node,
    &current->signal->multiprocess)
  ...
  pid = alloc_pid(...)
                                  rootns_kill_members()
                                    idr_for_each_entry(&pid_ns->idr, ...)
                                      /* parent: kill_pid() uses
                                       * PIDTYPE_TGID, so delayed.signal
                                       * is not updated */
                                      kill_pid(parent_pid, SIGTERM, 0)
                                      /* child: not attached yet */
                                      !pid_task(child_pid, PIDTYPE_TGID)
                                        -> continue
  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 escapes SIGTERM */

__send_signal_locked() only records signals in t->signal->multiprocess for
in-flight forks when type > PIDTYPE_TGID, whereas kill_pid() passes
PIDTYPE_TGID.  In addition, because pid_ns->idr is walked without holding
read_lock(&tasklist_lock), a parent at a higher IDR entry can fork and
attach a child at a lower, already-scanned IDR entry (via PID wrap-around
or clone3() set_tid) before the scan reaches the parent, allowing the child
to escape even SIGKILL, or rootns_kill_members() can observe
pid_task(pid, PIDTYPE_TGID) before attach_pid(p, PIDTYPE_PID) completes and
get -ESRCH from kill_pid().

Holding read_lock(&tasklist_lock) during the IDR walk and signaling via
group_send_sig_info(sig, SEND_SIG_NOINFO, task, PIDTYPE_MAX), as
zap_pid_ns_processes() and kill(-1, sig) do, would close these races.

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



More information about the Linux-security-module-archive mailing list