From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382798; b=zXilx2QTFmRj7DkEgDwhHnBh7p9EdzS5FvESiRLgHJj+qtWoVcD3T5875OXoPTW/pzxS YArIpDDFoX1Ybf7mJPy2YtM1Npq4mXZz4ZfJgwNNAGK4yGrh4uGrOscC6UlFnBCzfZd4V UffLWKYySXgQdpb0n022CznZdqr9+Af4+GkEaxYwqJ3r/0AAuitkxHzF0FeGlDFlYiVsY wZSV0/8WfjLZSle7k8/b8lbf2D7zdHcL9T55FbrYSynULtX1Zxj5VpYhAF0t+Ha76/a4q MTNKjJHOg40g+s2LR0t7JICp5sE1shQ83v1gOvP9g2VvoCjYtPfTfIsf1EyaTQW5pqA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382798; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=dCXRWm5DiX+cph/1/OAOjYRtkOWIDGWtYJKTR1AMqVU=; b=1dcYi1ghViF2c7Ax8cYbu6Qjz4g5Ko0pNWxNLnS4/Zd/v8+7fNPgWMTjLHJicoBSv25L LbigCognwyqU0MVCQffT5t3hTY/rL7Feg3DUJ/vz1/1KKsW7HwhnGyfPt32U0g27sXHuI Q5THpKLCWwqZMvZONh2SojPt4iGhL51VCBX1svurhqlP+eKrWXqeeUJCusoLFPwRVuP9i BhS5MQjnVtRP8vpJ8YssGswUR5P5HLjlwSJdtrkGaXojveT4bfI6D9DIFxe9podGVQij+ wdA6B5FClQFdO64UywwzY/p38G3rIrUMwdABeCNIa1QZGqFj0H8f71jHlMWLcvSM3bw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=L39CWnUT; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E28B606A68B; Fri, 4 Dec 2026 11:13:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=L39CWnUT Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40E231F00937; Fri, 4 Dec 2026 11:13:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382797; bh=dCXRWm5DiX+cph/1/OAOjYRtkOWIDGWtYJKTR1AMqVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=L39CWnUTGLjSIPqdOzxxDcjS6LTOsqIos0z8LG3OZY+XXp3H/vifctE0LqM/pmEOt 83t3CsncckeLfoNp1UMROOd2ex/Aj2kd9STJR8t05sU/ENFstNWAMvhhYHG/E5j+7T gaPBKQnXocxh0qD/DAKK8qoC3UNyI1hTh1yj/Lz4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , "Peter Zijlstra (Intel)" , "Paul E. McKenney" , Artem Dinaburg , Sasha Levin Subject: [PATCH 6.18 604/703] futex: Fix private hash use-after-free on resize Date: Fri, 4 Dec 2026 19:08:23 +0900 Message-ID: <20261204100643.845560559@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason [ 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 Signed-off-by: Sasha Levin --- 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 e6fbeb2ac1901..cb8cfa81d71ac 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; } -- 2.53.0