nfs: use vfs setgid helper
authorChristian Brauner <brauner@kernel.org>
Tue, 14 Mar 2023 11:51:10 +0000 (12:51 +0100)
committerChristian Brauner <brauner@kernel.org>
Thu, 30 Mar 2023 06:51:48 +0000 (08:51 +0200)
We've aligned setgid behavior over multiple kernel releases. The details
can be found in the following two merge messages:
cf619f891971 ("Merge tag 'fs.ovl.setgid.v6.2')
426b4ca2d6a5 ("Merge tag 'fs.setgid.v6.0')
Consistent setgid stripping behavior is now encapsulated in the
setattr_should_drop_sgid() helper which is used by all filesystems that
strip setgid bits outside of vfs proper. Switch nfs to rely on this
helper as well. Without this patch the setgid stripping tests in
xfstests will fail.

Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Message-Id: <20230313-fs-nfs-setgid-v2-1-9a59f436cfc0@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/attr.c
fs/internal.h
fs/nfs/inode.c
include/linux/fs.h

index aca9ff7aed3331c31848cf6bf7480bd4b9e27187..d60dc1edb526885584bf62b74da1542e271a8f7d 100644 (file)
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -47,6 +47,7 @@ int setattr_should_drop_sgid(struct mnt_idmap *idmap,
                return ATTR_KILL_SGID;
        return 0;
 }
+EXPORT_SYMBOL(setattr_should_drop_sgid);
 
 /**
  * setattr_should_drop_suidgid - determine whether the set{g,u}id bit needs to
index dc4eb91a577a80f16a3f49729e8c6f6dec2aeb3b..ab36ed8fa41caf2134cb5a1f0599a7f80590bf7c 100644 (file)
@@ -259,8 +259,6 @@ ssize_t __kernel_write_iter(struct file *file, struct iov_iter *from, loff_t *po
 /*
  * fs/attr.c
  */
-int setattr_should_drop_sgid(struct mnt_idmap *idmap,
-                            const struct inode *inode);
 struct mnt_idmap *alloc_mnt_idmap(struct user_namespace *mnt_userns);
 struct mnt_idmap *mnt_idmap_get(struct mnt_idmap *idmap);
 void mnt_idmap_put(struct mnt_idmap *idmap);
index 222a28320e1c211efd6c7898d26855931863cbab..97a76706fd542b9aa149a578a04aa8b42bbf2aad 100644 (file)
@@ -717,9 +717,7 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
                if ((attr->ia_valid & ATTR_KILL_SUID) != 0 &&
                    inode->i_mode & S_ISUID)
                        inode->i_mode &= ~S_ISUID;
-               if ((attr->ia_valid & ATTR_KILL_SGID) != 0 &&
-                   (inode->i_mode & (S_ISGID | S_IXGRP)) ==
-                    (S_ISGID | S_IXGRP))
+               if (setattr_should_drop_sgid(&nop_mnt_idmap, inode))
                        inode->i_mode &= ~S_ISGID;
                if ((attr->ia_valid & ATTR_MODE) != 0) {
                        int mode = attr->ia_mode & S_IALLUGO;
index c85916e9f7db500474d043c1f6a6b5e5c8d22020..af95b64fc810cce98d8cc9002944de781d396c15 100644 (file)
@@ -2675,6 +2675,8 @@ extern struct inode *new_inode(struct super_block *sb);
 extern void free_inode_nonrcu(struct inode *inode);
 extern int setattr_should_drop_suidgid(struct mnt_idmap *, struct inode *);
 extern int file_remove_privs(struct file *);
+int setattr_should_drop_sgid(struct mnt_idmap *idmap,
+                            const struct inode *inode);
 
 /*
  * This must be used for allocating filesystems specific inodes to set