From: Jeff Layton <jlayton@kernel.org>
To: "Seth Forshee (DigitalOcean)" <sforshee@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>
Cc: Amir Goldstein <amir73il@gmail.com>,
Aleksa Sarai <cyphar@cyphar.com>,
Alexander Mikhalitsyn <alexander@mihalicyn.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-nfs@vger.kernel.org
Subject: Re: [PATCH] fs: don't allow non-init s_user_ns for filesystems without FS_USERNS_MOUNT
Date: Thu, 29 Jan 2026 09:36:54 -0500 [thread overview]
Message-ID: <b02d93c9cd1ccda04127031155ec9b4c29ee69d5.camel@kernel.org> (raw)
In-Reply-To: <20240724-s_user_ns-fix-v1-1-895d07c94701@kernel.org>
On Wed, 2024-07-24 at 09:53 -0500, Seth Forshee (DigitalOcean) wrote:
> Christian noticed that it is possible for a privileged user to mount
> most filesystems with a non-initial user namespace in sb->s_user_ns.
> When fsopen() is called in a non-init namespace the caller's namespace
> is recorded in fs_context->user_ns. If the returned file descriptor is
> then passed to a process priviliged in init_user_ns, that process can
> call fsconfig(fd_fs, FSCONFIG_CMD_CREATE), creating a new superblock
> with sb->s_user_ns set to the namespace of the process which called
> fsopen().
>
> This is problematic. We cannot assume that any filesystem which does not
> set FS_USERNS_MOUNT has been written with a non-initial s_user_ns in
> mind, increasing the risk for bugs and security issues.
>
> Prevent this by returning EPERM from sget_fc() when FS_USERNS_MOUNT is
> not set for the filesystem and a non-initial user namespace will be
> used. sget() does not need to be updated as it always uses the user
> namespace of the current context, or the initial user namespace if
> SB_SUBMOUNT is set.
>
> Fixes: cb50b348c71f ("convenience helpers: vfs_get_super() and sget_fc()")
> Reported-by: Christian Brauner <brauner@kernel.org>
> Signed-off-by: Seth Forshee (DigitalOcean) <sforshee@kernel.org>
> ---
> fs/super.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/fs/super.c b/fs/super.c
> index 095ba793e10c..d681fb7698d8 100644
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -736,6 +736,17 @@ struct super_block *sget_fc(struct fs_context *fc,
> struct user_namespace *user_ns = fc->global ? &init_user_ns : fc->user_ns;
> int err;
>
> + /*
> + * Never allow s_user_ns != &init_user_ns when FS_USERNS_MOUNT is
> + * not set, as the filesystem is likely unprepared to handle it.
> + * This can happen when fsconfig() is called from init_user_ns with
> + * an fs_fd opened in another user namespace.
> + */
> + if (user_ns != &init_user_ns && !(fc->fs_type->fs_flags & FS_USERNS_MOUNT)) {
> + errorfc(fc, "mounting from non-initial user namespace is not allowed");
> + return ERR_PTR(-EPERM);
> + }
> +
> retry:
> spin_lock(&sb_lock);
> if (test) {
>
> ---
> base-commit: 256abd8e550ce977b728be79a74e1729438b4948
> change-id: 20240723-s_user_ns-fix-b00c31de1cb8
>
> Best regards,
I sent an incorrect RFC patch for this yesterday, but this patch breaks
NFS mounting in containers for us, as the prohibited activity is
exactly the process we use to do them.
We basically have a task in the container do an fsopen() and then pass
the fd to a daemon in the init namespace via unix socket. The daemon
vets the NFS mount parameters (ensuring that the mount options are
sane, and that we trust the server), and then does the mount inside the
container.
We don't want to set FS_USERNS_MOUNT on NFS, because that would give
the container carte blanche to mount anything it likes, even a
malicious server. Do we need to split that flag into two? Maybe
FS_USERNS_SAFE and FS_USERNS_MOUNT?
--
Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2026-01-29 14:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-24 14:53 [PATCH] fs: don't allow non-init s_user_ns for filesystems without FS_USERNS_MOUNT Seth Forshee (DigitalOcean)
2024-07-24 15:17 ` Alexander Mikhalitsyn
2024-07-25 8:19 ` Christian Brauner
2026-01-29 14:36 ` Jeff Layton [this message]
2026-01-29 15:49 ` Christian Brauner
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=b02d93c9cd1ccda04127031155ec9b4c29ee69d5.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=alexander@mihalicyn.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=cyphar@cyphar.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=sforshee@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