Skip to content

Commit 3c15df3

Browse files
committed
xfs: hoist recovered extent-free intent checks out of xfs_efi_item_recover
When we recover a extent-free intent from the log, we need to validate its contents before we try to replay them. Hoist the checking code into a separate function in preparation to refactor this code to use validation helpers. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Brian Foster <bfoster@redhat.com>
1 parent 0d79781 commit 3c15df3

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

fs/xfs/xfs_extfree_item.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,25 @@ const struct xfs_defer_op_type xfs_agfl_free_defer_type = {
578578
.cancel_item = xfs_extent_free_cancel_item,
579579
};
580580

581+
/* Is this recovered EFI ok? */
582+
static inline bool
583+
xfs_efi_validate_ext(
584+
struct xfs_mount *mp,
585+
struct xfs_extent *extp)
586+
{
587+
xfs_fsblock_t startblock_fsb;
588+
589+
startblock_fsb = XFS_BB_TO_FSB(mp,
590+
XFS_FSB_TO_DADDR(mp, extp->ext_start));
591+
if (startblock_fsb == 0 ||
592+
extp->ext_len == 0 ||
593+
startblock_fsb >= mp->m_sb.sb_dblocks ||
594+
extp->ext_len >= mp->m_sb.sb_agblocks)
595+
return false;
596+
597+
return true;
598+
}
599+
581600
/*
582601
* Process an extent free intent item that was recovered from
583602
* the log. We need to free the extents that it describes.
@@ -592,7 +611,6 @@ xfs_efi_item_recover(
592611
struct xfs_efd_log_item *efdp;
593612
struct xfs_trans *tp;
594613
struct xfs_extent *extp;
595-
xfs_fsblock_t startblock_fsb;
596614
int i;
597615
int error = 0;
598616

@@ -602,14 +620,13 @@ xfs_efi_item_recover(
602620
* just toss the EFI.
603621
*/
604622
for (i = 0; i < efip->efi_format.efi_nextents; i++) {
605-
extp = &efip->efi_format.efi_extents[i];
606-
startblock_fsb = XFS_BB_TO_FSB(mp,
607-
XFS_FSB_TO_DADDR(mp, extp->ext_start));
608-
if (startblock_fsb == 0 ||
609-
extp->ext_len == 0 ||
610-
startblock_fsb >= mp->m_sb.sb_dblocks ||
611-
extp->ext_len >= mp->m_sb.sb_agblocks)
623+
if (!xfs_efi_validate_ext(mp,
624+
&efip->efi_format.efi_extents[i])) {
625+
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
626+
&efip->efi_format,
627+
sizeof(efip->efi_format));
612628
return -EFSCORRUPTED;
629+
}
613630
}
614631

615632
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);

0 commit comments

Comments
 (0)