Skip to content

Commit 979086f

Browse files
committed
Merge tag 'fs.fixes.v5.19-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux
Pull vfs idmapping fix from Christian Brauner: "This fixes an issue where we fail to change the group of a file when the caller owns the file and is a member of the group to change to. This is only relevant on idmapped mounts. There's a detailed description in the commit message and regression tests have been added to xfstests" * tag 'fs.fixes.v5.19-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux: fs: account for group membership
2 parents 018ab4f + 168f912 commit 979086f

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

fs/attr.c

+20-6
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,15 @@ static bool chgrp_ok(struct user_namespace *mnt_userns,
6161
const struct inode *inode, kgid_t gid)
6262
{
6363
kgid_t kgid = i_gid_into_mnt(mnt_userns, inode);
64-
if (uid_eq(current_fsuid(), i_uid_into_mnt(mnt_userns, inode)) &&
65-
(in_group_p(gid) || gid_eq(gid, inode->i_gid)))
66-
return true;
64+
if (uid_eq(current_fsuid(), i_uid_into_mnt(mnt_userns, inode))) {
65+
kgid_t mapped_gid;
66+
67+
if (gid_eq(gid, inode->i_gid))
68+
return true;
69+
mapped_gid = mapped_kgid_fs(mnt_userns, i_user_ns(inode), gid);
70+
if (in_group_p(mapped_gid))
71+
return true;
72+
}
6773
if (capable_wrt_inode_uidgid(mnt_userns, inode, CAP_CHOWN))
6874
return true;
6975
if (gid_eq(kgid, INVALID_GID) &&
@@ -123,12 +129,20 @@ int setattr_prepare(struct user_namespace *mnt_userns, struct dentry *dentry,
123129

124130
/* Make sure a caller can chmod. */
125131
if (ia_valid & ATTR_MODE) {
132+
kgid_t mapped_gid;
133+
126134
if (!inode_owner_or_capable(mnt_userns, inode))
127135
return -EPERM;
136+
137+
if (ia_valid & ATTR_GID)
138+
mapped_gid = mapped_kgid_fs(mnt_userns,
139+
i_user_ns(inode), attr->ia_gid);
140+
else
141+
mapped_gid = i_gid_into_mnt(mnt_userns, inode);
142+
128143
/* Also check the setgid bit! */
129-
if (!in_group_p((ia_valid & ATTR_GID) ? attr->ia_gid :
130-
i_gid_into_mnt(mnt_userns, inode)) &&
131-
!capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID))
144+
if (!in_group_p(mapped_gid) &&
145+
!capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID))
132146
attr->ia_mode &= ~S_ISGID;
133147
}
134148

0 commit comments

Comments
 (0)