Commit a5f460b1 authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: check that br_blockcount doesn't overflow

xfs_bmbt_irec.br_blockcount is declared as xfs_filblks_t, which is an
unsigned 64-bit integer.  Though the bmbt helpers will never set a value
larger than 2^21 (since the underlying on-disk extent record has a
length field that is only 21 bits wide), we should be a little defensive
about checking that a bmbt record doesn't exceed what we're expecting or
overflow into the next AG.
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
parent 55e45429
...@@ -305,6 +305,7 @@ xfs_scrub_bmap_extent( ...@@ -305,6 +305,7 @@ xfs_scrub_bmap_extent(
{ {
struct xfs_mount *mp = info->sc->mp; struct xfs_mount *mp = info->sc->mp;
struct xfs_buf *bp = NULL; struct xfs_buf *bp = NULL;
xfs_filblks_t end;
int error = 0; int error = 0;
if (cur) if (cur)
...@@ -332,19 +333,23 @@ xfs_scrub_bmap_extent( ...@@ -332,19 +333,23 @@ xfs_scrub_bmap_extent(
irec->br_startoff); irec->br_startoff);
/* Make sure the extent points to a valid place. */ /* Make sure the extent points to a valid place. */
if (irec->br_blockcount > MAXEXTLEN)
xfs_scrub_fblock_set_corrupt(info->sc, info->whichfork,
irec->br_startoff);
if (irec->br_startblock + irec->br_blockcount <= irec->br_startblock) if (irec->br_startblock + irec->br_blockcount <= irec->br_startblock)
xfs_scrub_fblock_set_corrupt(info->sc, info->whichfork, xfs_scrub_fblock_set_corrupt(info->sc, info->whichfork,
irec->br_startoff); irec->br_startoff);
end = irec->br_startblock + irec->br_blockcount - 1;
if (info->is_rt && if (info->is_rt &&
(!xfs_verify_rtbno(mp, irec->br_startblock) || (!xfs_verify_rtbno(mp, irec->br_startblock) ||
!xfs_verify_rtbno(mp, irec->br_startblock + !xfs_verify_rtbno(mp, end)))
irec->br_blockcount - 1)))
xfs_scrub_fblock_set_corrupt(info->sc, info->whichfork, xfs_scrub_fblock_set_corrupt(info->sc, info->whichfork,
irec->br_startoff); irec->br_startoff);
if (!info->is_rt && if (!info->is_rt &&
(!xfs_verify_fsbno(mp, irec->br_startblock) || (!xfs_verify_fsbno(mp, irec->br_startblock) ||
!xfs_verify_fsbno(mp, irec->br_startblock + !xfs_verify_fsbno(mp, end) ||
irec->br_blockcount - 1))) XFS_FSB_TO_AGNO(mp, irec->br_startblock) !=
XFS_FSB_TO_AGNO(mp, end)))
xfs_scrub_fblock_set_corrupt(info->sc, info->whichfork, xfs_scrub_fblock_set_corrupt(info->sc, info->whichfork,
irec->br_startoff); irec->br_startoff);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment