Linux Documentation
 help / color / mirror / Atom feed
From: "Ozan Ağdepe (NullSecurityX)" <agdepeozan@gmail.com>
To: brauner@kernel.org, viro@zeniv.linux.org.uk
Cc: jack@suse.cz, corbet@lwn.net, linux-fsdevel@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Ozan Ağdepe (NullSecurityX)" <agdepeozan@gmail.com>
Subject: [PATCH] Documentation: failfs: setns() back out needs no privileges
Date: Sat, 21 Nov 2026 22:34:46 +0300	[thread overview]
Message-ID: <20261121193446.105396-1-agdepeozan@gmail.com> (raw)

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@gmail.com>
---
 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


                 reply	other threads:[~2026-11-21 19:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261121193446.105396-1-agdepeozan@gmail.com \
    --to=agdepeozan@gmail.com \
    --cc=brauner@kernel.org \
    --cc=corbet@lwn.net \
    --cc=jack@suse.cz \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox