From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F09E337CD5D for ; Fri, 13 Mar 2026 12:53:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773406386; cv=none; b=INeXvwEO2OSw+H1F8ja8o3toVVg18jIXRm+qDR1CcvSJ5flpcidZ0FT7jPzTollmaLqxJxmDItcDRYRBc0bN7H4EqK2PaBYv00c0ZrQhhQCQR67OhpLpdAJmUW6ZJu6znoocOA6CPBMJmGFQ0GIr134N4Az53HnMg066rELFodc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773406386; c=relaxed/simple; bh=mhE7Q84511jJgWrNq9/9tWJ5ybLAPeuccHqc5NPX3eI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OnpyyBnmnPT1TDzqwsBJ+jTOZJKDS3FDgJpfCT2kujfwkaW2W9jjaJnGPCPI2I8X7nInuOIZfvdxTiv3TftfW9BAKS+/UbthQrvCQgFIQoboZtuoM6SFQI2HCDa54b9VcgBt0X8i9DTzz3p8TzAo/aSnFHKXs31W1wLgo/Fn/08= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=O9NpuwUI; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="O9NpuwUI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=cujqiRNmMO8I28ODIpCl6QKAxGMAuK5u213jLmzAo34=; b=O9NpuwUI1tB2j/iEfFMgyshDFW a4msBvSHQRQ6AHgq9Fv/krU+MCSqhYQKzRhrk5Ha+EP0xXHYH2b9fXbHX9xNuAAMUUx3uX+Fo61IG vsInD5jSdX9eLkXY5FklVQ4N8moy0a6t+HJvzqE5+IFHYAHUN/l1DTO8lfxtzuEVitHDhzUfbrdbR 1blK/x2IenTPEwDHsEPRYNS4tHWG7NdisoaLFCXN3Z5cfxN6pXNleZcSUaTDt2Voy6yWo85Vfl96C hZkq/f6aILazeWWfBIgC1ZY0wJBdOeqKhRQSpT8Tb8VnfhVmwQ8zeaCrOUmk8FQd1Lqy5smPHLXO8 uxSc3jMw==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1w120h-00000003Ivv-3ISf; Fri, 13 Mar 2026 12:53:00 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 4C0AA3032C5; Fri, 13 Mar 2026 13:52:59 +0100 (CET) Date: Fri, 13 Mar 2026 13:52:59 +0100 From: Peter Zijlstra To: Hao-Yu Yang Cc: security@kernel.org, tglx@kernel.org, mingo@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] futex: Use-after-free between futex_key_to_node_opt and vma_replace_policy Message-ID: <20260313125259.GB2872@noisy.programming.kicks-ass.net> References: <20260313123940.51301-1-naup96721@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260313123940.51301-1-naup96721@gmail.com> On Fri, Mar 13, 2026 at 08:39:40PM +0800, Hao-Yu Yang wrote: > During futex_key_to_node_opt() execution, vma->vm_policy is read under > speculative mmap lock and RCU. Concurrently, mbind() may call > vma_replace_policy() which frees the old mempolicy immediately via > kmem_cache_free(). > > This creates a race where __futex_key_to_node() dereferences a freed > mempolicy pointer, causing a use-after-free read of mpol->mode. > > [ 151.412631] BUG: KASAN: slab-use-after-free in __futex_key_to_node (kernel/futex/core.c:349) > [ 151.414046] Read of size 2 at addr ffff888001c49634 by task e/87 > [ 151.414476] > [ 151.415431] CPU: 1 UID: 1000 PID: 87 Comm: e Not tainted 7.0.0-rc3-g0257f64bdac7 #1 PREEMPT(lazy) > [ 151.415758] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 > [ 151.415969] Call Trace: > [ 151.416059] > [ 151.416161] dump_stack_lvl (lib/dump_stack.c:123) > [ 151.416299] print_report (mm/kasan/report.c:379 mm/kasan/report.c:482) > [ 151.416359] ? __virt_addr_valid (./include/linux/mmzone.h:2046 ./include/linux/mmzone.h:2198 arch/x86/mm/physaddr.c:54) > [ 151.416412] ? __futex_key_to_node (kernel/futex/core.c:349) > [ 151.416517] ? kasan_complete_mode_report_info (mm/kasan/report_generic.c:182) > [ 151.416583] ? __futex_key_to_node (kernel/futex/core.c:349) > [ 151.416631] kasan_report (mm/kasan/report.c:597) > [ 151.416677] ? __futex_key_to_node (kernel/futex/core.c:349) > [ 151.416732] __asan_load2 (mm/kasan/generic.c:271) > [ 151.416777] __futex_key_to_node (kernel/futex/core.c:349) > [ 151.416822] get_futex_key (kernel/futex/core.c:374 kernel/futex/core.c:386 kernel/futex/core.c:593) > [ 151.416871] ? __pfx_get_futex_key (kernel/futex/core.c:550) > [ 151.416927] futex_wake (kernel/futex/waitwake.c:165) > [ 151.416976] ? __pfx_futex_wake (kernel/futex/waitwake.c:156) > [ 151.417022] ? __pfx___x64_sys_futex_wait (kernel/futex/syscalls.c:398) > [ 151.417081] __x64_sys_futex_wake (kernel/futex/syscalls.c:382 kernel/futex/syscalls.c:366 kernel/futex/syscalls.c:366) > [ 151.417129] x64_sys_call (arch/x86/entry/syscall_64.c:41) > [ 151.417236] do_syscall_64 (arch/x86/entry/syscall_64.c:63 arch/x86/entry/syscall_64.c:94) > [ 151.417342] entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130) > [ 151.418312] I would try and trim that trace, there is a lot of stuff that isn't really relevant. > Fix by adding rcu to __mpol_put(). > > Fixes: c042c505210d ("futex: Implement FUTEX2_MPOL") > Reported-by: Hao-Yu Yang > Signed-off-by: Hao-Yu Yang I would further suggest: Suggested-by: Eric Dumazet But yeah, other than that: Acked-by: Peter Zijlstra (Intel) > --- > change-log: > v2-v1: add rcu to __mpol_put > > include/linux/mempolicy.h | 1 + > mm/mempolicy.c | 2 +- > 2 files changed, 2 insertions(+), 1 deletion(-) > > diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h > index 0fe96f3ab3ef..65c732d440d2 100644 > --- a/include/linux/mempolicy.h > +++ b/include/linux/mempolicy.h > @@ -55,6 +55,7 @@ struct mempolicy { > nodemask_t cpuset_mems_allowed; /* relative to these nodes */ > nodemask_t user_nodemask; /* nodemask passed by user */ > } w; > + struct rcu_head rcu; > }; > > /* > diff --git a/mm/mempolicy.c b/mm/mempolicy.c > index 0e5175f1c767..6dc61a3d4a32 100644 > --- a/mm/mempolicy.c > +++ b/mm/mempolicy.c > @@ -487,7 +487,7 @@ void __mpol_put(struct mempolicy *pol) > { > if (!atomic_dec_and_test(&pol->refcnt)) > return; > - kmem_cache_free(policy_cache, pol); > + kfree_rcu(pol, rcu); > } > EXPORT_SYMBOL_FOR_MODULES(__mpol_put, "kvm"); > > -- > 2.34.1 > >