Skip to content

Commit

Permalink
xfs: improve ondisk dquot flags checking
Browse files Browse the repository at this point in the history
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 <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Darrick J. Wong committed Jul 29, 2020
1 parent 1a7ed27 commit a990f7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions fs/xfs/libxfs/xfs_dquot_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ xfs_dquot_verify(
struct xfs_disk_dquot *ddq,
xfs_dqid_t id) /* used only during quotacheck */
{
__u8 ddq_type;

/*
* We can encounter an uninitialized dquot buffer for 2 reasons:
* 1. If we crash while deleting the quotainode(s), and those blks got
Expand All @@ -59,9 +61,12 @@ xfs_dquot_verify(
if (ddq->d_version != XFS_DQUOT_VERSION)
return __this_address;

if (ddq->d_flags != XFS_DQTYPE_USER &&
ddq->d_flags != XFS_DQTYPE_PROJ &&
ddq->d_flags != XFS_DQTYPE_GROUP)
if (ddq->d_flags & ~XFS_DQTYPE_ANY)
return __this_address;
ddq_type = ddq->d_flags & XFS_DQTYPE_REC_MASK;
if (ddq_type != XFS_DQTYPE_USER &&
ddq_type != XFS_DQTYPE_PROJ &&
ddq_type != XFS_DQTYPE_GROUP)
return __this_address;

if (id != -1 && id != be32_to_cpu(ddq->d_id))
Expand Down
2 changes: 2 additions & 0 deletions fs/xfs/libxfs/xfs_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,8 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
XFS_DQTYPE_PROJ | \
XFS_DQTYPE_GROUP)

#define XFS_DQTYPE_ANY (XFS_DQTYPE_REC_MASK)

/*
* This is the main portion of the on-disk representation of quota information
* for a user. We pad this with some more expansion room to construct the on
Expand Down

0 comments on commit a990f7a

Please sign in to comment.