Commit 33005fd0 authored by Darrick J. Wong's avatar Darrick J. Wong
Browse files

xfs: refactor file range validation



Refactor all the open-coded validation of file block ranges into a
single helper, and teach the bmap scrubber to check the ranges.

Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent 18695ad4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6227,7 +6227,7 @@ xfs_bmap_validate_extent(
{
	struct xfs_mount	*mp = ip->i_mount;

	if (irec->br_startoff + irec->br_blockcount <= irec->br_startoff)
	if (!xfs_verify_fileext(mp, irec->br_startoff, irec->br_blockcount))
		return __this_address;

	if (XFS_IS_REALTIME_INODE(ip) && whichfork == XFS_DATA_FORK) {
+25 −0
Original line number Diff line number Diff line
@@ -258,3 +258,28 @@ xfs_verify_dablk(

	return dabno <= max_dablk;
}

/* Check that a file block offset does not exceed the maximum. */
bool
xfs_verify_fileoff(
	struct xfs_mount	*mp,
	xfs_fileoff_t		off)
{
	return off <= XFS_MAX_FILEOFF;
}

/* Check that a range of file block offsets do not exceed the maximum. */
bool
xfs_verify_fileext(
	struct xfs_mount	*mp,
	xfs_fileoff_t		off,
	xfs_fileoff_t		len)
{
	if (off + len <= off)
		return false;

	if (!xfs_verify_fileoff(mp, off))
		return false;

	return xfs_verify_fileoff(mp, off + len - 1);
}
+3 −0
Original line number Diff line number Diff line
@@ -203,5 +203,8 @@ bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount);
bool xfs_verify_dablk(struct xfs_mount *mp, xfs_fileoff_t off);
void xfs_icount_range(struct xfs_mount *mp, unsigned long long *min,
		unsigned long long *max);
bool xfs_verify_fileoff(struct xfs_mount *mp, xfs_fileoff_t off);
bool xfs_verify_fileext(struct xfs_mount *mp, xfs_fileoff_t off,
		xfs_fileoff_t len);

#endif	/* __XFS_TYPES_H__ */
+4 −0
Original line number Diff line number Diff line
@@ -329,6 +329,10 @@ xchk_bmap_iextent(
		xchk_fblock_set_corrupt(info->sc, info->whichfork,
				irec->br_startoff);

	if (!xfs_verify_fileext(mp, irec->br_startoff, irec->br_blockcount))
		xchk_fblock_set_corrupt(info->sc, info->whichfork,
				irec->br_startoff);

	xchk_bmap_dirattr_extent(ip, info, irec);

	/* There should never be a "hole" extent in either extent list. */
+1 −1
Original line number Diff line number Diff line
@@ -445,7 +445,7 @@ xfs_bui_validate(
	if (!xfs_verify_ino(mp, bmap->me_owner))
		return false;

	if (bmap->me_startoff + bmap->me_len <= bmap->me_startoff)
	if (!xfs_verify_fileext(mp, bmap->me_startoff, bmap->me_len))
		return false;

	return xfs_verify_fsbext(mp, bmap->me_startblock, bmap->me_len);
Loading