~/posts/kernel/failfs-setns-without-privileges.mdlast change dfdc34c · 29 Nov 2026
● mediumlinux 7.3 / failfs0x03

Leaving failfs without privileges: our first kernel patch

Linux 7.3's failfs lets a process lock itself out of the filesystem, and its documentation implied that getting back out needs privileges or a namespace fd. An unprivileged process can leave with one setns() call on a pidfd. We confirmed it on v7.3 and reported it on the kernel lists with a patch.

Linux 7.3 added failfs, a way for an ordinary process to lock itself out of the filesystem. Its documentation described leaving as something that needs privileges or a namespace file descriptor the process already holds. We found that an unprivileged process with neither can get out with a single setns() call on a pidfd, confirmed it on v7.3, and reported it on the kernel mailing lists together with a patch.

This post walks through the sandbox, the way out, the kernel code that allows it, and how we decided what kind of report it deserved.

Step 1: What failfs is

failfs arrived in Linux 7.3. It is a kernel-internal filesystem whose every operation fails with EOPNOTSUPP. It can't be mounted from userspace and nothing can be mounted on top of it. The only way in is a sentinel file descriptor, FD_FAILFS_ROOT, that fchdir() and fchroot() understand.

The idea is simple. A process that moves its root directory into failfs can no longer resolve any absolute path: not /etc/passwd, not an absolute symlink, not even the dynamic loader of a binary it tries to exec. What still works is lookup relative to directory file descriptors the process already holds. In other words, failfs forces a process into fd-based access only, the fs_struct equivalent of RESOLVE_BENEATH.

Step 2: How an unprivileged process gets in

Normally fchroot(FD_FAILFS_ROOT, 0) needs CAP_SYS_CHROOT, like chroot(). The point of failfs, though, is that ordinary programs can lock themselves down, so an unprivileged caller is allowed in when three conditions hold:

  1. no_new_privs is set. Otherwise a setuid binary reached through an inherited directory fd could run with an unusable root, a classic confused-deputy setup.
  2. The caller is not already chrooted. The failfs root can't be reached by walking up a real mount tree, so moving a chrooted task into failfs would let it escape its chroot with openat(fd, "..").
  3. The caller does not share its fs_struct (fs->users == 1), the same rule setns() applies to mount and user namespaces.
entering · c
prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
fchroot(FD_FAILFS_ROOT, 0);                  /* no capabilities needed now */

open("/etc/passwd", O_RDONLY);               /* -> EOPNOTSUPP */

Step 3: Why getting out is supposed to be hard

The documentation has a "Leaving" section that explains why a process in failfs can't easily undo it:

  • A failfs root counts as chrooted for current_chrooted(), and create_user_ns() refuses to create a user namespace for a chrooted task. So the process can't unshare(CLONE_NEWUSER) to give itself CAP_SYS_CHROOT in a fresh namespace.
  • chroot() and fchroot() back out require CAP_SYS_CHROOT, which it doesn't have.
  • The remaining route is setns() into a mount namespace, which resets root and working directory. The documentation said this needs CAP_SYS_ADMIN over the target mount namespace plus CAP_SYS_CHROOT and CAP_SYS_ADMIN in the caller's user namespace, and that a process without such a namespace fd, with *chdir(), *chroot() and setns() filtered by seccomp, cannot get back out.

That last paragraph reads as: an unprivileged process that does not already hold a namespace fd is stuck. We set out to test that.

Step 4: Getting a namespace handle without the filesystem

The classic way to reference another process's namespaces is a path: /proc/<pid>/ns/mnt. In failfs that's an absolute path, so it fails. But since Linux 5.8, setns() also accepts a pidfd, and pidfd_open() takes a number, not a path:

c
int pfd = pidfd_open(target_pid, 0);   /* no path lookup at all */

pidfd_open() itself requires no permission over the target. The permission check comes later, inside setns(), where validate_nsset() asks for ptrace_may_access(tsk, PTRACE_MODE_READ_REALCREDS). For a process owned by the same user that is a read-level check, and it passes.

So the escape needs one ingredient: another process the caller 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. On a desktop those are everywhere: rootless containers, bubblewrap sandboxes (and so flatpak apps), browser sandbox helpers.

Step 5: Joining a user namespace without creating one

