Skip to content

Commit fd5e2aa

Browse files
Dwight EngenBen Myers
authored andcommitted
xfs: ioctl check for capabilities in the current user namespace
Use inode_capable() to check if SUID|SGID bits should be cleared to match similar check in inode_change_ok(). The check for CAP_LINUX_IMMUTABLE was not modified since all other file systems also check against init_user_ns rather than current_user_ns. Only allow changing of projid from init_user_ns. Reviewed-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Gao feng <gaofeng@cn.fujitsu.com> Signed-off-by: Dwight Engen <dwight.engen@oracle.com> Signed-off-by: Ben Myers <bpm@sgi.com>
1 parent 288bbe0 commit fd5e2aa

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎fs/xfs/xfs_ioctl.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,15 +1015,22 @@ xfs_ioctl_setattr(
10151015
* to the file owner ID, except in cases where the
10161016
* CAP_FSETID capability is applicable.
10171017
*/
1018-
if (current_fsuid() != ip->i_d.di_uid && !capable(CAP_FOWNER)) {
1018+
if (!inode_owner_or_capable(VFS_I(ip))) {
10191019
code = XFS_ERROR(EPERM);
10201020
goto error_return;
10211021
}
10221022

10231023
/*
10241024
* Do a quota reservation only if projid is actually going to change.
1025+
* Only allow changing of projid from init_user_ns since it is a
1026+
* non user namespace aware identifier.
10251027
*/
10261028
if (mask & FSX_PROJID) {
1029+
if (current_user_ns() != &init_user_ns) {
1030+
code = XFS_ERROR(EINVAL);
1031+
goto error_return;
1032+
}
1033+
10271034
if (XFS_IS_QUOTA_RUNNING(mp) &&
10281035
XFS_IS_PQUOTA_ON(mp) &&
10291036
xfs_get_projid(ip) != fa->fsx_projid) {
@@ -1137,7 +1144,7 @@ xfs_ioctl_setattr(
11371144
* cleared upon successful return from chown()
11381145
*/
11391146
if ((ip->i_d.di_mode & (S_ISUID|S_ISGID)) &&
1140-
!capable(CAP_FSETID))
1147+
!inode_capable(VFS_I(ip), CAP_FSETID))
11411148
ip->i_d.di_mode &= ~(S_ISUID|S_ISGID);
11421149

11431150
/*

‎kernel/capability.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,4 @@ bool inode_capable(const struct inode *inode, int cap)
464464

465465
return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
466466
}
467+
EXPORT_SYMBOL(inode_capable);

0 commit comments

Comments
 (0)