[RFC PATCH v5 12/25] rootns: Track init lifecycle via copy_process() and pid_namespace

Jarkko Sakkinen jarkko at kernel.org
Sat Nov 21 18:08:52 UTC 2026


On Sat, Nov 21, 2026 at 03:32:08AM +0200, Jarkko Sakkinen wrote:
> On Sat, Nov 21, 2026 at 02:08:31AM +0200, Jarkko Sakkinen wrote:
> > A root namespace needs to record its init thread group's PID when
> > bootstrapped and capture its exit status once all processes in the root
> > namespace have terminated, without serializing normal fork() and exit()
> > paths inside the container.
> > 
> > Commit the bootstrap child reaper and bind pid_ns->rootns in
> > copy_rootns() after attach_pid(PIDTYPE_PID), and invoke exit_rootns()
> > from zap_pid_ns_processes() after the root namespace's PID namespace has
> > killed and reaped all member tasks.
> > 
> > Co-developed-by: David Howells <dhowells at redhat.com>
> > Signed-off-by: David Howells <dhowells at redhat.com>
> > Signed-off-by: Jarkko Sakkinen <jarkko at kernel.org>
> 
> ROOTNS_GET_NSFD will be the only surviving ioctl, which make access
> control wise sense.
> 
> This leaves room for ROOTNS_SHARE_NSFD, which would share a namespace
> from host. This makes whole a lot more sense than unsharing security
> wise as it is allow listing (instead of deny listing).
> 
> It can be post-clone3 disabled. This is what we do in SGX driver i.e.,
> have build phase enabled ioctls.

/**
 * DOC: ROOTNS_SHARE_NSFD
 *
 * ``ioctl(rootns_fd, ROOTNS_SHARE_NSFD, ns_fd)`` replaces the corresponding
 * member namespace of ``rootns_fd`` with the ``nsfs`` namespace referenced by
 * ``ns_fd`` (one of ``CLONE_NEWCGROUP``, ``CLONE_NEWIPC``, ``CLONE_NEWUTS``,
 * ``CLONE_NEWNET``, or ``CLONE_NEWTIME``) while ``rootns_fd`` is in its
 * initial build phase (``ROOTNS_INIT``).
 *
 * Requires ``CAP_SYS_ADMIN`` in the container object's user namespace, and
 * when the caller is not already a member of ``ns_fd``, ``CAP_SYS_ADMIN``
 * in the owning user namespace of ``ns_fd``.
 *
 * Returns ``0`` on success, or ``-1`` with ``errno`` set to ``EBADF`` if
 * ``ns_fd`` is not an open file descriptor, ``EINVAL`` if ``ns_fd`` is not a
 * shareable ``nsfs`` namespace file descriptor, ``EOPNOTSUPP`` if the
 * namespace type is unsupported, ``EPERM`` without required capabilities, or
 * ``EBUSY`` once ``CLONE_INTO_ROOTNS`` has transitioned ``rootns_fd`` out of
 * ``ROOTNS_INIT``.
 */
#define ROOTNS_SHARE_NSFD      _IO(ROOTNS_IOCTL_MAGIC, 0x02)

Makes sense enough to include to the next version.

Br, Jarkko



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