Skip to content

Commit 2bed0d8

Browse files
Dave ChinnerDarrick J. Wong
authored andcommitted
xfs: fix bounds check in xfs_defer_agfl_block()
Need to happen before we allocate and then leak the xefi. Found by coverity via an xfsprogs libxfs scan. [djwong: This also fixes the type of the @agbno argument.] Fixes: 7dfee17 ("xfs: validate block number being freed before adding to xefi") Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
1 parent edd8276 commit 2bed0d8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,25 +2470,26 @@ static int
24702470
xfs_defer_agfl_block(
24712471
struct xfs_trans *tp,
24722472
xfs_agnumber_t agno,
2473-
xfs_fsblock_t agbno,
2473+
xfs_agblock_t agbno,
24742474
struct xfs_owner_info *oinfo)
24752475
{
24762476
struct xfs_mount *mp = tp->t_mountp;
24772477
struct xfs_extent_free_item *xefi;
2478+
xfs_fsblock_t fsbno = XFS_AGB_TO_FSB(mp, agno, agbno);
24782479

24792480
ASSERT(xfs_extfree_item_cache != NULL);
24802481
ASSERT(oinfo != NULL);
24812482

2483+
if (XFS_IS_CORRUPT(mp, !xfs_verify_fsbno(mp, fsbno)))
2484+
return -EFSCORRUPTED;
2485+
24822486
xefi = kmem_cache_zalloc(xfs_extfree_item_cache,
24832487
GFP_KERNEL | __GFP_NOFAIL);
2484-
xefi->xefi_startblock = XFS_AGB_TO_FSB(mp, agno, agbno);
2488+
xefi->xefi_startblock = fsbno;
24852489
xefi->xefi_blockcount = 1;
24862490
xefi->xefi_owner = oinfo->oi_owner;
24872491
xefi->xefi_agresv = XFS_AG_RESV_AGFL;
24882492

2489-
if (XFS_IS_CORRUPT(mp, !xfs_verify_fsbno(mp, xefi->xefi_startblock)))
2490-
return -EFSCORRUPTED;
2491-
24922493
trace_xfs_agfl_free_defer(mp, agno, 0, agbno, 1);
24932494

24942495
xfs_extent_free_get_group(mp, xefi);

0 commit comments

Comments
 (0)