From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796305924; b=oEk/Q5KriqEnruAhypeV/BHlo/rQ+UHBPiCYyVmp4/Zpr9lR5Ibp/ueiEBK39jtHaYxH j3wX5LLjAZO4oDTltqX/dBUEdw8WtL2zDylZuwMO9ADK4cIcfnuYz0bOFQyt/1xc15Otc xU0+XQUmW0LoKUPlwP4OP2klD92va6NM1fhlBhxC3i0sw6q5lPx1xv0YRdZNE+PQ0fUAA XVv6uaUSxt658eHFCwqJiZfstR6LFs3tTe3+PeYCwUBIThVV01NHrUUlYVExJ6dsrDWLr pq7qAnEnCtiUyJhuNi0eFWjg42H6pAILbLfvyIgwMSy8Fvi2KIqAFYwwliDqlsWDo4g== 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=WTGj+/un11EO8DqyDpapt0yYKMqzMjB+XYibhPeCTl12jsqb0qxD13bzRn4UaY14i9qZ THyeWlvMYKx+xWk05Gb9bpmKotIf63cfgs5Ebw7wRjLW2+HIgkUVJTZoqecoiThBnxIlm qUH0dBAD+6mNtpdXUjXGF8Uklx108pXZknQrw9SGh/B0hP+gRfTNNWpc8hph31KHAXfTO 5gh85KG5KX4eq7PyR5YN2B9+sx7lDyb55McCbkJ+t/6u1YINbUo1SChuQ/tPYQgvdXTZm eYsul0xzqXmG7nwbl2hpFoYpIWv36/2lW/bDbCVP4ya3ovPlIubtCzTXRR2eATiPmOA== 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.215.169 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 9C2E7606A32C for ; Thu, 3 Dec 2026 13:52:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C2E7606A32C 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-pg1-f169.google.com with SMTP id 41be03b00d2f7-cdd9d0c9bbdso8149103a12.1 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=htL0+JeNubNQNPsXv3i56gjN9KDtHa32QjzwCCchPYhZW9KZ/q7JxSlLOV8QmLXbeH SVO9v0iTZ7YA8aWL9a2VVklRTwcfkgnSfQczoNhSeGvFvHGroncVKfcMXiuO0GfLk2O9 xOFYgDNuA/GgX2rpjf4wTFpBQWg9dmM7ErdjrTf4QZ8hzNyAr+6cJvD2VAfvLHUP4BPh a3wPOrhxDUrtQ9LU+mpMXG7EHni14pWpFKlnHEbMGClLgUBI2cjDmamxzjSUjo/FXoRi k8kWjrMQmsiN6Yerr0zdhQ2El59eXwnDFZHrnMUxjIAf3CaL72AZEzJGkC3CQnDotQL8 PzJw== X-Gm-Message-State: APuU4Z+BOPZR6Svq+8EZVwrbPB9bAxiOcXHNxmRLnbUwCtTEqF4dx/AW 0UlJeBfaqGta8kM1iYBvsjxE4XEz7CI9aiPtKRQT0hmb44wPmNLeXSPzxKDldQ== X-Gm-Gg: AZFdTZd1RGmXqBWLV9Xb8o+k5EoqRHl5WFtr1RZL4LtRzRK9xByjYLfnyn1WjPA0lNa 7gxpWLphuTzjfjyLKcl+aM1l10DH+xDk5TkcPyYcvXwjR0QdxpI0NGMyKznmUhhFsqRnt5Q2Hnd F3p3BxAUsrWiF5+5xqWy7S96NkYbVDyeyZ0b/CZGjUh1sfxuhjlCc9tZYXwY9+TYS8S7q/bvWKh WyA6Sj33Y3f3yRrPw6so86i656zA31kKIbfdqBmGzM+qPR0I9L6awsph3PIe5lzeeZl1W/yN+U8 C6b+W2wszxjgJKlUW6PXLql14TiLkhyQzRQVsRJaxfgdNcPKJpg/O+hRL1x1Gsu5Pc0tlMlt3Y/ 8WJWFPmNadUt9+Pk2UttlsXE2R0ntGK5iBrxfA6acZQGC6o3zPczgkWP6C9ZgarnL3eGAmWHDq5 Amx85FS3wBMCgAZbWDQs1t4dfqXsLbu09yhVXfvV4uGjyCK7FgoVc/uzx3BkuGFJIySv4o6WUAQ OEVSYKyFgtrYyecC4OSI+LtL/WWkZ5qo8DK2JffP2fLxWA11ejKqMc8kFzPxXx3zpHQMjr+RN84 IzVXNqX6b4XOf9MA3w3BL4yn 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-xfs@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 /*