From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796019212; b=Lfx4EBcEeamUXDBUd2sfxp7iJjVtpUZ6h9aKvg+HzIQQ87COw3ZyIFGeLqxZM3/1FLY4 Xo9G7U8UwtWoDx1n9nl5E3IWSPOKMq8Sy77fJBoGiYPyxqEWNTMkO+SgFVOvY15KgFNR2 QcQxZyCMtGUwfJ7MpJeIrER69vfm8vDZ7nSpQ48fZFGNSoKtaKR7ZuCFFl6RqRmxXGdqE aZpg9n8P5MN3Yo+Hg8WAjDgQT+Q7oA5WaQzA+62BKppU7kWq1keRIODxUfB90o7zc4W7j 5ErOvsUnyAJt62XRXPMhgZx9ZSO6/CjeAn4jgmlFafZ7UKDqZsSTOOCL3k99mkfOfzQ== 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-Forwarded-Encrypted: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=nFBV8T5zwVEnZ3nj/NQs/PWSP/sckxSXxsfFlEA48BIqJgPkAJWUPgzY4GVoqwbTqAX7 rjutmTpH9Chzx2NJJ9gAYHrDnPDK8HJyFu4MHpQeqjCho2R0EjXfJ6WZ6MjKc+8TEBg5/ oS6OJaoByXs8M5MHLJ7tUdEmbY++Le64FDP3AqO9ldJlsizh7bQTDgz4FuxwB0Zw03/uk 3z/IC3VRYXMqnceQEfL24kTZz5bl8qJ59LN1B4Y4BHqjsTy1SHdZd9sR38uLCQhbuY6f8 vODspDCz4KHkHOzf+vCm9aAyT+xu+VpEMMnSSQYwgNHEe85wX8uzLQt3G+B9Ab2eJog== 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.169 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.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 837C9606A31C for ; Mon, 30 Nov 2026 06:13:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 837C9606A31C 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, unprotected) header.d=trailofbits.com header.i=@trailofbits.com header.a=rsa-sha256 header.s=google header.b=NMSUJtCV Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-386c4d2e2ccso9046327eec.0 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=bzYKO3P53p8XMM4ob5t6863lPml8movIP7G5aQH5wWg4Bd8Zk3CJgaLJsvTgHBIMzq 4mDufADUGDoQ9gszOFso3UaG+ajR0Jm4WLFk64tF3zcLszWisMiKwuJqS57ZtdJ5qlz4 nIKIpPFska6z/Wju+PQMh2JUUpeQkc0wQrX/pV2qxjlrPEDLSFx+eGh6F/Ga4dDmgOu3 dgVx9pvmcvhrbbsdgH04SG9JegszQe5RIwnwit4zfWA7KjUTTuc9raHtgmlG9We8MBCz tXT+eXBbX5Mf1x9aY/FVlJZxC7MYN+c3aGnuA/f29L8x5vdsY015roH/cjPZViDlraZb hYsQ== X-Forwarded-Encrypted: i=1; AL+hErHby80b79BI1jxC/2wiJl2W0jXAURhYCUH8jsPj+pRDjIowye+FfZUsoPIkdBltdzt3aIrZY2A0daBzQe4=@vger.kernel.org X-Gm-Message-State: APuU4Z9cs6s9Fy9+vMxEcA4YtTyVBjk1YGhbm1mb0vf+OKOOz0UrV4Si Nji7aYfumzG1C5m2LK15FbUv/81Rj00GOJ9rDGYe3I/0CketKpz1tYieUR4KdN4HRW4= X-Gm-Gg: AZFdTZeNmkEu4DYz5lNyleBruaZ8h5xgABL4ZCOQ2NEkCYNJa0z46R3nKEkJKFJR6Vy aCrT5TybqKPFnASRNGp9IEi6b3OsvuIxQefYj2pzYBBnJvOH1S+TJ3JcH0iuWPtXnVxqfhsPwmD Kqrel2lZRlfiWj7E7fx8GsGXEIWm8QWvD8UZ78DhplEkhUUvahDqEGVocrb6RcuVGEErjmu+UIc qd2rrUOKmQ6qxymnQCX3K3oNo28SXTKLq8x0qsQFrJeyrx8D4WEA/T+aZH3sq8829PnO2pvdnE4 bdYVQukgMzo3sHUt73dAUygMizjalUhQFp0UtbWYDqQ6AWdC9HyX8NHHnkScCJmFwXiqOReLTZr bSCtjDdG8Fc2f3+My2y+aSLI+yOhgR6EcEu/8j1MknxxlRrtdkzReJeLEVKVnt3DKK9O2w43gMj da9NMs92GhlDBRHfAQqBZdy+Q9vMtkmMT+xsS8WH7zI5Q6sJQLKvnxIRVSCgKnkdHNq/dUB7hbL CQsfuryvaXuxIvAYNy1tlerVr2q2DNzYRi0rCuEGRKdJo93s5xj+5XxRrfRToaFbrLz50xgh7tP Anf0whddQkV5fSRxENCt4o9ISwhFfnTzWtAPuovFCUd64FfBaQPcWtxuFAAXKCeWrZojCaLiZ/R 5EatILW3fkpy96YDxjQGliUiqNts= 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: linux-kernel@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; }