Skip to content

Commit dd60687

Browse files
Christoph Hellwigdjwong
authored andcommitted
xfs: don't set v3 xflags for v2 inodes
Reject attempts to set XFLAGS that correspond to di_flags2 inode flags if the inode isn't a v3 inode, because di_flags2 only exists on v3. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 7bf7a19 commit dd60687

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

fs/xfs/xfs_ioctl.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -931,16 +931,15 @@ xfs_ioc_fsgetxattr(
931931
return 0;
932932
}
933933

934-
STATIC void
935-
xfs_set_diflags(
934+
STATIC uint16_t
935+
xfs_flags2diflags(
936936
struct xfs_inode *ip,
937937
unsigned int xflags)
938938
{
939-
unsigned int di_flags;
940-
uint64_t di_flags2;
941-
942939
/* can't set PREALLOC this way, just preserve it */
943-
di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
940+
uint16_t di_flags =
941+
(ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
942+
944943
if (xflags & FS_XFLAG_IMMUTABLE)
945944
di_flags |= XFS_DIFLAG_IMMUTABLE;
946945
if (xflags & FS_XFLAG_APPEND)
@@ -970,19 +969,24 @@ xfs_set_diflags(
970969
if (xflags & FS_XFLAG_EXTSIZE)
971970
di_flags |= XFS_DIFLAG_EXTSIZE;
972971
}
973-
ip->i_d.di_flags = di_flags;
974972

975-
/* diflags2 only valid for v3 inodes. */
976-
if (ip->i_d.di_version < 3)
977-
return;
973+
return di_flags;
974+
}
975+
976+
STATIC uint64_t
977+
xfs_flags2diflags2(
978+
struct xfs_inode *ip,
979+
unsigned int xflags)
980+
{
981+
uint64_t di_flags2 =
982+
(ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK);
978983

979-
di_flags2 = (ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK);
980984
if (xflags & FS_XFLAG_DAX)
981985
di_flags2 |= XFS_DIFLAG2_DAX;
982986
if (xflags & FS_XFLAG_COWEXTSIZE)
983987
di_flags2 |= XFS_DIFLAG2_COWEXTSIZE;
984988

985-
ip->i_d.di_flags2 = di_flags2;
989+
return di_flags2;
986990
}
987991

988992
STATIC void
@@ -1023,6 +1027,7 @@ xfs_ioctl_setattr_xflags(
10231027
struct fsxattr *fa)
10241028
{
10251029
struct xfs_mount *mp = ip->i_mount;
1030+
uint64_t di_flags2;
10261031

10271032
/* Can't change realtime flag if any extents are allocated. */
10281033
if ((ip->i_d.di_nextents || ip->i_delayed_blks) &&
@@ -1053,7 +1058,14 @@ xfs_ioctl_setattr_xflags(
10531058
!capable(CAP_LINUX_IMMUTABLE))
10541059
return -EPERM;
10551060

1056-
xfs_set_diflags(ip, fa->fsx_xflags);
1061+
/* diflags2 only valid for v3 inodes. */
1062+
di_flags2 = xfs_flags2diflags2(ip, fa->fsx_xflags);
1063+
if (di_flags2 && ip->i_d.di_version < 3)
1064+
return -EINVAL;
1065+
1066+
ip->i_d.di_flags = xfs_flags2diflags(ip, fa->fsx_xflags);
1067+
ip->i_d.di_flags2 = di_flags2;
1068+
10571069
xfs_diflags_to_linux(ip);
10581070
xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
10591071
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);

0 commit comments

Comments
 (0)