Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795949626; b=opFSZlwWwmW8KuohJV3zHMT7cEHbyRjflOqzIrkHDEvlL3tVau/mA2TTLuuPAkLU8F4q DMjMANLeWZGyV9EHF8dHtZywhVm6Ejq+I0YehXZjRylPk7c4PCVB5t/vaNLOzFm+GVOYt H+iX40jdOTkyzXaiqIcKD0kixNXUMdmeY1NM3aWvi9kQYqtK4L9Jfg3YqrNcsawxvT2Gi R7JCvrgX+2QuuUmVLjOeQ6AjyF6zcAKfXl0GYfQqjN1/qNeMqPw1AQTJZy7W5xKdNiiNn knYMx/0GjA7740aEXC0irKOV1BQ9C3SLnf0QhBRx+abdAVPzQm47RUhATVYTwJOWyUQ== 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=Kbj3Y79MKnMqgAzj116cVr4SiBOKoe789VSY+75G1095FkhxhUViwUI6b4yVPAfJLIMy RPg71kRU4Dgz64PrPI3Auz4lEN4OVIT71yN3WSgZTiDZ7Q0kanM1PU4Q+Z5doZ4spi/9b Nc4yqfSI1x034MSs7uDH+WE7pZYORL0SVapd9F144gsnsxyagRVGQG32aIPKtXia9bbNH l0mNwxZvzMll57q3ppZbXDBDl3o+eF9CfPU0yHH/9IBUXUGrZwkT6yp8UZKktpRSyFwpt T5LOj6kTe7VhV6UPcUcPw8gLNTc1wtUcpZ100mvum0aouwWWNFh+MxjB4iWoX2GU0NA== 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.214.180 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 68866606A325 for ; Sun, 29 Nov 2026 10:53:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 68866606A325 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-pl1-f180.google.com with SMTP id d9443c01a7336-2f02ee04378so74106815ad.1 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=kq3TMvqQOeZGdvJOzOhy+wWa5lO0wJI+y3ABViGSmmyo1QdzCSi6GZqpqJn3fpL2pT nANRNid8nRXiuCg8/uHtMGEGo1XjBJ5HoxKuIVYXB3nwgCsQzXubEyaU4Pc+iGAlfqNE mgzER3Grb1kF1yxCUfB6JxhZQfJR+yLSzcf3iOVmcP6xfIDtEQmwOIh8naaC9HG9S3fD S0fW/pQnN0bE/+voF0i7l7MCh6wmX1fTM62uPUX4tI7dArm8Rnv1E4Zspnv6DY+4N+F1 mMeXU/RHB/nkynVVajHdjdWe6t0GVjK0tRnIqgyhYbz/LmYpywzqaT1ekJDrQ/aIxIA3 OoYg== X-Gm-Message-State: APuU4Z/YX7GYmXZ3+VId8GFQYSm+zFjEsnWUjv5LEOAPCK6puAmy0zkA AiWcfcfcMdXeFgplpeySX5OhxJEgzrw84Cp9yvFbd2CIz4OIRww+irxR9nnmKCTB X-Gm-Gg: AZFdTZcIiTdVOWU9245Foe2PwGJs1hAC0e+vdZ3Lbl2+0DrRUxiqF6CmcbXmq9gewPD ELJXrUFEiX/kZI+cOg9naVj7VNF0KcKahnNbOpU+PGOvMRLJPXd1Pg98cuVW/LKJzijLTGzFanr rTOf0xgbw71TFjsxucJQaeiEOjXPDUa9SggFxzZfBke2FEVgh/eGMmv4Bdr2LN8NHLLEjOYE76D YkxreUkV3LlWK8OAZOyi/16P2PXRgm8i3W+7GhY/Js9ZA0JVR151NI9ntXVQs1bPXMNo8yWuTx9 /7Gr1nvQkqTuddYZheE5zHYWYktMM0hARPcpgapfsUVCFy2vVzlIy98IHA5r9SPmWCqGAkpI3BP e8o5KtmdRt6FcshoQ1j0m+Yuv8sScKTsr3CNnNHqIoHzE+LVrSsB3S8W2k5QzLqrBH2XKYO/lhZ j6I44ar6ELkorlP1y0KyzbEAXuaonr0s04Y4EckRNYBPmgSZu63V58j4ObryDw+brb8aEYKDrdW UBvgGdM+vZD9AOCWkPQdlGXoYTvtU/GAxvWhA9k1G427keKb3Z2ksAhAktD8Ur/GjeAfWdD3j7O 0UPR6MZzSB0wmg1b7y1hGOVuD3n25Oc= 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-xfs@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