attr: use consistent sgid stripping checks
[platform/kernel/linux-starfive.git] / fs / open.c
index a81319b..9d0197d 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -54,7 +54,7 @@ int do_truncate(struct user_namespace *mnt_userns, struct dentry *dentry,
        }
 
        /* Remove suid, sgid, and file capabilities on truncate too */
-       ret = dentry_needs_remove_privs(dentry);
+       ret = dentry_needs_remove_privs(mnt_userns, dentry);
        if (ret < 0)
                return ret;
        if (ret)
@@ -723,10 +723,10 @@ retry_deleg:
                return -EINVAL;
        if ((group != (gid_t)-1) && !setattr_vfsgid(&newattrs, gid))
                return -EINVAL;
-       if (!S_ISDIR(inode->i_mode))
-               newattrs.ia_valid |=
-                       ATTR_KILL_SUID | ATTR_KILL_SGID | ATTR_KILL_PRIV;
        inode_lock(inode);
+       if (!S_ISDIR(inode->i_mode))
+               newattrs.ia_valid |= ATTR_KILL_SUID | ATTR_KILL_PRIV |
+                                    setattr_should_drop_sgid(mnt_userns, inode);
        /* Continue to send actual fs values, not the mount values. */
        error = security_path_chown(
                path,