From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796305924; b=Eqs28LiXQYCYIa5ezbiraRjjSauJot5xwpxP205tz6u11xzKNAmrDSuxudJJ+HFYP8yX Sb+33iZgywj9l6KPkZiasmi67ULr8YyEXMAVNKHZH3ay8C0DlmhOJeF1IyPUssACWHRdF tUqlO7GIPdt5gWWmFbmHSoopR9A0fBOYEYs0jGPhyCbej5FwMM9khbRUG4FbEVgwK3HtZ FlOyEibqIVl/Dmxs5C7XZCWZ0L8dlr5XdmUl19UcgC9MG6w1b9UKx05n0uuukqmyrW3IW gC14hsmsvoXy0hAbX5UOTiHsImMs3DNK6UP30b1Aa26enFhUgxXVa2MEh6X9vkpaLnQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796305924; 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=hF+Ym/d86wNDjOf9aom/vNOp+/13VmpxIeE4A/Usx8s=; b=mH/zu2EnXG4M4mvrbEeHQOO4NuHqXvRi+DbvlRq831LZ5vkPPmWVznYljlHFdi+zVOtA A/lpuKcoz/CFz6B2DscojweeY0fDFkjmztUbIE5xlibGlvFKSOtolpOq1dsBXOYNxZA6V IatkYtHFI8gQyTsjfVHZMnv8sRtZmyLOpw4purz8kHBvGri4dXnWgqs+owm2XQSIOBxC4 483uUoelpw4dXOMwSi96EOitu+aLVrfZdWM0n2AZNoXkYprcvn4aVU16ayJNjou17Qcyi 7DE59YMF8YsGnOWSt4dp2EqNw9R51QghiKlIE43DjlbW6J1Q2X3Q4pSm431ftnEcLyA== 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=N2OHa5aV; arc=none smtp.remote-ip=209.85.216.54 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 99F24606A322 for ; Thu, 3 Dec 2026 13:52:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 99F24606A322 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=N2OHa5aV Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-3b532dfb874so4615444a91.3 for ; Thu, 03 Dec 2026 05:52:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796305923; x=1796910723; 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=hF+Ym/d86wNDjOf9aom/vNOp+/13VmpxIeE4A/Usx8s=; b=N2OHa5aVlKmJFM7ILgd+XgYL6+KzDDaONZXHo8jShAD228I7qBslzZ/CpnXlLVDP8L /aR/Apwc+Eesgn0sdoMxaahdZYeTBUEqmugZfQRDyTCQgveNpXz7xDbusUPalFh/c2W5 ViyXvvTVmu5uAHLbIKjXj+O065DOqNd+FUF9k45ORui0JMR45bhBzqxvqrl6qvduOlyn EuVB/EsIYscZ9aF/vepRzlA/LgsKtLB508DnCndgUSoJb22+0IdVTXuAGxRAulsw4Yae XfGP4gmxbkGtpqYzMJEQg/c65oaqMrgrjVUrcuQ/VNJjWycLIKrDvEnrdcs3gJYyJn/i pqSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796305923; x=1796910723; 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=hF+Ym/d86wNDjOf9aom/vNOp+/13VmpxIeE4A/Usx8s=; b=m0QNZ9iA0Hm8jUI8/WsQShPJnB+a0StamN4ZB4r6oJV7ivjc70mo1ZuSKOJSu4rAX0 ycRIqqGi/aQOn7bWcSWRnjDC1li0nTCzj2xeYOZx3/5/osyd1lzDIVfBJEeBzQAWJXGm zsUU8xRKQqtyTOlrk9d7r9MyQJdgCC2zMTfpQ9J17QgyutIeDrMWzVogsXnzRxdBrd0N vSwMQ3VZgihx8P1osjLPvGtt8pOpJb/7wxG/gaIYlbHWzBxIVPsD5D37W9VxB+FzOlA3 jvUhGISdITrWePNm4eJgMcfBW+iuT+TjaedTW8E6f7ARqMXZnZwLtA7nzgbXDQNzSD8U Lizw== X-Gm-Message-State: APuU4Z9tPDSNj9XZe6aeGLkakotOBYPsuPw67Y7mmvN32K1wpzVU8koW Gy0zKtex5TvSM0kc7UETnWYtfWkYcKi+NHZBhs98U0mzP0BewHJwYEZU X-Gm-Gg: AZFdTZdIdvPdRnLGI+hzRrYVIcwNcPisek0xWd3A/oVatzXL6NeLblAUq0IygmRY2R+ D/e6/9zZ1OQzN5DxzY6ZOTAJ3sTFRfvdJFYsit3r2jJnN2+cTMq1EzLV8on5dUkHy1Oxzgedxep RLA7jz0fKLejJYXDh8fLACmKWIvpFBOXK/qFEvDgOhKtzOBqrrgyrL/renYFus5jPmbvGL3v0QU nZEEaTimg0KJEdBz6QXI3VPglEtL5iVeKYeKpmyhP7w2s3I37d1TE85H4Ij5/q6cyfCiigYK5Ae gc5yxQ47bZsOegfGDaQGC1rxi3qT0Yc25Vs9LJ0jvlL0Wjtln3cNI0941iY9bT66MjV0PjiGYq8 biv1Hn7xAclrwS1trCeoT0v3zxFTHwsQE70Azjo1kIuG3hm2oHzTQpEP3mKusY2FiRO2QNDGaSi V8+ev7zS7IvvyoJrIYRhQco6xvcBZX01ZCoO2Bod5mSDOwunq988xYEgH5Kf7S39xvFmhtCbkX5 pvwcWNLVfiYHXKZSI49EPwn+975o+TiLtI3cky4bSD08+wZgPQljslW600/zZS6jjDPAFdzm2aQ 8rYGRMoTYCwr2PJyt+FxUFo3 X-Received: by 2002:a17:90b:5546:b0:3b4:c66d:2633 with SMTP id 98e67ed59e1d1-3b4c66d280emr37040720a91.62.1796305922764; Thu, 03 Dec 2026 05:52:02 -0800 (PST) Received: from DESKTOP-UCPRL76.localdomain ([2602:f919:106::b8]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c7d65000sm4458804a91.11.2026.12.03.05.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 05:52:02 -0800 (PST) From: Zheng Shuhao To: linux-xfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, hch@infradead.org, cem@kernel.org, djwong@kernel.org, hemanth.selam@gmail.com, shinsj4653@gmail.com, syzbot+e7f24354da9f7915bc54@syzkaller.appspotmail.com Subject: [PATCH v3] xfs: fix slab-use-after-free in xrep_newbt_free() Date: Thu, 03 Dec 2026 21:22:03 +0800 Message-ID: <179630412330.565.9260762935217160800@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 On Wed, Dec 2, 2026 at 07:28:34AM +0000, Christoph Hellwig wrote: > Using the control flow instead of global state is usually preferable. > I.e. check which path can free the autoreap information and treat them > differently using a goto or similar. I think the only relevant call is > xrep_newbt_free in the xrep_newbt_free loop, but I'm not an expert on > this code, so please double check. I considered changing the control flow, but found that this would make error-path handling more complex because the defer-finish failure paths would need to be handled separately. I therefore kept the existing control flow and used a standard list traversal to check whether the exact deferred item is still pending before unpausing it. I compared this with checking: if (!list_empty(&sc->tp->t_dfops)) before calling xfs_alloc_commit_autoreap() in xrep_newbt_free(). Both approaches produced the same results with the reproducer and relevant xfstests. The current patch is more robust because it checks the exact item referenced by the autoreap reservation, rather than only checking whether the transaction has any pending deferred items. An autoreap reservation can retain a pointer to a deferred item after a failed defer finish cancels that item. This patch checks that the exact item is still on the transaction's pending list before unpausing it. Testing: - The focused reproducer triggers the reported KASAN use-after-free on the baseline kernel. No KASAN use-after-free was observed with this patch in the recorded runs. - I reran all 150 test IDs extracted from the earlier exact-dfp xfstests run using a corrected 4 GiB guest root filesystem and corrected device-mapper setup. The results were 144 passed, 5 failures, and 1 skipped test. All XFS cases passed, and no patch-specific failure was observed. - The five failures were also present with the baseline and list_empty() versions: generic/131, generic/571, generic/786, and generic/787 failed because guest networking was unavailable; generic/794 found the same EOF-gap issue on the baseline. generic/470 was skipped because the QEMU test device does not support DAX. - A five-run 512 MiB benchmark averaged 45.214 seconds on the baseline, 44.849 seconds with the list_empty() variant, and 45.439 seconds with this lookup. The measurements showed no meaningful performance difference. 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 --- v3: - Keep the existing control flow and check whether the exact autoreap item is still on the transaction's pending deferred list. - Compare the exact-item lookup with the list_empty() approach. diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index f762dcce8d133..74c86c48d7fbf 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -2774,8 +2774,18 @@ xfs_alloc_commit_autoreap( struct xfs_trans *tp, struct xfs_alloc_autoreap *aarp) { - if (aarp->dfp) - xfs_defer_item_unpause(tp, aarp->dfp); + struct xfs_defer_pending *dfp; + + if (!aarp->dfp) + return; + + /* The deferred item might have been canceled by a failed defer finish. */ + list_for_each_entry(dfp, &tp->t_dfops, dfp_list) { + if (dfp =3D=3D aarp->dfp) { + xfs_defer_item_unpause(tp, dfp); + return; + } + } } =20 /*