Re: [RFC PATCH v4 07/14] fork: Support CLONE_INTO_ROOTNS in clone3()
From: Jarkko Sakkinen
Date: Fri Nov 20 2026 - 07:47:34 EST
On Fri, Nov 20, 2026 at 12:33:25PM +0200, Jarkko Sakkinen wrote:
> On Fri, Nov 20, 2026 at 12:43:05AM +0200, Jarkko Sakkinen 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 CLONE_INTO_ROOTNS and struct clone_args.rootns (CLONE_ARGS_SIZE_VER3)
> > to spawn a child process directly into a rootns whose root mount has
> > been installed. Transition the rootns from ROOTNS_INIT 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.
> >
> > Derive child credentials from current, require CAP_SYS_ADMIN and
> > CAP_SYS_CHROOT in the target user namespace and an ancestor active PID
> > namespace, preserve caller umask, reset dumpability across user namespace
> > transitions, commit time namespace vvar mappings after copy_process()
> > succeeds, and look up the live mount namespace root. Restrict companion
> > flags to CLONE_VFORK, CLONE_PIDFD, CLONE_PIDFD_AUTOKILL, CLONE_AUTOREAP,
> > CLONE_CLEAR_SIGHAND, CLONE_INTO_CGROUP, and CLONE_NNP.
> >
> > Co-developed-by: David Howells <dhowells@xxxxxxxxxx>
> > Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
> > Signed-off-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
>
> Being fd-bound object the gist is that the first clone3() binds
> cgroups, which could e.g., different process than who build the
> container.
>
> CLONE_INTO_CGROUPS is of course available as an optional flag when
> using CLONE_INTO_ROOTNS.
The major benefit over Cells is that there is no embryonic task state
and nothing from the host mount table is inherited unless explicitly
moved in. Also, unshare() cannot ascend from the rootns() created
hierarchy.
Shooting yourself in the foot is an explicit and planned action taken.
And further, it has provably more defence in depth than Cells because
LSM hooks accurately populate the data crossings.
Br, Jarkko