From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796019212; b=BXItmpdrusXfvRUtiHDKGVWQEBKjltIKIuo1wA/H2dsy/+J0Z+028tLSP+ynbLrlpm1u tzuY7+RpHj/Vzj7iO3o6C2jIbaA2ARKe1TPjlQSp3KJPKYfxuYqfpsnBXOQ35DYP2SCUf IEUR0qVXCsn/i6UGj2VQo98eT6uHvVYdVLI1xGtRw5e97gL1pg2lgmtTggjPyelwONNlt 4QLKnri6C4PJEvr2z1YSZaiUE9sJwGWL/vz+RJLOCzAMNEzXWJT2tBjKTemuarQJWoQ/w xBTXPyBPrdRv0jIbhSCGHJULcZv8uT3RQicCi5LFqD7GvPML0gqXhA9rHybwMqMaEKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796019212; 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:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=UpJBm+DdLFF7yk/z/T98+1ohmfrE7XNFdv6ONm9EWjY=; b=T2yWCgi72bsk2K03EYokC7lUTuR1saaGzSd4gQasIvJB1GR6KuGNQzXmt/BJOMLjhobf Q+IIYdq6wEHvuR4UfYB6HWK9s5E6/M0l5wjWRQwUdWcMBYecD6XQ7Vt71AWGzPAiUEEBG qpZzpEvmZPzHcGPAE2ITtZ/mn4tqkzvHz4WDk/l7dKSLgKMi78uPDmGlDDSpqG6rbUIiP d69vOjCGhQqLGBL3CTRNSnnJLZ2OKUldqYtVtMHrFD0DXUzPKjTYFVRz+/VTYOZPw+UHl B1HrcXc/uihBtJPjdhalAPQ3H2QmOk80UnhAGJyu/Szzqm5QGcC8uZTHS99pVJ6u/Yw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass header.d=trailofbits.com header.i=@trailofbits.com header.a=rsa-sha256 header.s=google header.b=NMSUJtCV; arc=none smtp.remote-ip=74.125.82.170 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (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 93945606A320 for ; Mon, 30 Nov 2026 06:13:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93945606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.a=rsa-sha256 header.s=google header.b=NMSUJtCV Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-38190551625so19100240eec.1 for ; Sun, 29 Nov 2026 22:13:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1796019212; x=1796624012; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=UpJBm+DdLFF7yk/z/T98+1ohmfrE7XNFdv6ONm9EWjY=; b=NMSUJtCVyKd5036cEzW37BUABsvj/zAkDjITbPo5RxDm6+IOFuCT+/u4L4lpioDn/r /U0tYwMSyhVvu9VjN5Wk/e08Wvd8DWhKo8JFB1GX8vJWvZwZciEx7lDzqVoqbkHoGqp7 AQG35SP/EsPF8nqejOWTXYJjIu7Ch5sGxumVhRrJA7KrDlSiuj3qBhFvPH9rPG3+0/bF 71crYa/vg4tpWJ5UkYRfKQIWd6KUEZw/KdUipEYz3LG1Ih1h+MeXb1TXfuRfe1jUr/Sr yDYDLqS4Xz8lBDfmJQzomvnbSpZJiAV0oHjK6URu/iOLl6El8bdA7434uivc/NifLS3w DO7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796019212; x=1796624012; h=content-transfer-encoding:content-type:mime-version: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=UpJBm+DdLFF7yk/z/T98+1ohmfrE7XNFdv6ONm9EWjY=; b=xHxQtPuB1vJrLYtzOb52qZtH0OajIQ4O7o+29LN6Ro6em3dH2fbxA19Guvy4Bg/9vb QIQbKl2GvepmbM+ACbBLFGKTKNcCcUMt2AFWPrzMaYik2rvkuQbRByau7l+n34aWJWLk soLcAWp5cks8q997FAnnbJ1KVPJTCZ6CZ1WAWrEgiAVOFIlIqmdOoQjWALcWifXyBax7 Sj0aQ46UhgoaFECbHMoqm5svVULawohPOhKa4knVO4lI/aLpEOEVJvX3YdnLf7qEkuqN 27MPD+/AijC5S2hoppDQr1Hccg4IwbL0ecEwSpX0e/grmFRyC/zkkvmWQrSk3juomg96 nL5g== X-Gm-Message-State: APuU4Z+Z4rNrkgLWRDoKPtJ09vcNjoJ9CKp2VwsPKB5QcmfjboR9/guD Vbvutr3MzolRZcCDTR31KnfRPGbjjQo1nXti2BxRSnQac+8b5JXihUuwrgpx1rk/InguZi6A2co 5VSFY X-Gm-Gg: AZFdTZfw8VTTYIrrA5YtU/EI4U1cAZ8c/79oWVomUWMe743k95gepli67B7VdJTragO bJQ5pcAugdpXcUlg4Kt0KJAk/kqM7QEMFkWnNo3qZkKr54ZwMPSaRszRFC8NjVd278iIgpTqlGL jOzV7YktRuyS4x075TgHmE0zTxtzf1bHw8log0TD3kxoo6PXZ9eV2WE4Y5ltmdQ+sFGekAPAn+n ZsG8+5cf0jmj3maEfeSlY/mOBine/b/VwMVCU8A1+U6chNdIT1+reuFTISHU5ZKDsctphkJ+9O6 Laymg3UzjEG3KnM9ZPuBxhAyrIfCgQmbetDl9SX7t9+Nb8B5vtuQ9q8xl6euxh0kfIW15nx4yB0 K8GZfs1W085vNu3IoduQKwq2ga5w24cMpPNrj0SvgZfdrbcUBa76wsuRUQNR8wJunSWR3gKJXmp OdXKIqigPNRuIt4Y5rOIa8SudD6U90z89RCcXPGf6+EKRQyDgCT8O4zioMIKJjqKZBai8Jlt35U FhQ0BHAHbi2CbsjycLGT5gdRN8ZcQtn974Ea8KmnrYd8zJX49U/0zi7QYBOWElIQ66IQs4C15IN K1fBlhtuiN6BJN7fbzGZRVsjCl7bTng39bnOIqhY2lv6nYW/vE7nEf/MR7uy4uJnqU1ea6sf7x4 uRWDARc1urSz5bVy/0NdoygAAgZM= X-Received: by 2002:a05:693c:8850:b0:386:b351:d5eb with SMTP id 5a478bee46e88-386b351dcddmr20808166eec.7.1796019211453; Sun, 29 Nov 2026 22:13:31 -0800 (PST) Received: from localhost.localdomain ([2603:8003:6d40:6669:69ad:25af:f892:8dbd]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385677c0c1dsm107546065eec.21.2026.11.29.22.13.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 29 Nov 2026 22:13:30 -0800 (PST) From: Artem Dinaburg To: stable@vger.kernel.org Cc: andrealmeid@igalia.com, dave@stgolabs.net, dvhart@infradead.org, linux-kernel@vger.kernel.org, mason@kernel.org, mingo@redhat.com, paulmck@kernel.org, peterz@infradead.org, tglx@kernel.org Subject: [PATCH 6.18.y] futex: Fix private hash use-after-free on resize Date: Mon, 30 Nov 2026 01:13:23 -0500 Message-ID: <20261130061323.13637-1-artem@trailofbits.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit From: Chris Mason Date: Thu, 1 Oct 2026 13:50:22 +0000 [ Upstream commit f35e3b5784221654f9cdbd6222275a7fa203f6c3 ] poll_state_synchronize_rcu(mm->futex.phash.batches) is used by futex_ref_drop() to check that a grace period has passed since the current hash was published. This relies on batches referencing a grace period which started after the hash pointer was assigned. __futex_pivot_hash() sets mmph->batches before it replaces mmph->hash: scoped_guard(rcu) { mmph->batches = get_state_synchronize_rcu(); rcu_assign_pointer(mmph->hash, new); } The scoped_guard(rcu) doesn't stop new grace periods from starting, and if one starts between those two assignments, futex_ref_drop() can move forward while a reader still holds a pointer to the old hash. Fix things by setting mmph->batches after assigning mmph->hash. The scoped_guard(rcu) isn't needed, so let's drop that as well. Fixes: 56180dd20c19 ("futex: Use RCU-based per-CPU reference counting instead of rcuref_t") Assisted-by: kres Signed-off-by: Chris Mason Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Paul E. McKenney Link: https://patch.msgid.link/20261001135022.2220288-1-mason@kernel.org [ Backport to 6.18.y: 6.18 predates commit 1f7f4816b9b0 ("futex: Move futex related mm_struct data into a struct"), so use mm->futex_phash and mm->futex_batches instead of mmph->hash and mmph->batches. ] Signed-off-by: Artem Dinaburg --- Hi, Please apply this to 6.18.y. It fixes CVE-2026-98788. The upstream commit does not apply as-is because 6.18 still uses the old mm_struct futex field names. The backport only renames those fields; the code change is otherwise identical. The fix has been in mainline since 7.3-rc6 and was backported to 7.2.y in 7.2.10. Kernels 6.12.y and older do not contain 56180dd20c19 and are not affected. 6.18.y already has the related futex fixes from 6.18.46 and 6.18.47: futex: Fix race in futex_pivot_pending() during private hash resize futex: Fix might_sleep() warning in futex_pivot_pending() futex: Avoid private hash use-after-free on final put futex: Fix race on the initial mm->futex.phash.ref allocation None of them changes the ordering in __futex_pivot_hash(), so 6.18.y still samples the RCU grace-period state before publishing the new hash. Compile-tested on 6.18.65 with CONFIG_FUTEX_PRIVATE_HASH=y. I used an LLM to help adapt the patch and draft this email, and reviewed the result myself. Thanks, Artem Dinaburg kernel/futex/core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/futex/core.c b/kernel/futex/core.c index e6fbeb2ac19014e08e636623d6cf2ba3a67c85f5..cb8cfa81d71ac4dc1cd4697624871e8d3bbd50dd 100644 --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -214,10 +214,12 @@ static bool __futex_pivot_hash(struct mm_struct *mm, futex_rehash_private(fph, new); } new->state = FR_PERCPU; - scoped_guard(rcu) { - mm->futex_batches = get_state_synchronize_rcu(); - rcu_assign_pointer(mm->futex_phash, new); - } + rcu_assign_pointer(mm->futex_phash, new); + /* + * mm->futex_batches must reference a grace period which started after + * mm->futex_phash was assigned. See futex_ref_drop(). + */ + mm->futex_batches = get_state_synchronize_rcu(); kvfree_rcu(fph, rcu); return true; }