]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
xfs: refactor data device extent validation
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 4 Dec 2020 21:20:00 +0000 (13:20 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Wed, 9 Dec 2020 17:49:38 +0000 (09:49 -0800)
Refactor all the open-coded validation of non-static data device extents
into a single helper.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
fs/xfs/libxfs/xfs_bmap.c
fs/xfs/libxfs/xfs_types.c
fs/xfs/libxfs/xfs_types.h
fs/xfs/scrub/bmap.c
fs/xfs/xfs_bmap_item.c
fs/xfs/xfs_extfree_item.c
fs/xfs/xfs_refcount_item.c
fs/xfs/xfs_rmap_item.c

index de9c27ef68d861d7de6a81c706a2b48d7f165220..7f1b6ad570a93cc33bdae561400365b9bc3c4ce1 100644 (file)
@@ -6242,12 +6242,8 @@ xfs_bmap_validate_extent(
                if (!xfs_verify_rtbno(mp, endfsb))
                        return __this_address;
        } else {
-               if (!xfs_verify_fsbno(mp, irec->br_startblock))
-                       return __this_address;
-               if (!xfs_verify_fsbno(mp, endfsb))
-                       return __this_address;
-               if (XFS_FSB_TO_AGNO(mp, irec->br_startblock) !=
-                   XFS_FSB_TO_AGNO(mp, endfsb))
+               if (!xfs_verify_fsbext(mp, irec->br_startblock,
+                                          irec->br_blockcount))
                        return __this_address;
        }
        if (irec->br_state != XFS_EXT_NORM && whichfork != XFS_DATA_FORK)
index 4f595546a639b7c784a670fe31a7cd6870e8d3e2..b74866dbea941ad94d9eb0141450cfe20915dead 100644 (file)
@@ -61,6 +61,29 @@ xfs_verify_fsbno(
        return xfs_verify_agbno(mp, agno, XFS_FSB_TO_AGBNO(mp, fsbno));
 }
 
+/*
+ * Verify that a data device extent is fully contained inside the filesystem,
+ * does not cross an AG boundary, and does not point at static metadata.
+ */
+bool
+xfs_verify_fsbext(
+       struct xfs_mount        *mp,
+       xfs_fsblock_t           fsbno,
+       xfs_fsblock_t           len)
+{
+       if (fsbno + len <= fsbno)
+               return false;
+
+       if (!xfs_verify_fsbno(mp, fsbno))
+               return false;
+
+       if (!xfs_verify_fsbno(mp, fsbno + len - 1))
+               return false;
+
+       return  XFS_FSB_TO_AGNO(mp, fsbno) ==
+               XFS_FSB_TO_AGNO(mp, fsbno + len - 1);
+}
+
 /* Calculate the first and last possible inode number in an AG. */
 void
 xfs_agino_range(
index 397d94775440d039e43d05b37ebb68dac045459a..7feaaac25b3d76ee95c3c40463c4b99d08cb994b 100644 (file)
@@ -184,6 +184,8 @@ xfs_agblock_t xfs_ag_block_count(struct xfs_mount *mp, xfs_agnumber_t agno);
 bool xfs_verify_agbno(struct xfs_mount *mp, xfs_agnumber_t agno,
                xfs_agblock_t agbno);
 bool xfs_verify_fsbno(struct xfs_mount *mp, xfs_fsblock_t fsbno);
+bool xfs_verify_fsbext(struct xfs_mount *mp, xfs_fsblock_t fsbno,
+               xfs_fsblock_t len);
 
 void xfs_agino_range(struct xfs_mount *mp, xfs_agnumber_t agno,
                xfs_agino_t *first, xfs_agino_t *last);
index fed56d213a3f9c33acbc4502274e2680badd48ca..3e2ba787505904a7fee7133782fde04e48c0419a 100644 (file)
@@ -359,10 +359,7 @@ xchk_bmap_iextent(
                xchk_fblock_set_corrupt(info->sc, info->whichfork,
                                irec->br_startoff);
        if (!info->is_rt &&
-           (!xfs_verify_fsbno(mp, irec->br_startblock) ||
-            !xfs_verify_fsbno(mp, end) ||
-            XFS_FSB_TO_AGNO(mp, irec->br_startblock) !=
-                               XFS_FSB_TO_AGNO(mp, end)))
+           !xfs_verify_fsbext(mp, irec->br_startblock, irec->br_blockcount))
                xchk_fblock_set_corrupt(info->sc, info->whichfork,
                                irec->br_startoff);
 
index a21a9f71c0c0c182176a7c6e031ae5ec00092a67..659bde22c505c9f1d6cfc997ea5d97d4c47dc1f7 100644 (file)
@@ -448,16 +448,7 @@ xfs_bui_validate(
        if (bmap->me_startoff + bmap->me_len <= bmap->me_startoff)
                return false;
 
-       if (bmap->me_startblock + bmap->me_len <= bmap->me_startblock)
-               return false;
-
-       if (!xfs_verify_fsbno(mp, bmap->me_startblock))
-               return false;
-
-       if (!xfs_verify_fsbno(mp, bmap->me_startblock + bmap->me_len - 1))
-               return false;
-
-       return true;
+       return xfs_verify_fsbext(mp, bmap->me_startblock, bmap->me_len);
 }
 
 /*
index bfdfbd192a38e6048f444a0dc532e1f8fea8bf94..93223ebb33721ed3fb8429d7e3f34e92935484c3 100644 (file)
@@ -584,16 +584,7 @@ xfs_efi_validate_ext(
        struct xfs_mount                *mp,
        struct xfs_extent               *extp)
 {
-       if (extp->ext_start + extp->ext_len <= extp->ext_start)
-               return false;
-
-       if (!xfs_verify_fsbno(mp, extp->ext_start))
-               return false;
-
-       if (!xfs_verify_fsbno(mp, extp->ext_start + extp->ext_len - 1))
-               return false;
-
-       return true;
+       return xfs_verify_fsbext(mp, extp->ext_start, extp->ext_len);
 }
 
 /*
index 937d482c9be4c8554097a072d365fe1fdfd30abd..07ebccbbf4dfab8e270b9c4aca46800d1fceff2f 100644 (file)
@@ -439,16 +439,7 @@ xfs_cui_validate_phys(
                return false;
        }
 
-       if (refc->pe_startblock + refc->pe_len <= refc->pe_startblock)
-               return false;
-
-       if (!xfs_verify_fsbno(mp, refc->pe_startblock))
-               return false;
-
-       if (!xfs_verify_fsbno(mp, refc->pe_startblock + refc->pe_len - 1))
-               return false;
-
-       return true;
+       return xfs_verify_fsbext(mp, refc->pe_startblock, refc->pe_len);
 }
 
 /*
index 9b84017184d9583d21779e493ad2a6ce5fcbeb86..4fa875237422cfefe394dbfcdef70261e2a9661e 100644 (file)
@@ -493,16 +493,7 @@ xfs_rui_validate_map(
        if (rmap->me_startoff + rmap->me_len <= rmap->me_startoff)
                return false;
 
-       if (rmap->me_startblock + rmap->me_len <= rmap->me_startblock)
-               return false;
-
-       if (!xfs_verify_fsbno(mp, rmap->me_startblock))
-               return false;
-
-       if (!xfs_verify_fsbno(mp, rmap->me_startblock + rmap->me_len - 1))
-               return false;
-
-       return true;
+       return xfs_verify_fsbext(mp, rmap->me_startblock, rmap->me_len);
 }
 
 /*