setns(pfd, CLONE_NEWUSER | CLONE_NEWNS) joins both namespaces of the target in one call. The kernel handles the user namespace first, so the credentials it grants are the ones used to check the mount namespace.

The user namespace part goes through userns_install(). Its checks, in order:

kernel/user_namespace.c (checks in userns_install) · c
if (user_ns == current_user_ns())             return -EINVAL;  /* not the same ns */
if (!thread_group_empty(current))             return -EINVAL;  /* single-threaded */
if (current->fs->users != 1)                  return -EINVAL;  /* unshared fs_struct */
if (!ns_capable(user_ns, CAP_SYS_ADMIN))      return -EPERM;

There is no current_chrooted() check here. create_user_ns() has one, so a chrooted task can't create a user namespace, but nothing stops it from joining an existing one.

The capability check passes too. The caller owns every user namespace that its effective uid created below its own, and the owner of a user namespace has every capability inside it. After the switch, our process holds a full capability set in that namespace.

Note that the third condition from step 2 (fs->users == 1) is exactly what userns_install() and mntns_install() want as well, so a process that was allowed into failfs automatically meets it.

Step 6: The mount namespace resets the root

mntns_install() now checks CAP_SYS_ADMIN over the target mount namespace and CAP_SYS_CHROOT plus CAP_SYS_ADMIN in the caller's user namespace. All three are satisfied by the credentials from step 5: the "caller's user namespace" is now the one we just joined.

Then it does what the documentation says it does:

fs/namespace.c (end of mntns_install, simplified) · c
/* Find the root */
...
set_fs_pwd(fs, &root);
set_fs_root(fs, &root);

Root and working directory point at the root of the joined mount namespace. failfs is gone, and absolute paths work again.

Step 7: The whole chain

Simplified version of our test program. It creates its own "holder" process first, standing in for a flatpak or container process, so the test doesn't depend on what happens to be running:

failfs_setns_userns.c (simplified) · c
/* 1. holder: same uid, its own user + mount namespace */
pid_t holder = fork();
if (holder == 0) {
    unshare(CLONE_NEWUSER | CLONE_NEWNS);
    pause();
}
sleep(1);

/* 2. lock ourselves into failfs */
prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
fchroot(FD_FAILFS_ROOT, 0);
report("open(/etc/passwd)", open("/etc/passwd", O_RDONLY));    /* EOPNOTSUPP */
report("unshare(NEWUSER)", unshare(CLONE_NEWUSER));             /* EPERM */

/* 3. out through the holder's namespaces */
int pfd = pidfd_open(holder, 0);                                /* no path */
setns(pfd, CLONE_NEWUSER | CLONE_NEWNS);                        /* succeeds */
report("open(/etc/passwd)", open("/etc/passwd", O_RDONLY));    /* succeeds */

In a real sandbox the PID wouldn't even need to be known in advance: pidfd_open() needs no permission, so a loop over the PID range finds candidates, and setns() simply fails on the ones that don't qualify. We didn't need that for the test.

Step 8: Confirming it on 7.3.0

We built 7.3.0 with virtme-ng, which boots a freshly built kernel in a lightweight VM that shares the host's filesystem. The default minimal config had CONFIG_USER_NS disabled, so we enabled it before building. Then we ran the program as an ordinary user (uid 1000):

kernel 7.3.0-virtme · uid=1000 · text
$ ls /proc/self/ns/
cgroup ipc mnt net pid pid_for_children time time_for_children user uts
$ ./failfs_setns_userns
in failfs: open("/etc/passwd") -> EOPNOTSUPP, unshare(CLONE_NEWUSER) -> EPERM
AFFECTED: after setns() the root is no longer failfs; open("/etc/passwd") succeeded

The first line proves failfs was active: absolute paths failed and creating a user namespace was refused. The second shows the root was back after setns().

Step 9: Is it a vulnerability?

This is where it is worth slowing down. We had a reproducible escape from a sandbox, on a release kernel, needing no privileges. It is tempting to call that a CVE. We checked three things first.

What the documentation promises. The "Leaving" section describes the difficulty of leaving as a property of the current implementation, not a guaranteed interface, and recommends seccomp filtering of setns() for a full lockdown. A sandbox that follows that advice is not affected: our chain needs setns().

