Skip to content

Commit a990f7a

Browse files
committed
xfs: improve ondisk dquot flags checking
Create an XFS_DQTYPE_ANY mask for ondisk dquots flags, and use that to ensure that we never accept any garbage flags when we're loading dquots. While we're at it, restructure the quota type flag checking to use the proper masking. Note that I plan to add y2038 support soon, which will require a new xfs_dqtype_t flag for extended timestamp support, hence all the work to make the type masking work correctly. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 1a7ed27 commit a990f7a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

fs/xfs/libxfs/xfs_dquot_buf.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ xfs_dquot_verify(
3939
struct xfs_disk_dquot *ddq,
4040
xfs_dqid_t id) /* used only during quotacheck */
4141
{
42+
__u8 ddq_type;
43+
4244
/*
4345
* We can encounter an uninitialized dquot buffer for 2 reasons:
4446
* 1. If we crash while deleting the quotainode(s), and those blks got
@@ -59,9 +61,12 @@ xfs_dquot_verify(
5961
if (ddq->d_version != XFS_DQUOT_VERSION)
6062
return __this_address;
6163

62-
if (ddq->d_flags != XFS_DQTYPE_USER &&
63-
ddq->d_flags != XFS_DQTYPE_PROJ &&
64-
ddq->d_flags != XFS_DQTYPE_GROUP)
64+
if (ddq->d_flags & ~XFS_DQTYPE_ANY)
65+
return __this_address;
66+
ddq_type = ddq->d_flags & XFS_DQTYPE_REC_MASK;
67+
if (ddq_type != XFS_DQTYPE_USER &&
68+
ddq_type != XFS_DQTYPE_PROJ &&
69+
ddq_type != XFS_DQTYPE_GROUP)
6570
return __this_address;
6671

6772
if (id != -1 && id != be32_to_cpu(ddq->d_id))

fs/xfs/libxfs/xfs_format.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,8 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
11581158
XFS_DQTYPE_PROJ | \
11591159
XFS_DQTYPE_GROUP)
11601160

1161+
#define XFS_DQTYPE_ANY (XFS_DQTYPE_REC_MASK)
1162+
11611163
/*
11621164
* This is the main portion of the on-disk representation of quota information
11631165
* for a user. We pad this with some more expansion room to construct the on

0 commit comments

Comments
 (0)