]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nfs: use vfs setgid helper
authorChristian Brauner <brauner@kernel.org>
Tue, 14 Mar 2023 11:51:10 +0000 (12:51 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 30 Aug 2023 14:18:19 +0000 (16:18 +0200)
commit 4f704d9a8352f5c0a8fcdb6213b934630342bd44 upstream.

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>
[ Harshit: backport to 5.15.y]
    fs/internal.h -- minor conflcit due to code change differences.
    include/linux/fs.h -- Used struct user_namespace *mnt_userns
                          instead of struct mnt_idmap *idmap
    fs/nfs/inode.c -- Used init_user_ns instead of nop_mnt_idmap ]
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/attr.c
fs/internal.h
fs/nfs/inode.c
include/linux/fs.h

index 0ca14cbd4b8bb4ab78623f5fb575090bccfb17d5..28e953e86960fc0de4b2544217e1acd82af1774d 100644 (file)
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -47,6 +47,7 @@ int setattr_should_drop_sgid(struct user_namespace *mnt_userns,
                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 1ff8cfc94467bf95ff2e2ed6ebf0683f036ae8ff..d241eaa0c58b22a2587c05869b8b47adfa9e1fab 100644 (file)
@@ -235,5 +235,3 @@ int do_setxattr(struct user_namespace *mnt_userns, struct dentry *dentry,
 /*
  * fs/attr.c
  */
-int setattr_should_drop_sgid(struct user_namespace *mnt_userns,
-                            const struct inode *inode);
index e4524635a129a080823d018f31ad200114eb3693..d8f01d222c499b07c0b34b8d5b72bd5d0624aa0d 100644 (file)
@@ -731,9 +731,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(&init_user_ns, inode))
                        inode->i_mode &= ~S_ISGID;
                if ((attr->ia_valid & ATTR_MODE) != 0) {
                        int mode = attr->ia_mode & S_IALLUGO;
index c0dd2794e1ba0b941bab5981d87b0d3df8c73a80..6bba7a58c95c669819bfca1b32dae5677138abe0 100644 (file)
@@ -3135,6 +3135,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 user_namespace *, struct inode *);
 extern int file_remove_privs(struct file *);
+int setattr_should_drop_sgid(struct user_namespace *mnt_userns,
+                            const struct inode *inode);
 
 extern void __insert_inode_hash(struct inode *, unsigned long hashval);
 static inline void insert_inode_hash(struct inode *inode)