On Wed, Nov 18, 2026 at 10:42:10PM +0200, Jarkko Sakkinen wrote:
quoted
I.e. before PID 1 and /proc/<pid>/ns/* existss, nsfd for namespace other
than root nsfd can be acquired as follows:
int mnts_fd = ioctl(root_fd, ROOTNS_GET_NSFD, CLONE_NEWNS);
Unprivileged caller becomes the owner of rootns->user_ns. Each mount
syscall then just checks CAP_SYS_ADMIN against rootns->user_ns.
The user space wiring goes along the lines of:
int root_fd = rootns_create(ROOTNS_KILL_ON_CLOSE | ROOTNS_CLOSE_ON_EXEC);
int mntns_fd = ioctl(root_fd, ROOTNS_GET_NSFD, CLONE_NEWNS);
int tmpfs_fd = fsopen("tmpfs", 0);
fsconfig(tmpfs_fd, FSCONFIG_SET_ROOTNS, NULL, NULL, root_fd);
fsconfig(tmpfs_fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
int rootfs_fd = fsmount(tmpfs_fd, 0, 0);
move_mount(rootfs_fd, "", mntns_fd, "/", MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_MNTNS);
struct clone_args args = {
.flags = CLONE_INTO_ROOTNS,
.rootns = root_fd,
};
pid_t pid = clone3(&args, sizeof(args));
[BTW, this patch set is pointed out to David and not fsdevel mailing by a
mishap, apologies.]
I reduced syscalls can be further to only a single syscall: rootns()
The complete API after this:
1. rootns(flags)
2. ioctl(rootfs_fd, ROOTNS_GET_NSFD, ns)
3. ioctl(rootfs_fd, ROOTNS_WAIT, NULL)
4. ioctl(rootfs_fd, ROOTNS_KILL, signum)
An updated version of the patch set is available over here:
https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/log/?h=rootns
In order to find more evidence that the API is trimmed and code has no
extra fat, I tried how LSM hooks size-fit.
Attached are the experimental LSM hooks and while possibly not exactly
right they should not be at least in the ballpar (Paul?).
Not perfect, but very usable, and there's a steady track of convergence
where resolving a bottleneck leads into a better symmetry and coherency
overall.
Br, Jarkko