Skip to content

Commit 1c253e1

Browse files
author
Darrick J. Wong
committed
xfs: fix UAF in xchk_btree_check_block_owner
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>
1 parent ca27313 commit 1c253e1

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
@@ -372,12 +372,15 @@ xchk_btree_check_block_owner(
372372
{
373373
xfs_agnumber_t agno;
374374
xfs_agblock_t agbno;
375+
bool is_bnobt, is_rmapbt;
375376
bool init_sa;
376377
int error = 0;
377378

378379
if (!bs->cur)
379380
return 0;
380381

382+
is_bnobt = xfs_btree_is_bno(bs->cur->bc_ops);
383+
is_rmapbt = xfs_btree_is_rmap(bs->cur->bc_ops);
381384
agno = xfs_daddr_to_agno(bs->cur->bc_mp, daddr);
382385
agbno = xfs_daddr_to_agbno(bs->cur->bc_mp, daddr);
383386

@@ -400,11 +403,11 @@ xchk_btree_check_block_owner(
400403
* have to nullify it (to shut down further block owner checks) if
401404
* self-xref encounters problems.
402405
*/
403-
if (!bs->sc->sa.bno_cur && xfs_btree_is_bno(bs->cur->bc_ops))
406+
if (!bs->sc->sa.bno_cur && is_bnobt)
404407
bs->cur = NULL;
405408

406409
xchk_xref_is_only_owned_by(bs->sc, agbno, 1, bs->oinfo);
407-
if (!bs->sc->sa.rmap_cur && xfs_btree_is_rmap(bs->cur->bc_ops))
410+
if (!bs->sc->sa.rmap_cur && is_rmapbt)
408411
bs->cur = NULL;
409412

410413
out_free:

0 commit comments

Comments
 (0)