public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Cc: mszeredi@redhat.com, stgraber@stgraber.org,
	 linux-fsdevel@vger.kernel.org,
	Seth Forshee <sforshee@kernel.org>,
	 Miklos Szeredi <miklos@szeredi.hu>,
	Amir Goldstein <amir73il@gmail.com>,
	 Bernd Schubert <bschubert@ddn.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 9/9] fs/fuse: allow idmapped mounts
Date: Wed, 14 Aug 2024 16:19:12 +0200	[thread overview]
Message-ID: <20240814-knochen-ersparen-9b3f366caac4@brauner> (raw)
In-Reply-To: <20240814114034.113953-10-aleksandr.mikhalitsyn@canonical.com>

On Wed, Aug 14, 2024 at 01:40:34PM GMT, Alexander Mikhalitsyn wrote:
> Now we have everything in place and we can allow idmapped mounts
> by setting the FS_ALLOW_IDMAP flag. Notice that real availability
> of idmapped mounts will depend on the fuse daemon. Fuse daemon
> have to set FUSE_ALLOW_IDMAP flag in the FUSE_INIT reply.
> 
> To discuss:
> - we enable idmapped mounts support only if "default_permissions" mode is enabled,
> because otherwise we would need to deal with UID/GID mappings in the userspace side OR
> provide the userspace with idmapped req->in.h.uid/req->in.h.gid values which is not
> something that we probably want to. Idmapped mounts phylosophy is not about faking
> caller uid/gid.
> 
> - We have a small offlist discussion with Christian around adding fs_type->allow_idmap
> hook. Christian pointed that it would be nice to have a superblock flag instead like
> SB_I_NOIDMAP and we can set this flag during mount time if we see that filesystem does not
> support idmappings. But, unfortunately I didn't succeed here because the kernel will
> know if the filesystem supports idmapping or not after FUSE_INIT request, but FUSE_INIT request
> is being sent at the end of mounting process, so mount and superblock will exist and
> visible by the userspace in that time. It seems like setting SB_I_NOIDMAP flag in this
> case is too late as user may do the trick with creating a idmapped mount while it wasn't
> restricted by SB_I_NOIDMAP. Alternatively, we can introduce a "positive" version SB_I_ALLOWIDMAP

Hm, I'm confused why won't the following (uncompiled) work?

diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index ed4c2688047f..8ead1cacdd2f 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -1346,10 +1346,12 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
                        if (flags & FUSE_OWNER_UID_GID_EXT)
                                fc->owner_uid_gid_ext = 1;
                        if (flags & FUSE_ALLOW_IDMAP) {
-                               if (fc->owner_uid_gid_ext && fc->default_permissions)
+                               if (fc->owner_uid_gid_ext && fc->default_permissions) {
                                        fc->allow_idmap = 1;
-                               else
+                                       fm->sb->s_iflags &= ~SB_I_NOIDMAP;
+                               } else {
                                        ok = false;
+                               }
                        }
                } else {
                        ra_pages = fc->max_read / PAGE_SIZE;
@@ -1576,6 +1578,7 @@ static void fuse_sb_defaults(struct super_block *sb)
        sb->s_time_gran = 1;
        sb->s_export_op = &fuse_export_operations;
        sb->s_iflags |= SB_I_IMA_UNVERIFIABLE_SIGNATURE;
+       sb->s_iflags |= SB_I_NOIDMAP;
        if (sb->s_user_ns != &init_user_ns)
                sb->s_iflags |= SB_I_UNTRUSTED_MOUNTER;
        sb->s_flags &= ~(SB_NOSEC | SB_I_VERSION);
diff --git a/fs/namespace.c b/fs/namespace.c
index 328087a4df8a..d1702285c915 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -4436,6 +4436,10 @@ static int can_idmap_mount(const struct mount_kattr *kattr, struct mount *mnt)
        if (!(m->mnt_sb->s_type->fs_flags & FS_ALLOW_IDMAP))
                return -EINVAL;

+       /* The filesystem has turned off idmapped mounts. */
+       if (m->mnt_sb->s_iflags & SB_I_NOIDMAP)
+               return -EINVAL;
+
        /* We're not controlling the superblock. */
        if (!ns_capable(fs_userns, CAP_SYS_ADMIN))
                return -EPERM;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index fd34b5755c0b..185004c41a5e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1189,6 +1189,7 @@ extern int send_sigurg(struct fown_struct *fown);
 #define SB_I_TS_EXPIRY_WARNED 0x00000400 /* warned about timestamp range expiry */
 #define SB_I_RETIRED   0x00000800      /* superblock shouldn't be reused */
 #define SB_I_NOUMASK   0x00001000      /* VFS does not apply umask */
+#define SB_I_NOIDMAP   0x00002000      /* No idmapped mounts on this superblock */

 /* Possible states of 'frozen' field */
 enum {

  reply	other threads:[~2024-08-14 14:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-14 11:40 [PATCH v2 0/9] fuse: basic support for idmapped mounts Alexander Mikhalitsyn
2024-08-14 11:40 ` [PATCH v2 1/9] fs/fuse: add FUSE_OWNER_UID_GID_EXT extension Alexander Mikhalitsyn
2024-08-14 11:40 ` [PATCH v2 2/9] fs/fuse: support idmap for mkdir/mknod/symlink/create Alexander Mikhalitsyn
2024-08-14 11:40 ` [PATCH v2 3/9] fs/fuse: support idmapped getattr inode op Alexander Mikhalitsyn
2024-08-14 11:40 ` [PATCH v2 4/9] fs/fuse: support idmapped ->permission " Alexander Mikhalitsyn
2024-08-14 11:40 ` [PATCH v2 5/9] fs/fuse: support idmapped ->setattr op Alexander Mikhalitsyn
2024-08-14 11:40 ` [PATCH v2 6/9] fs/fuse: drop idmap argument from __fuse_get_acl Alexander Mikhalitsyn
2024-08-14 11:40 ` [PATCH v2 7/9] fs/fuse: support idmapped ->set_acl Alexander Mikhalitsyn
2024-08-14 11:40 ` [PATCH v2 8/9] fs/fuse: properly handle idmapped ->rename op Alexander Mikhalitsyn
2024-08-14 11:40 ` [PATCH v2 9/9] fs/fuse: allow idmapped mounts Alexander Mikhalitsyn
2024-08-14 14:19   ` Christian Brauner [this message]
2024-08-15  8:08     ` Aleksandr Mikhalitsyn
2024-08-15 13:20       ` 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=20240814-knochen-ersparen-9b3f366caac4@brauner \
    --to=brauner@kernel.org \
    --cc=aleksandr.mikhalitsyn@canonical.com \
    --cc=amir73il@gmail.com \
    --cc=bschubert@ddn.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=mszeredi@redhat.com \
    --cc=sforshee@kernel.org \
    --cc=stgraber@stgraber.org \
    /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