[tip: locking/core] futex: Avoid private hash use-after-free on final put
"tip-bot2 for Felix Hoffmann" <[email protected]> Tue, 04 Aug 2026 10:31:52 -0000
| Newsgroups | org.kernel.vger.stable,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <178583951210.1210945.18223157820047637311.tip-bot2@tip-bot2> |
The following commit has been merged into the locking/core branch of tip: Commit-ID: 1c7efabfbaf796f11000a46094a69955a01ec6cc Gitweb: https://git.kernel.org/tip/1c7efabfbaf796f11000a46094a69955a01ec6cc Author: Felix Hoffmann <[email protected]> AuthorDate: Fri, 31 Jul 2026 17:50:24 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 04 Aug 2026 12:29:45 +02:00 futex: Avoid private hash use-after-free on final put 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 <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: [email protected] Link: https://patch.msgid.link/[email protected] --- kernel/futex/core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/futex/core.c b/kernel/futex/core.c index 0864c6e..d3fcad4 100644 --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -139,8 +139,14 @@ static bool futex_private_hash_get(struct futex_private_hash *fph) void futex_private_hash_put(struct futex_private_hash *fph) { - if (fph && futex_ref_put(fph)) - wake_up_var(fph->mm); + struct mm_struct *mm; + + if (!fph) + return; + + mm = fph->mm; + if (futex_ref_put(fph)) + wake_up_var(mm); } static struct futex_hash_bucket *