Skip to content

Commit 6697f29

Browse files
Christian Braunergregkh
authored andcommitted
ceph: fix up non-directory creation in SGID directories
commit fd84bfd upstream. 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: stable@vger.kernel.org Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fffb658 commit 6697f29

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎fs/ceph/file.c‎

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

0 commit comments

Comments
 (0)