Skip to content

Commit 1d41127

Browse files
Darrick J. Wonggregkh
authored andcommitted
xfs: fix UAF in xchk_btree_check_block_owner
commit 1c253e1 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: ec793e6 ("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>
1 parent ae38582 commit 1d41127

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

fs/xfs/scrub/btree.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,15 @@ xchk_btree_check_block_owner(
370370
{
371371
xfs_agnumber_t agno;
372372
xfs_agblock_t agbno;
373+
bool is_bnobt, is_rmapbt;
373374
bool init_sa;
374375
int error = 0;
375376

376377
if (!bs->cur)
377378
return 0;
378379

380+
is_bnobt = xfs_btree_is_bno(bs->cur->bc_ops);
381+
is_rmapbt = xfs_btree_is_rmap(bs->cur->bc_ops);
379382
agno = xfs_daddr_to_agno(bs->cur->bc_mp, daddr);
380383
agbno = xfs_daddr_to_agbno(bs->cur->bc_mp, daddr);
381384

@@ -398,11 +401,11 @@ xchk_btree_check_block_owner(
398401
* have to nullify it (to shut down further block owner checks) if
399402
* self-xref encounters problems.
400403
*/
401-
if (!bs->sc->sa.bno_cur && xfs_btree_is_bno(bs->cur->bc_ops))
404+
if (!bs->sc->sa.bno_cur && is_bnobt)
402405
bs->cur = NULL;
403406

404407
xchk_xref_is_only_owned_by(bs->sc, agbno, 1, bs->oinfo);
405-
if (!bs->sc->sa.rmap_cur && xfs_btree_is_rmap(bs->cur->bc_ops))
408+
if (!bs->sc->sa.rmap_cur && is_rmapbt)
406409
bs->cur = NULL;
407410

408411
out_free:

0 commit comments

Comments
 (0)