[RFC PATCH v5 14/25] rootns: Add ROOTNS_WAIT ioctl

Jarkko Sakkinen jarkko at kernel.org
Sat Nov 21 01:09:10 UTC 2026


On Sat, Nov 21, 2026 at 02:18:14AM +0200, Jarkko Sakkinen wrote:
> > Ought to be dropped but seemed too irrelevant detail for the time
> > being
> 
> I mean replaced with a syscall path.

Yeah, a lot better overall (less fallible paths).

+long rootns_waitid(int upid, struct waitid_info *infop, int options,
+                  struct rusage *ru)
 {
-       struct pid_namespace *pid_ns = task_active_pid_ns(current);
-       struct rootns_wait_args args;
+       struct pid_namespace *pid_ns;
+       unsigned int f_flags;
+       struct rootns *rootns;
+       bool nonblock;
+       int status;
+       kuid_t uid;
        long ret;

-       if (!uarg)
+       if (upid < 0 || ru)
                return -EINVAL;
-       if (copy_from_user(&args, uarg, sizeof(args)))
-               return -EFAULT;
-       if (args.flags & ~WNOHANG)
+       if (options & ~(WEXITED | WNOHANG | WNOWAIT))
                return -EINVAL;
+       if (!(options & WEXITED))
+               return -EINVAL;
+
+       CLASS(fd, f)(upid);
+       if (fd_empty(f) || !is_rootns_file(fd_file(f)))
+               return -EBADF;
+
+       f_flags = READ_ONCE(fd_file(f)->f_flags);
+       nonblock = (options & WNOHANG) || (f_flags & O_NONBLOCK);
+       rootns = fd_file(f)->private_data;
+       pid_ns = task_active_pid_ns(current);
+
        if (!pidns_is_ancestor(rootns->ns->pid_ns_for_children, pid_ns))
                return -ECHILD;
        if (READ_ONCE(rootns->state) == ROOTNS_INIT)
                return -ECHILD;

-       if (!(args.flags & WNOHANG)) {
+       if (!nonblock) {
                ret = wait_event_freezable(rootns->waitq,
                                           READ_ONCE(rootns->state) == ROOTNS_DEAD ||
                                           READ_ONCE(rootns->state) == ROOTNS_INIT);
@@ -154,15 +191,23 @@ static long rootns_wait(struct rootns *rootns, void __user *uarg)
                if (rootns->state == ROOTNS_INIT)
                        return -ECHILD;
                if (rootns->state != ROOTNS_DEAD)
-                       return 0;
+                       return (options & WNOHANG) ? 0 : -EAGAIN;
                ret = pid_nr_ns(rootns->init_pid, pid_ns);
                if (ret <= 0)
                        return -ECHILD;
-               args.status = rootns->exit_code;
+               status = rootns->exit_code;
+               uid = rootns->init_uid;
        }

-       if (copy_to_user(uarg, &args, sizeof(args)))
-               return -EFAULT;
+       if ((status & 0x7f) == 0) {
+               infop->cause = CLD_EXITED;
+               infop->status = status >> 8;
+       } else {
+               infop->cause = (status & 0x80) ? CLD_DUMPED : CLD_KILLED;
+               infop->status = status & 0x7f;
+       }
+       infop->pid = ret;
+       infop->uid = from_kuid_munged(current_user_ns(), uid);
        return ret;
 }

Br, Jarkko



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