What the maintainers said. In the RFC discussion, Andy Lutomirski argued that the restriction should not be promised at all, and Christian Brauner said he had considered closing this kind of route but found it too risky to bring in with this series. The behaviour was known territory, not an oversight.

What the attacker gains. No other user's data is reached and no new privilege is obtained. The process only leaves a restriction it placed on itself, and ends up with exactly the access its uid already had before entering failfs.

Taken together, we did not treat it as a vulnerability in the CVE sense, and we didn't send it to the private security list. But it is a real, unprivileged way out of failfs that the documentation said did not exist, and anyone building a sandbox on top of failfs needs to know about it. The right place for that is in public, on the lists where failfs is developed, with a patch that puts the facts into the documentation sandbox authors will read.

Step 10: The report and the patch

The mail went to linux-fsdevel, linux-doc and LKML on 21 November 2026. Its changelog is the report itself, in kernel style:

  1. What the documentation claims. The "Leaving" section names setns() with a mount namespace fd as the remaining way out and lists the capabilities it needs, which reads as if a task with no namespace fd is stuck.
  2. Why that is wrong. A pidfd names another task's namespaces without a path lookup. create_user_ns() refuses chrooted callers but userns_install() doesn't, and the caller owns every user namespace its effective uid created below its own. So setns(pidfd, CLONE_NEWUSER | CLONE_NEWNS) passes validate_nsset(), userns_install() and mntns_install(), and the last one resets root and working directory.
  3. Where it matters. Rootless containers, bubblewrap and browser sandboxes all run suitable tasks.
  4. Proof. Verified on v7.3 with an unprivileged caller: inside failfs, open("/etc/passwd") and unshare(CLONE_NEWUSER) fail as documented; after the setns() call, open("/etc/passwd") succeeds.
  5. Scope of the change. The section already says leaving is not a guaranteed interface and that seccomp has to restrict setns(), so the patch only describes the path accurately.

The diff touches one file, Documentation/filesystems/failfs.rst (14 insertions, 5 deletions):

Documentation/filesystems/failfs.rst · diff
@@ -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.

Two details in the new text are deliberate. "With a mount namespace file descriptor" became "into a mount namespace", because a pidfd works just as well. And the last sentence now ties "cannot get back out" to the seccomp restriction alone, not to the absence of a namespace fd.

If a maintainer later decides the route should be closed in code instead, the obvious candidate is a current_chrooted() check in userns_install(), mirroring the one in create_user_ns(). We left that decision to the people who designed failfs.

How a kernel patch is sent

For anyone doing it for the first time:

  1. Commit the change in a kernel tree with a subject in the subsystem's style (Documentation: failfs: ...), a body that explains why, and a Signed-off-by: line.
  2. Add a Fixes: tag pointing at the commit that introduced the text being corrected, here a45a6605cd04 ("Documentation: add failfs documentation").
  3. Produce the patch with git format-patch and run scripts/checkpatch.pl on it.
  4. Find the recipients with scripts/get_maintainer.pl.
  5. Send it as plain text with git send-email. Kernel lists don't take attachments or HTML mail.

At the time of writing the patch is waiting for review.

What we learned

  • Classify before you report. Whether an escape is a vulnerability depends on what was promised. Reading the documentation, the threat model and the design discussion first told us where the report belonged: a public patch, not a private security list.
  • Join is not create. Kernel checks often guard the creation of an object and not the act of entering an existing one. create_user_ns() vs userns_install() is a textbook example.
  • Path-free handles change sandbox assumptions. pidfds made namespaces reachable without /proc years before failfs existed. Any new sandbox that relies on "no paths" has to account for them.
  • Code reading alone is getting crowded. Patterns that can be found by reading (SMB ACL parsing, count fields in drivers, __counted_by) are scanned heavily by syzbot, AI systems and hardening teams. Most remaining bugs only show up at runtime. Our next step is fuzzing an under-covered subsystem with syzkaller on a KASAN kernel.

Method note: The issue was found during an AI-assisted review of fs/ and kernel/user_namespace.c. The reproducer, the documentation text and the changelog were drafted with the assistant, then reviewed and tested by us. The patch changelog says the same.

Get the next post by email

One email when something new is published.