[PATCH] Documentation: failfs: setns() back out needs no privileges
From: Ozan Ağdepe (NullSecurityX)
Date: Sat Nov 21 2026 - 14:35:03 EST
The "Leaving" section says the remaining way out of failfs is setns()
with a mount namespace file descriptor and that it requires
CAP_SYS_ADMIN over the target mount namespace as well as CAP_SYS_CHROOT
and CAP_SYS_ADMIN in the caller's user namespace. That reads as if an
unprivileged task in failfs that holds no namespace file descriptor
cannot get out.
It can. A pidfd names the namespaces of another task without a path
lookup. create_user_ns() refuses chrooted callers, but userns_install()
does not, and the caller owns every user namespace created by its
effective uid below its own. setns(pidfd, CLONE_NEWUSER | CLONE_NEWNS)
on a task that runs in such a user namespace and in a mount namespace
owned by it passes validate_nsset(), userns_install() and
mntns_install(), and mntns_install() resets root and working directory
to the root of that mount namespace. Rootless containers, bubblewrap
and browser sandboxes all run such tasks.
Verified on v7.3 with an unprivileged caller: after
fchroot(FD_FAILFS_ROOT) open("/etc/passwd") and unshare(CLONE_NEWUSER)
fail as documented, and after setns(pidfd, CLONE_NEWUSER | CLONE_NEWNS)
open("/etc/passwd") succeeds.
The section already says leaving is not a guaranteed interface and that
seccomp has to restrict setns() among others, so only describe the path
accurately.
The issue was found during an AI-assisted review of fs/ and
kernel/user_namespace.c. The reproducer, the documentation text and
this changelog were drafted with the assistant and reviewed and tested
by the submitter.
Fixes: a45a6605cd04 ("Documentation: add failfs documentation")
Signed-off-by: Ozan Ağdepe (NullSecurityX) <agdepeozan@xxxxxxxxx>
---
Documentation/filesystems/failfs.rst | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/Documentation/filesystems/failfs.rst b/Documentation/filesystems/failfs.rst
index 21ff2db79..c34e29403 100644
--- a/Documentation/filesystems/failfs.rst
+++ b/Documentation/filesystems/failfs.rst
@@ -65,9 +65,18 @@ implementation, not a guaranteed interface, and may be loosened later.
For now a process that entered failfs counts as chrooted, so it cannot
create user namespaces to regain ``CAP_SYS_CHROOT``, and ``chroot(2)``
or ``fchroot(2)`` back out require ``CAP_SYS_CHROOT``. The remaining way
-out today is ``setns(2)`` with a mount namespace file descriptor, which
-requires ``CAP_SYS_ADMIN`` over the target mount namespace as well as
+out today is ``setns(2)`` into a mount namespace, which requires
+``CAP_SYS_ADMIN`` over the target mount namespace as well as
``CAP_SYS_CHROOT`` and ``CAP_SYS_ADMIN`` in the caller's user namespace
-and resets both root and working directory. A process that holds no such
-file descriptor and restricts ``*chdir()``/``*chroot()``/``setns()`` via
-seccomp cannot currently get back out.
+and resets both root and working directory.
+
+That way out does not need privileges or a namespace file descriptor. A
+pidfd names the namespaces of another task without a path lookup, and
+joining an existing user namespace is not refused for a chrooted task
+the way creating one is. An unprivileged caller can thus leave with
+``setns(pidfd, CLONE_NEWUSER | CLONE_NEWNS)`` on any task it may access
+in ``PTRACE_MODE_READ`` mode that runs in a user namespace owned by the
+caller's effective uid and in a mount namespace owned by that user
+namespace. A process that restricts
+``*chdir()``/``*chroot()``/``setns()`` via seccomp cannot currently get
+back out.
--
2.53.0