From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Felix Hoffmann <f3lix.dev@gmx.de>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 7.1.y 2/2] futex: Avoid private hash use-after-free on final put
Date: Tue, 25 Aug 2026 11:09:47 -0400 [thread overview]
Message-ID: <20260825150947.4024767-2-sashal@kernel.org> (raw)
In-Reply-To: <20260825150947.4024767-1-sashal@kernel.org>
From: Felix Hoffmann <f3lix.dev@gmx.de>
[ Upstream commit 1c7efabfbaf796f11000a46094a69955a01ec6cc ]
futex_private_hash_put() drops the reference to fph before evaluating
fph->mm for wake_up_var(). futex_ref_put() enables preemption again before
returning. If that put drops the final reference and the task is preempted,
another task can pivot to the replacement hash and free the old hash after
an RCU grace period. The first task then reads fph->mm from the freed
allocation when it resumes.
KASAN reports a slab-use-after-free in futex_private_hash_put(), with the
read at offset 24 in a freed kmalloc-512 allocation. The allocation and
free stacks point to futex_hash_allocate() and the RCU free path,
respectively.
Load the mm pointer while the fph reference is still held and pass the
saved value to wake_up_var(). wake_up_var() uses the pointer as a waitqueue
key and does not dereference the mm through it.
Fixes: bd54df5ea7ca ("futex: Allow to resize the private local hash")
Signed-off-by: Felix Hoffmann <f3lix.dev@gmx.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20260731155024.1150011-1-f3lix.dev@gmx.de
[ dropped the `!fph` NULL guard since this tree's callers already check, keeping the existing `if (futex_ref_put(fph))` form ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/futex/core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index cfaa96c009320..a68bbeb2db610 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -149,8 +149,10 @@ static bool futex_private_hash_get(struct futex_private_hash *fph)
void futex_private_hash_put(struct futex_private_hash *fph)
{
+ struct mm_struct *mm = fph->mm;
+
if (futex_ref_put(fph))
- wake_up_var(fph->mm);
+ wake_up_var(mm);
}
/**
--
2.53.0
prev parent reply other threads:[~2026-08-25 15:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 10:51 FAILED: patch "[PATCH] futex: Avoid private hash use-after-free on final put" failed to apply to 7.1-stable tree gregkh
2026-08-25 15:09 ` [PATCH 7.1.y 1/2] futex: Make futex_mm_init() void Sasha Levin
2026-08-25 15:09 ` Sasha Levin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260825150947.4024767-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=f3lix.dev@gmx.de \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox