Skip to content

Commit 01ea173

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: fix up non-directory creation in SGID directories
XFS 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, see commit 0fa3ecd ("Fix up non-directory creation in SGID directories") for details. Switch XFS to use the generic helper for the normal path to fix this, just keeping the simple field inheritance open coded for the case of the non-sgid case with the bsdgrpid mount option. Fixes: 1da177e ("Linux-2.6.12-rc2") Reported-by: Christian Brauner <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent eaf9254 commit 01ea173

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

fs/xfs/xfs_inode.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ xfs_init_new_inode(
775775
prid_t prid,
776776
struct xfs_inode **ipp)
777777
{
778+
struct inode *dir = pip ? VFS_I(pip) : NULL;
778779
struct xfs_mount *mp = tp->t_mountp;
779780
struct xfs_inode *ip;
780781
unsigned int flags;
@@ -804,18 +805,17 @@ xfs_init_new_inode(
804805

805806
ASSERT(ip != NULL);
806807
inode = VFS_I(ip);
807-
inode->i_mode = mode;
808808
set_nlink(inode, nlink);
809-
inode->i_uid = current_fsuid();
810809
inode->i_rdev = rdev;
811810
ip->i_d.di_projid = prid;
812811

813-
if (pip && XFS_INHERIT_GID(pip)) {
814-
inode->i_gid = VFS_I(pip)->i_gid;
815-
if ((VFS_I(pip)->i_mode & S_ISGID) && S_ISDIR(mode))
816-
inode->i_mode |= S_ISGID;
812+
if (dir && !(dir->i_mode & S_ISGID) &&
813+
(mp->m_flags & XFS_MOUNT_GRPID)) {
814+
inode->i_uid = current_fsuid();
815+
inode->i_gid = dir->i_gid;
816+
inode->i_mode = mode;
817817
} else {
818-
inode->i_gid = current_fsgid();
818+
inode_init_owner(inode, dir, mode);
819819
}
820820

821821
/*

0 commit comments

Comments
 (0)