Skip to content

Commit

Permalink
xfs: fix up non-directory creation in SGID directories
Browse files Browse the repository at this point in the history
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 <christian.brauner@ubuntu.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
  • Loading branch information
Christoph Hellwig authored and Darrick J. Wong committed Jan 23, 2021
1 parent eaf9254 commit 01ea173
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions fs/xfs/xfs_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ xfs_init_new_inode(
prid_t prid,
struct xfs_inode **ipp)
{
struct inode *dir = pip ? VFS_I(pip) : NULL;
struct xfs_mount *mp = tp->t_mountp;
struct xfs_inode *ip;
unsigned int flags;
Expand Down Expand Up @@ -804,18 +805,17 @@ xfs_init_new_inode(

ASSERT(ip != NULL);
inode = VFS_I(ip);
inode->i_mode = mode;
set_nlink(inode, nlink);
inode->i_uid = current_fsuid();
inode->i_rdev = rdev;
ip->i_d.di_projid = prid;

if (pip && XFS_INHERIT_GID(pip)) {
inode->i_gid = VFS_I(pip)->i_gid;
if ((VFS_I(pip)->i_mode & S_ISGID) && S_ISDIR(mode))
inode->i_mode |= S_ISGID;
if (dir && !(dir->i_mode & S_ISGID) &&
(mp->m_flags & XFS_MOUNT_GRPID)) {
inode->i_uid = current_fsuid();
inode->i_gid = dir->i_gid;
inode->i_mode = mode;
} else {
inode->i_gid = current_fsgid();
inode_init_owner(inode, dir, mode);
}

/*
Expand Down

0 comments on commit 01ea173

Please sign in to comment.