From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C767730BB9B for ; Mon, 23 Mar 2026 23:43:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774309437; cv=none; b=kxwwvCCilZ2excXFDP/tfUOrKKALeG9qlhzREyKh1MqS1ByKeLxuby5XNN27fuv8kowKajnGuqFBNWIywpnFAK8cSRlWQl6U8Grmt4wQpyv5ZWSbvO+luvVfnQiiRfYaiaLE55BZid4EnZ8JqeHhkG59s2T7XOYZV8y2Ho6Vqbc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774309437; c=relaxed/simple; bh=kpAf8Rptgi6/so+2bIb7btCUK4GlCU2XHZbTHenFBxA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=M4Syb4QldRWAPRwstCw6kxFp56xuh+BNNrqinkkl5ZfeJI4sLFghg1OVcpL2QTteM/qNw8y7+i9C94qpxoSFI+RYudEHvztk+7rlQZbgAsVz8vEmKDphS7KMfBASGCg1Al/cF6yqO4rDmBj2SAwOiaiTFUTGCU7JL1afBeNGJFw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dGfBThsA; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dGfBThsA" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-8298fad2063so2335065b3a.3 for ; Mon, 23 Mar 2026 16:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774309435; x=1774914235; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=nk23nS4uNqRq9buSJNAiJ+S2Nw+SaX69zi7y546U44E=; b=dGfBThsATdR6LXdBWV394IZCbwwKGJO+ryci2LgAfj0PJBKTAMhhVoaKHzTuArMVax kSUOM/74JcuHLHGvSkzSFuTszAsoxmZzcdFOL6ma/XAVFjxAhotFsqa2FaP3FdV/u6H7 VrT5FvHpGfpdirTUuT0O6gCYHVNip/LPkiCpXDo/GGBIumjriPL2sQ3gSWiuK42Mt1dt SktmEevJJK54g/2yzqJfltJLO8hO/cjqbU379z2DZU0tVHzHjhszUH4fsOl+nh0zCGGa F2UEOnXhm8vzgZJJ6UPfz3hmacVlaZV2K+RPgBRlU/GHvPGEcGIXKhEAWGcSRObTwvrd Maww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774309435; x=1774914235; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nk23nS4uNqRq9buSJNAiJ+S2Nw+SaX69zi7y546U44E=; b=OapZoKDsmuPQtol1fVJu6ohwSGtwc5hWtBrOVbfyHbqZl9fAtARBvAnXVsuXkz7Xd5 PTFNXvcq3R+S9jhWT2x20vw1+k2nPGMpxkecyXRSs4EOYAENhwWFm0zL7patguHLvv1p YLa4YJjOBTte3HAB4YT93SyHIWy5821QO4+gn7WCRu5B5lU5LqxvEvkedQ0bPyE9Gtgm BbM7UiDrlt9oVb4kBdEOIC9GyfC8vK93Tq8RRWtKuJ+iszJgjGhufXQIYoBbUEPlj95F c/Jk1twFCTA4CRrwagEKZjuEfqxQIz5DY2XkzR3DhIhtNce/oxTsWo4LKuqaf61ITzSm A1Kw== X-Forwarded-Encrypted: i=1; AJvYcCWa+4L5vV43ROa1GKoSOCIpUiWVJCgsxheJidDEz74TvxFicDOnpeEQuZOvAhow3lWGFHyzyHD364oSYOk=@vger.kernel.org X-Gm-Message-State: AOJu0YxdodSQz/1bPjDyb72YzCDioGVDMrjUTgyC9sX//NCcZ5N6sBMj T6IU6PqhmaT5b/KaE4dzujkHvKQOBoKSH2alWxEIHK0y/p/0uIlAnAwC X-Gm-Gg: ATEYQzxVgft1rAW8LihFSvcNH1Ehfe75vL6UNHvPb9+/ckYWEB0p1DJKc74Q1mUXuas puTKdqAYgXDyId06U14AyNac4UshcN7zX5BLvYWvxEwW2ke8qleDMWUj/Y78hcNyYgNb/U2Anlt L19XLPRQ6INdFOqmjOnifU/OSc81PagwGkgZWc7AzwZ9Gin995CSYk6dC8aQ2GYpi8W9G6Aqacx d3g71rZeAmKQlTni0FIYlmRsHmhqeOlL1CGCiuIL/XrJtpV8XtCOcGvERq+Mng6X80MZ8QHXOUl xmyD3znDHMtB/381GXzM2grwjbei7mk8d8lYTiIlsJtyf4kTqscxpEjnuEJEOF5qwKBij+AQkmn GTomtC0isZ9pJCgH5kvPzMT6/r3h8TjU/SMmK/IgiT4QH2uGGPj+VfqH13wabjXnBfWBf+irKn0 BR14OnJbCXiMJBH0gXqGrG6dir6y9kHSdh63YqdAaFeV+kQMhC X-Received: by 2002:a05:6a00:9507:b0:82a:6d7b:cd3e with SMTP id d2e1a72fcca58-82a8c233005mr13119826b3a.19.1774309434923; Mon, 23 Mar 2026 16:43:54 -0700 (PDT) Received: from naup-virtual-machine ([140.113.92.221]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82b03be2589sm10084120b3a.24.2026.03.23.16.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 16:43:54 -0700 (PDT) Date: Tue, 24 Mar 2026 07:43:50 +0800 From: Hao-Yu Yang To: Thomas Gleixner Cc: mingo@redhat.com, linux-kernel@vger.kernel.org, Andrew Morton , David Hillenbrand , Eric Dumazet , linux-mm@kvack.org, Peter Zijlstra Subject: Re: [PATCH v2] futex: Use-after-free between futex_key_to_node_opt and vma_replace_policy Message-ID: References: <20260313124756.52461-1-naup96721@gmail.com> <87a4vyihlx.ffs@tglx> 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: <87a4vyihlx.ffs@tglx> OK, so now i need to submit v3 patch? On Mon, Mar 23, 2026 at 06:24:42PM +0100, Thomas Gleixner wrote: > Hao-Yu! > > On Fri, Mar 13 2026 at 20:47, Hao-Yu Yang wrote: > > I've removed the security list as this is public already. > Also added the mm list and the maintainers. While it fixes the futex > problem it is a change to the MM subsystem, so those people need to be > involved. > > > 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] > > Please trim the backtrace so it only contains the real important > information. > > https://docs.kernel.org/process/submitting-patches.html#backtraces-in-commit-messages > > > Fix by adding rcu to __mpol_put(). > > > > change-log: > > v2-v1: add rcu to __mpol_put > > The change history is not part of the change log, it want's to be placed > after the --- separator. > > > Fixes: c042c505210d ("futex: Implement FUTEX2_MPOL") > > Reported-by: Hao-Yu Yang > > Signed-off-by: Hao-Yu Yang > > This should have a > > Suggested-by: Eric Dumazet > > tag. > > > --- > > 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"); > > While this looks functionally correct it is incomplete in terms of RCU. > > The vma->vm_policy pointer needs to be marked __rcu. That then requires > to use rcu_dereference_check() at the reader side and > rcu_assign_pointer() and rcu_replace_pointer() on the writer side. > > Especially the writer side is required so that the proper memory > barriers are inserted for architectures with a weakly ordered memory > model. > > Thanks, > > tglx