]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: check deferred refcount op continuation parameters
authorDarrick J. Wong <djwong@kernel.org>
Fri, 18 Nov 2022 10:02:45 +0000 (11:02 +0100)
committerCarlos Maiolino <cem@kernel.org>
Mon, 21 Nov 2022 14:26:48 +0000 (15:26 +0100)
Source kernel commit: 8edbe0cf8b4bbe2cf47513998641797b0aca8ee2

If we're in the middle of a deferred refcount operation and decide to
roll the transaction to avoid overflowing the transaction space, we need
to check the new agbno/aglen parameters that we're about to record in
the new intent.  Specifically, we need to check that the new extent is
completely within the filesystem, and that continuation does not put us
into a different AG.

If the keys of a node block are wrong, the lookup to resume an
xfs_refcount_adjust_extents operation can put us into the wrong record
block.  If this happens, we might not find that we run out of aglen at
an exact record boundary, which will cause the loop control to do the
wrong thing.

The previous patch should take care of that problem, but let's add this
extra sanity check to stop corruption problems sooner than later.

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_refcount.c

index c1ebc5047bd7099a325124d82a2d99213200d449..5ba8241998f9ac0422f4b2ceaf27585a7b2ad15e 100644 (file)
@@ -1133,6 +1133,32 @@ xfs_refcount_finish_one_cleanup(
                xfs_trans_brelse(tp, agbp);
 }
 
+/*
+ * Set up a continuation a deferred refcount operation by updating the intent.
+ * Checks to make sure we're not going to run off the end of the AG.
+ */
+static inline int
+xfs_refcount_continue_op(
+       struct xfs_btree_cur            *cur,
+       xfs_fsblock_t                   startblock,
+       xfs_agblock_t                   new_agbno,
+       xfs_extlen_t                    new_len,
+       xfs_fsblock_t                   *new_fsbno)
+{
+       struct xfs_mount                *mp = cur->bc_mp;
+       struct xfs_perag                *pag = cur->bc_ag.pag;
+
+       if (XFS_IS_CORRUPT(mp, !xfs_verify_agbext(pag, new_agbno, new_len)))
+               return -EFSCORRUPTED;
+
+       *new_fsbno = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno);
+
+       ASSERT(xfs_verify_fsbext(mp, *new_fsbno, new_len));
+       ASSERT(pag->pag_agno == XFS_FSB_TO_AGNO(mp, *new_fsbno));
+
+       return 0;
+}
+
 /*
  * Process one of the deferred refcount operations.  We pass back the
  * btree cursor to maintain our lock on the btree between calls.
@@ -1200,12 +1226,20 @@ xfs_refcount_finish_one(
        case XFS_REFCOUNT_INCREASE:
                error = xfs_refcount_adjust(rcur, bno, blockcount, &new_agbno,
                                new_len, XFS_REFCOUNT_ADJUST_INCREASE);
-               *new_fsb = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno);
+               if (error)
+                       goto out_drop;
+               if (*new_len > 0)
+                       error = xfs_refcount_continue_op(rcur, startblock,
+                                       new_agbno, *new_len, new_fsb);
                break;
        case XFS_REFCOUNT_DECREASE:
                error = xfs_refcount_adjust(rcur, bno, blockcount, &new_agbno,
                                new_len, XFS_REFCOUNT_ADJUST_DECREASE);
-               *new_fsb = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno);
+               if (error)
+                       goto out_drop;
+               if (*new_len > 0)
+                       error = xfs_refcount_continue_op(rcur, startblock,
+                                       new_agbno, *new_len, new_fsb);
                break;
        case XFS_REFCOUNT_ALLOC_COW:
                *new_fsb = startblock + blockcount;