Skip to content

Commit fd84bfd

Browse files
Christian Brauneridryomov
authored andcommitted
ceph: fix up non-directory creation in SGID directories
Ceph always inherits the SGID bit if it is set on the parent inode, while the generic inode_init_owner does not do this in a few cases where it can create a possible security problem (cf. [1]). Update ceph to strip the SGID bit just as inode_init_owner would. This bug was detected by the mapped mount testsuite in [3]. The testsuite tests all core VFS functionality and semantics with and without mapped mounts. That is to say it functions as a generic VFS testsuite in addition to a mapped mount testsuite. While working on mapped mount support for ceph, SIGD inheritance was the only failing test for ceph after the port. The same bug was detected by the mapped mount testsuite in XFS in January 2021 (cf. [2]). [1]: commit 0fa3ecd ("Fix up non-directory creation in SGID directories") [2]: commit 01ea173 ("xfs: fix up non-directory creation in SGID directories") [3]: https://git.kernel.org/fs/xfs/xfstests-dev.git Cc: [email protected] Signed-off-by: Christian Brauner <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent ee2a095 commit fd84bfd

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

fs/ceph/file.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,25 @@ static int ceph_finish_async_create(struct inode *dir, struct dentry *dentry,
605605
in.cap.realm = cpu_to_le64(ci->i_snap_realm->ino);
606606
in.cap.flags = CEPH_CAP_FLAG_AUTH;
607607
in.ctime = in.mtime = in.atime = iinfo.btime;
608-
in.mode = cpu_to_le32((u32)mode);
609608
in.truncate_seq = cpu_to_le32(1);
610609
in.truncate_size = cpu_to_le64(-1ULL);
611610
in.xattr_version = cpu_to_le64(1);
612611
in.uid = cpu_to_le32(from_kuid(&init_user_ns, current_fsuid()));
613-
in.gid = cpu_to_le32(from_kgid(&init_user_ns, dir->i_mode & S_ISGID ?
614-
dir->i_gid : current_fsgid()));
612+
if (dir->i_mode & S_ISGID) {
613+
in.gid = cpu_to_le32(from_kgid(&init_user_ns, dir->i_gid));
614+
615+
/* Directories always inherit the setgid bit. */
616+
if (S_ISDIR(mode))
617+
mode |= S_ISGID;
618+
else if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP) &&
619+
!in_group_p(dir->i_gid) &&
620+
!capable_wrt_inode_uidgid(&init_user_ns, dir, CAP_FSETID))
621+
mode &= ~S_ISGID;
622+
} else {
623+
in.gid = cpu_to_le32(from_kgid(&init_user_ns, current_fsgid()));
624+
}
625+
in.mode = cpu_to_le32((u32)mode);
626+
615627
in.nlink = cpu_to_le32(1);
616628
in.max_size = cpu_to_le64(lo->stripe_unit);
617629

0 commit comments

Comments
 (0)