Re: [RFC PATCH 07/13] rootns: Add rootns_enter() system call
From: Jarkko Sakkinen
Date: Tue Nov 17 2026 - 15:03:43 EST
On Tue, Nov 17, 2026 at 09:42:26AM -0800, Andy Lutomirski wrote:
> On Mon, Nov 16, 2026 at 9:09 PM Jarkko Sakkinen <jarkko@xxxxxxxxxx> wrote:
> >
> > Multithreaded userspace daemons cannot call setns(CLONE_NEWUSER) or
> > safely mutate process-wide filesystem state in place before spawning a
> > child into a target namespace set.
> >
> > Add the rootns_enter() system call to fork a child process directly into
> > a rootns whose root mount has been installed. Transition the rootns from
> > ROOTNS_READY through ROOTNS_FORKING to ROOTNS_RUNNING for the first
> > process so it becomes PID 1, serialize concurrent entrants on waitq
> > until bootstrap resolves, and admit subsequent callers into the running
> > PID namespace until teardown begins.
> >
> > Require CAP_SYS_ADMIN in the target user namespace, forbid credential or
> > PR_SET_NO_NEW_PRIVS privilege escalation
>
> Why are you disallowing this if no_new_privs?
For no any good reason at all apparently: no_new_privs is inherited by
the child and only restricts privilege gain across execve(), whereas
user_namespace transitions are allowed under it.
So yeah, it's a spurious check, and thus I'll drop it.
> This isn't necessarily a showstopper, but fork() is really quite slow
> in many cases. It would be nice to have a more spawn-like API
> available. I assume it's possible to open a file in the target's
> mountns by some sane API even without entering that mountns, as a side
> effect of how the fsopen / move_mount mechanism works.
If the caller retains the O_PATH fd returned by fsmount() for "/", it is
able to open files inside the target mount tree via openat2(...,
RESOLVE_IN_ROOT) w/o entering the mount namespace, and pass the
resulting fd to execveat().
For avoiding full fork(), there are (at least) two options:
1. A rootns flag in clone3() (e.g., CLONE_INTO_ROOTNS) and a rootns fd
in struct clone_args (disallowing incompatible CLONE_NEW*, CLONE_FS,
CLONE_THREAD, ...), and callers can pair it with CLONE_VM | CLONE_VFORK.
2. A flags parameter in rootns_enter() (e.g., ROOTNS_ENTER_VFORK), which
would map directly to CLONE_VM | CLONE_VFORK.
>
> --Andy
Br, Jarkko