]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
xfs: fix UAF in xchk_btree_check_block_owner
authorDarrick J. Wong <djwong@kernel.org>
Fri, 23 Jan 2026 17:27:39 +0000 (09:27 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 16 Feb 2026 09:19:46 +0000 (10:19 +0100)
commit 1c253e11225bc5167217897885b85093e17c2217 upstream.

We cannot dereference bs->cur when trying to determine if bs->cur
aliases bs->sc->sa.{bno,rmap}_cur after the latter has been freed.
Fix this by sampling before type before any freeing could happen.
The correct temporal ordering was broken when we removed xfs_btnum_t.

Cc: r772577952@gmail.com
Cc: <stable@vger.kernel.org> # v6.9
Fixes: ec793e690f801d ("xfs: remove xfs_btnum_t")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Jiaming Zhang <r772577952@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/xfs/scrub/btree.c

index cd6f0ff382a7c8d85a8375a13a73920697da53ed..acade92c5fce1ab0718915a69ade597f962b7dc5 100644 (file)
@@ -370,12 +370,15 @@ xchk_btree_check_block_owner(
 {
        xfs_agnumber_t          agno;
        xfs_agblock_t           agbno;
+       bool                    is_bnobt, is_rmapbt;
        bool                    init_sa;
        int                     error = 0;
 
        if (!bs->cur)
                return 0;
 
+       is_bnobt = xfs_btree_is_bno(bs->cur->bc_ops);
+       is_rmapbt = xfs_btree_is_rmap(bs->cur->bc_ops);
        agno = xfs_daddr_to_agno(bs->cur->bc_mp, daddr);
        agbno = xfs_daddr_to_agbno(bs->cur->bc_mp, daddr);
 
@@ -398,11 +401,11 @@ xchk_btree_check_block_owner(
         * have to nullify it (to shut down further block owner checks) if
         * self-xref encounters problems.
         */
-       if (!bs->sc->sa.bno_cur && xfs_btree_is_bno(bs->cur->bc_ops))
+       if (!bs->sc->sa.bno_cur && is_bnobt)
                bs->cur = NULL;
 
        xchk_xref_is_only_owned_by(bs->sc, agbno, 1, bs->oinfo);
-       if (!bs->sc->sa.rmap_cur && xfs_btree_is_rmap(bs->cur->bc_ops))
+       if (!bs->sc->sa.rmap_cur && is_rmapbt)
                bs->cur = NULL;
 
 out_free: