]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: create a predicate to verify per-AG extents
authorDarrick J. Wong <djwong@kernel.org>
Fri, 18 Nov 2022 10:01:45 +0000 (11:01 +0100)
committerCarlos Maiolino <cem@kernel.org>
Mon, 21 Nov 2022 14:26:48 +0000 (15:26 +0100)
Source kernel commit: b65e08f83b119ae9345ed23d4da357a72b3cb55c

Create a predicate function to verify that a given agbno/blockcount pair
fit entirely within a single allocation group and don't suffer
mathematical overflows.  Refactor the existng open-coded logic; we're
going to add more calls to this function in the next patch.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_ag.h
libxfs/xfs_alloc.c
libxfs/xfs_refcount.c
libxfs/xfs_rmap.c

index 517a138faa669b8494dda3810edbab78dc1930ac..191b22b9a35bfd67981de4f05c97703ad2371f7f 100644 (file)
@@ -133,6 +133,21 @@ xfs_verify_agbno(struct xfs_perag *pag, xfs_agblock_t agbno)
        return true;
 }
 
+static inline bool
+xfs_verify_agbext(
+       struct xfs_perag        *pag,
+       xfs_agblock_t           agbno,
+       xfs_agblock_t           len)
+{
+       if (agbno + len <= agbno)
+               return false;
+
+       if (!xfs_verify_agbno(pag, agbno))
+               return false;
+
+       return xfs_verify_agbno(pag, agbno + len - 1);
+}
+
 /*
  * Verify that an AG inode number pointer neither points outside the AG
  * nor points at static metadata.
index 3e310ce3e5bc9bb737fce9882724286521c00bdd..8c2c2e832f5baec22d4db13e3fbc964bffeb63c5 100644 (file)
@@ -259,11 +259,7 @@ xfs_alloc_get_rec(
                goto out_bad_rec;
 
        /* check for valid extent range, including overflow */
-       if (!xfs_verify_agbno(pag, *bno))
-               goto out_bad_rec;
-       if (*bno > *bno + *len)
-               goto out_bad_rec;
-       if (!xfs_verify_agbno(pag, *bno + *len - 1))
+       if (!xfs_verify_agbext(pag, *bno, *len))
                goto out_bad_rec;
 
        return 0;
index 146e833b0d180527a1820f90fa362904814d934e..c1ebc5047bd7099a325124d82a2d99213200d449 100644 (file)
@@ -134,11 +134,7 @@ xfs_refcount_get_rec(
        }
 
        /* check for valid extent range, including overflow */
-       if (!xfs_verify_agbno(pag, realstart))
-               goto out_bad_rec;
-       if (realstart > realstart + irec->rc_blockcount)
-               goto out_bad_rec;
-       if (!xfs_verify_agbno(pag, realstart + irec->rc_blockcount - 1))
+       if (!xfs_verify_agbext(pag, realstart, irec->rc_blockcount))
                goto out_bad_rec;
 
        if (irec->rc_refcount == 0 || irec->rc_refcount > MAXREFCOUNT)
index fa4ae8fca382da6b035aeb17d79457ef174724c0..b3caff1da30c74dcfbd95ee4c81c43b39eeb8975 100644 (file)
@@ -234,13 +234,8 @@ xfs_rmap_get_rec(
                        goto out_bad_rec;
        } else {
                /* check for valid extent range, including overflow */
-               if (!xfs_verify_agbno(pag, irec->rm_startblock))
-                       goto out_bad_rec;
-               if (irec->rm_startblock >
-                               irec->rm_startblock + irec->rm_blockcount)
-                       goto out_bad_rec;
-               if (!xfs_verify_agbno(pag,
-                               irec->rm_startblock + irec->rm_blockcount - 1))
+               if (!xfs_verify_agbext(pag, irec->rm_startblock,
+                                           irec->rm_blockcount))
                        goto out_bad_rec;
        }