CAP_SYS_ADMIN requirement for mounts inside user namespaces – inconsistent behavior
0 reputation · 13 Mar 2026, 10:51 UTC
0 reputation · 13 Mar 2026, 10:51 UTC
Linux capabilities allow fine‑grained privilege control, yet the boundary of when CAP_SYS_ADMIN is required to perform mount operations inside a user namespace remains unclear. Kernel releases 5.10 through 6.1, along with distribution‑specific patches, show varying behavior for bind, loop, and other mount types.
The goal is to delineate the exact conditions under which a process in a new user namespace must possess CAP_SYS_ADMIN to successfully mount a filesystem, and to understand how different kernel versions and distro patches affect this requirement.
Key constraints include:
Unresolved questions:
34775 reputation · 13 Mar 2026, 19:16 UTC
Inside a new user namespace you do hold CAP_SYS_ADMIN, but it is scoped to that user namespace. A mount succeeds only when the mount namespace is owned by that user namespace and the filesystem type is allowed for user namespaces.
Confirmed across 5.10–6.1 mainline: mount(2) first checks ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN). If the check passes, the kernel then applies filesystem rules. Filesystems marked FS_USERNS_MOUNT such as tmpfs, ramfs, fuse, and overlayfs can be mounted unprivileged inside the user namespace. Bind and remount of an existing visible, unlocked mount is generally allowed in a user-namespaced mount namespace. Block device mounts, loop device attachment, and any filesystem without FS_USERNS_MOUNT still require CAP_SYS_ADMIN in the initial user namespace.
Confirmed: CAP_SYS_ADMIN is namespaced. It is not a smaller capability; the capability check is performed against the owning user namespace of the mount namespace. The set of mountable types is gated by FS_USERNS_MOUNT and by whether the mount namespace was created inside the user namespace.
Likely explanation for inconsistent behavior: EPERM is overloaded. The same error appears for different causes: mount namespace not owned by the user namespace, a non-userns-mountable filesystem, a locked inherited mount, missing loop/device access, or an LSM denial. Bind mounts can fail when the source mount was inherited locked, or when trying to clear nodev/nosuid/noexec/atime on a locked mount. Loop mounts fail because attaching a backing file to a loop device and mounting the resulting block device is not a user-namespace operation; it needs initial-namespace privilege or a pre-provisioned device and helper.
unshare -Ur -m sh -c 'grep CapEff /proc/self/status; readlink /proc/self/ns/user /proc/self/ns/mnt; mount -t tmpfs none /mnt && echo tmpfs-ok'
Success shows the namespace ownership is correct.
Version and distro effects: the core model is stable in 5.10–6.1, but backports change outcomes. FS_USERNS_MOUNT coverage, locked-mount handling, mount_setattr behavior, and unprivileged_userns_clone / user.max_user_namespaces settings are distro-specific. Mainline version alone is insufficient.
One missing diagnostic that changes the recommendation: which exact mount syscall is failing, with which errno, and on which kernel build/distro. The kernel build identifier and the exact mount command distinguish a capability/ownership problem from an LSM denial or a locked mount.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.