From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795949626; b=4iL4m5+o9kF9PTj2MX10KhedQRjGzc9RF5r3KbISWW3b7gOQL42xPjgvFzW7W1SO3FAU wSVikdG3rISlxOxtI7u+6/fYboo/ArMwcJu4J+W0apwMcgzxs25H7dbaswJYM1sD42DV+ 9VZ0H8GTwa2nLpWIsbvcaIk4GgGMzIzGIQLR0b4rHMTjV2uT7ZT1yuIV4yz2Vh79VyWHX XZILXrv64Yg53w0L5DOpRXYifKG+BkKBTkNgXuUiXCHZ2Zo7Rm8nO6xhNih50zXRZnJVt gt4r4Nsub4Fhapcl/OjXY19S71n03WOm72YtJo1aHVkgw2zhx37KKHNee7xSEMIRN/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795949626; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version; bh=W6r6D3iW9+Gp0OL/yfplZz4vf6F7Yp4gBEIYefg1EXk=; b=NbOhQ5WIfnuH0g4rA8YWnhEWYzgzEj1FR8V9XucyuuogM84ZJWcm8EZ3qVoE3RSI/8pz U+6WisBYBxaXeo4qiVF/vOqCuhx5UsLu2tIqu6cgszxMEyhIaoTb5Z6H9uJFTW3IJsnM9 1gqpdeA8ooWfHte14T3ppZ+R+vwgbp2LeB/2DdHDYhgITSXrqBcfJboLP9PZFQN0KS9cM wDWNlGtvxs3AkuUEptKgMZdBKrNoWLHeRyrxOaNCs7nMBW1fto8NY4xX8PJK5kiXkoK2Q oKqQNlljSzGfRoMr2Jl9wc8XsLAJJfzCAZM6XWoIL39JoalMp+72aiI83w/QlBAleeQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hKtQkmZQ; arc=none smtp.remote-ip=209.85.216.53 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5796A606A31C for ; Sun, 29 Nov 2026 10:53:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5796A606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hKtQkmZQ Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-3b09a83d12aso6796704a91.2 for ; Sun, 29 Nov 2026 02:53:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795949626; x=1796554426; darn=vger.kernel.org; h=mime-version:content-transfer-encoding:content-type:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=W6r6D3iW9+Gp0OL/yfplZz4vf6F7Yp4gBEIYefg1EXk=; b=hKtQkmZQRcbZrbFxNJztWDCI8D80gQR/Jvil4+PDePkIEdzZK6JTvNpQe668h3aJhz CeaaIkfls0INLck69MpjL5hodD26hj/uEUk0e2fdEGLQjhaQqxBxrGW5IHn4q9ArYG1k R4ggsOBmsEOHLR1198yfTxy14ujpkwgCvx7JD2+DtiX/bn+2nla1U5fEbUshFgo5YiAK EkOCJImeTXzjhZHkXfupur7Pw1hunwVRosT8qdvOZ5HxjM+HnrMY8fPYV+W4kHqSQvYr EobwgBeg++FHh35yNRj6bWkphBQBDhwIxTWqUyaIH+SB9p+MFfPFzESWNZWym4pK8ueG CDtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795949626; x=1796554426; h=mime-version:content-transfer-encoding:content-type:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=W6r6D3iW9+Gp0OL/yfplZz4vf6F7Yp4gBEIYefg1EXk=; b=tRz5vxuv2aTplmePtndris9MFqjU0e7bozG0xT+932euIf2+XdcQgR4uvZ0lLnrhyE bn5he2jU7wAOy1DNR3vrT2Bb7ByaNLBBVn3c9VshoszZe6BzvYp67f/8IEaK6e7W7eBG KoBpBXmMeVtSvcPVSwWpqThAB8HOJaGa90HytSu5rt2DqcNhSd1SeLmL7dykFHTe1puq EJCg3oHEk4g8qsl/wMjh+fkBdl5uRFgcf3QFtAZJbLAltJIAJvKImcDWbhCT+H/YwRzh wRHyDk6Ib164vwXvKvBdqknG30rX4TdRUjiGxE37zMNj43E6ZchwUv3fiBhtnsryPGuO q4xg== X-Gm-Message-State: APuU4Z+LjmFLBdxYHAY0CiJ0EQLZfLtzPlgX0YWaKXAOQypYUZf1c+5n 20wNH/lJzazVTYD5AJCXJAHejolbHlHYb2FtujpLalfqlyG1WrzlgQyh X-Gm-Gg: AZFdTZft61Ir8Hn7KXrD0U1Libok8KijCPKFmHu2m5SMhRTKrCZ0cRwNzCiYElAeLcJ UmHS05rnp9n+Ssm+rJH979iJ27eASWgP0W3fsQQdHe/nW6KQ+ZFSKoQQGzhrbVKAIIAxMb/VkEv 0U7XN3gzrJaprEe7oIFzfAUKoqlwLJkQ5h2KNz4BTBq+Z6lJYWQ9Pgxkg0kfATgJlbJ7fvKpLqo rbT85C3FVIerBmr65QYVa9+9ksmTwzVpI4K7/xe+kxeTGsDPMGDG+uScd0+1U2BHowhrvYqwkok CinG3IRAnUns8keJVqNfcT46NX2BzD22OCOTJ0elwJKYcyIfXjbbwbrsIHxdgACSVc86e/kRRV+ AwP+z5EVQiu74ATZJ3mA7lSq1nRGeAztobEIXNBMDIMl8zJNo+K2ustoMR29sjoqTdvXM7xV0z4 UuraOKcoJe5eIECZxeeh2id5ik6IX3qxUm6D07PiE9RimDsGclHCRaHgZzjWlaLP9WcGlakCng2 3auCEFg/jt9CpBwOKI5HTPeh97bdLrtka8767d+qdDvMIipcK6SGIDIcyLwAhvn3xpiMmXYjD/C /4+MpxS4oxNYOcHsPteJ5XQB7ijjr8g= X-Received: by 2002:a17:90b:4a47:b0:3a8:9d0d:ca50 with SMTP id 98e67ed59e1d1-3b41c8fe84amr32056407a91.10.1795949625692; Sun, 29 Nov 2026 02:53:45 -0800 (PST) Received: from [169.254.42.106] ([2602:f919:106::b8]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b41abb2076sm47827409a91.2.2026.11.29.02.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 02:53:45 -0800 (PST) From: Zheng Shuhao To: linux-xfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Carlos Maiolino , Darrick J. Wong , Kees Cook , syzbot+e7f24354da9f7915bc54@syzkaller.appspotmail.com, stable@vger.kernel.org Subject: [PATCH v2] xfs: fix slab-use-after-free in xrep_newbt_free() Date: Sun, 29 Nov 2026 18:53:38 +0800 Message-ID: <179594961807.35052.14164978078383342786@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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=3De7f24354da9f7915bc54 Cc: stable@vger.kernel.org Signed-off-by: Zheng Shuhao --- 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( =20 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); --=20 2.43.0