提交 0a6d21a3 编写于 作者: C Christoph Hellwig 提交者: Zheng Zengkai

xfs: fix up non-directory creation in SGID directories

mainline inclusion
from mainline-v5.11-rc4
commit 01ea173e
category: bugfix
bugzilla: 185881 https://gitee.com/openeuler/kernel/issues/I4DDEL
CVE: CVE-2021-4037

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=01ea173e103edd5ec41acec65b9261b87e123fc2

-------------------------------------------------

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 0fa3ecd8
("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: 1da177e4 ("Linux-2.6.12-rc2")
Reported-by: NChristian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
Signed-off-by: NDarrick J. Wong <djwong@kernel.org>

conflicts:
fs/xfs/xfs_inode.c
Signed-off-by: NGuo Xuenan <guoxuenan@huawei.com>
Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
Reviewed-by: NXiu Jianfeng <xiujianfeng@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 9c7e37e5
...@@ -802,6 +802,7 @@ xfs_ialloc( ...@@ -802,6 +802,7 @@ xfs_ialloc(
xfs_buf_t **ialloc_context, xfs_buf_t **ialloc_context,
xfs_inode_t **ipp) xfs_inode_t **ipp)
{ {
struct inode *dir = pip ? VFS_I(pip) : NULL;
struct xfs_mount *mp = tp->t_mountp; struct xfs_mount *mp = tp->t_mountp;
xfs_ino_t ino; xfs_ino_t ino;
xfs_inode_t *ip; xfs_inode_t *ip;
...@@ -847,18 +848,17 @@ xfs_ialloc( ...@@ -847,18 +848,17 @@ xfs_ialloc(
return error; return error;
ASSERT(ip != NULL); ASSERT(ip != NULL);
inode = VFS_I(ip); inode = VFS_I(ip);
inode->i_mode = mode;
set_nlink(inode, nlink); set_nlink(inode, nlink);
inode->i_uid = current_fsuid();
inode->i_rdev = rdev; inode->i_rdev = rdev;
ip->i_d.di_projid = prid; ip->i_d.di_projid = prid;
if (pip && XFS_INHERIT_GID(pip)) { if (dir && !(dir->i_mode & S_ISGID) &&
inode->i_gid = VFS_I(pip)->i_gid; (mp->m_flags & XFS_MOUNT_GRPID)) {
if ((VFS_I(pip)->i_mode & S_ISGID) && S_ISDIR(mode)) inode->i_uid = current_fsuid();
inode->i_mode |= S_ISGID; inode->i_gid = dir->i_gid;
inode->i_mode = mode;
} else { } else {
inode->i_gid = current_fsgid(); inode_init_owner(inode, dir, mode);
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册