* [PATCH v2] xfs: fix slab-use-after-free in xrep_newbt_free()
@ 2026-11-29 10:53 Zheng Shuhao
2026-12-01 8:58 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: Zheng Shuhao @ 2026-11-29 10:53 UTC (permalink / raw)
To: linux-xfs
Cc: linux-kernel, Carlos Maiolino, Darrick J. Wong, Kees Cook,
syzbot+e7f24354da9f7915bc54, stable
syzbot reported a slab-use-after-free read in
xfs_defer_item_unpause() while online repair was rebuilding a bmap
btree:
BUG: KASAN: slab-use-after-free in xfs_defer_item_unpause+0x116/0x250
Read of size 4 at addr ffff8880132c127c by task syz.0.0/5327
Each new btree reservation stores an autoreap pointer to a deferred
pending item. If deferred work fails while staging the new btree,
xfs_defer_finish_noroll() shuts down the filesystem and
xfs_defer_cancel_list() frees the pending items. During repair
unwind, xrep_newbt_free() could then pass a stale autoreap pointer to
xfs_alloc_commit_autoreap().
Skip committing autoreaps after shutdown. Any deferred items still
attached to the transaction are canceled during transaction teardown.
Testing:
- Ran xfstests -g auto on the patched x86_64 kernel in QEMU: 1286 tests
were included in the run; 26 failed, and some tests were skipped.
- No KASAN/use-after-free report, NULL-pointer dereference, general
protection fault, or kernel panic was observed in the patched run.
Fixes: 6bb9ea8ecd2c ("xfs: log EFIs for all btree blocks being used to stage a btree")
Reported-by: syzbot+e7f24354da9f7915bc54@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e7f24354da9f7915bc54
Cc: stable@vger.kernel.org
Signed-off-by: Zheng Shuhao <viennaoffh@gmail.com>
---
v2:
- Shorten the shutdown-path comment.
fs/xfs/scrub/newbt.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/xfs/scrub/newbt.c b/fs/xfs/scrub/newbt.c
index 584076b2a6eed..69b135d711aef 100644
--- a/fs/xfs/scrub/newbt.c
+++ b/fs/xfs/scrub/newbt.c
@@ -514,12 +514,12 @@ xrep_newbt_free(
junkit:
/*
- * If we still have reservations attached to @newbt, cleanup must have
- * failed and the filesystem is about to go down. Clean up the incore
- * reservations and try to commit to freeing the space we used.
+ * Shutdown can free deferred items referenced by the autoreaps;
+ * transaction teardown cancels any remaining items.
*/
list_for_each_entry_safe(resv, n, &xnr->resv_list, list) {
- xfs_alloc_commit_autoreap(sc->tp, &resv->autoreap);
+ if (!xfs_is_shutdown(sc->mp))
+ xfs_alloc_commit_autoreap(sc->tp, &resv->autoreap);
list_del(&resv->list);
xfs_perag_put(resv->pag);
kfree(resv);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] xfs: fix slab-use-after-free in xrep_newbt_free()
2026-11-29 10:53 [PATCH v2] xfs: fix slab-use-after-free in xrep_newbt_free() Zheng Shuhao
@ 2026-12-01 8:58 ` Christoph Hellwig
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2026-12-01 8:58 UTC (permalink / raw)
To: Zheng Shuhao
Cc: linux-xfs, linux-kernel, Carlos Maiolino, Darrick J. Wong,
Kees Cook, syzbot+e7f24354da9f7915bc54, stable
On Sun, Nov 29, 2026 at 06:53:38PM +0800, Zheng Shuhao wrote:
> list_for_each_entry_safe(resv, n, &xnr->resv_list, list) {
> - xfs_alloc_commit_autoreap(sc->tp, &resv->autoreap);
> + if (!xfs_is_shutdown(sc->mp))
> + xfs_alloc_commit_autoreap(sc->tp, &resv->autoreap);
I don't think this is the correct check, and the commit log does not
describe the situation correctly.
A shutdown does not free deferred items. A failing
xfs_defer_finish_noroll just happens to call xfs_defer_cancel_list
AND shuts down the file systems. So the condition here is not
"is the file system shut down" but: did a defer_finish fail for this
chain, and the logic needs to represent that.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 8:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 10:53 [PATCH v2] xfs: fix slab-use-after-free in xrep_newbt_free() Zheng Shuhao
2026-12-01 8:58 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox