[RFC PATCH v4 05/14] rootns: Add ROOTNS_WAIT ioctl
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Fri Nov 20 22:44:33 UTC 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] rootns: delayed PID namespace visibility check in
rootns_wait()
--
commit 68c6e4532ee164e48940d00824536de847b1c5d0
Author: Jarkko Sakkinen <jarkko at kernel.org>
rootns: Add ROOTNS_WAIT ioctl
This commit adds the ROOTNS_WAIT ioctl to wait for a root namespace's init
thread group to exit and retrieve its wait status and TGID.
> diff --git a/kernel/rootns.c b/kernel/rootns.c
> index d9ef68d603a24..5f03b6ba4a543 100644
> --- a/kernel/rootns.c
> +++ b/kernel/rootns.c
> @@ -115,6 +115,45 @@ static long rootns_get_nsfd(struct rootns *rootns, unsigned long nstype)
> return nsproxy_open_namespace(rootns->ns, rootns->user_ns, nstype);
> }
>
> +static long rootns_wait(struct rootns *rootns, void __user *uarg)
> +{
> + struct pid_namespace *pid_ns = task_active_pid_ns(current);
> + struct rootns_wait_args args;
> + long ret;
> +
> + if (!uarg)
> + return -EINVAL;
> + if (copy_from_user(&args, uarg, sizeof(args)))
> + return -EFAULT;
> + if (args.flags & ~WNOHANG)
> + return -EINVAL;
> + if (READ_ONCE(rootns->state) == ROOTNS_INIT)
> + return -ECHILD;
> +
> + if (!(args.flags & WNOHANG)) {
> + ret = wait_event_freezable(rootns->waitq,
> + READ_ONCE(rootns->state) == ROOTNS_DEAD ||
> + READ_ONCE(rootns->state) == ROOTNS_INIT);
> + if (ret)
> + return ret;
> + }
> +
> + scoped_guard(spinlock, &rootns->lock) {
> + if (rootns->state == ROOTNS_INIT)
> + return -ECHILD;
> + if (rootns->state != ROOTNS_DEAD)
> + return 0;
> + ret = pid_nr_ns(rootns->init_pid, pid_ns);
> + if (ret <= 0)
> + return -ECHILD;
[Severity: Medium]
Should rootns_wait() check whether the rootns PID namespace is visible in
pid_ns before waiting or returning 0 for WNOHANG?
Because pid_nr_ns() is only checked after rootns->state reaches
ROOTNS_DEAD, a caller in a non-ancestor PID namespace gets 0 instead of
-ECHILD when calling ROOTNS_WAIT with WNOHANG on a running rootns, and a
blocking call sleeps in wait_event_freezable() until init exits before
failing with -ECHILD. Checking
pidns_is_ancestor(rootns->ns->pid_ns_for_children, pid_ns) upfront (as in
rootns_get_nsfd()) would reject invisible targets immediately.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119224312.1037966-1-jarkko@kernel.org?part=5
More information about the Linux-security-module-archive
mailing list