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 8D7533E63A3 for ; Wed, 25 Mar 2026 15:14:52 +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=1774451694; cv=none; b=rAoLZjkIbxgAjdLl30AgvA19FFw1wCkWe854gy7o0SZ872D7/YRknAkW/qMNdaOX2qT66m4Pkx79IF7MmNM98uwAhDMDxzJxayv4fAByNKyDYO8C4DNA0RqoYXRpq1fCnsR6X8WmtItePdt6LaNhM81wQHDTDjvfR2piGX1wHMk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774451694; c=relaxed/simple; bh=0gI1TU8hN8bWOYKBS6HZ5O/2VXcOGtIQ3CqtY9k3qSM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Dyfj51m/rPkz3aISp6WHDLCegRZuE6/kqKAmUUa/KHv3O9q/EV4uV2RDTUkEoa/YphY3RLC3D57NISy63vN3ELxUTUJiL2CMDC3RCPbNCeBWHKomJ5y/D3NL+kcIGsJFhnf3WYGGICtdqD5xKGWLT9oMA2wHJXOt3oV3fS1T/Nw= 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=CRX3aX3T; 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="CRX3aX3T" 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=T3Ov7FjiYremHpEShBz/unCCCoOiTOaqvTiJ6hyZmUE=; b=CRX3aX3Ttk456hTBtCeBHKmSaJ ttDysMdpK0PRepez0vQSlY2dE4WFSWNm3TywAq63zr80MuvxQwBkpUFOW5ttpVg9PYv+57v/nY+By b7xy9TAHN0aeDK0yuInOZeuX+fhitapaLwdEUVKwIuSOl5ZWG9oj9GMo+22qeWKEZM/biJRQyB1GD QJ10s3qn3/wHnahrXKkrSizpSudPNs7lGvDmh9+M/vpYFVHHfaeL4di23MPf/aCb+s7sknDjjp4qB DC0WAVlG1sARSzXTGbskTDUCPSXDzmOK+QMw87wAnT5Wvr/TgXWw3lNhfJq/80UXUSE5nXnXp7fon gOJqULRA==; Received: from 2001-1c00-8d85-5700-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:5700:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1w5PwU-00000006S4q-21CN; Wed, 25 Mar 2026 15:14:46 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 85009300312; Wed, 25 Mar 2026 16:14:45 +0100 (CET) Date: Wed, 25 Mar 2026 16:14:45 +0100 From: Peter Zijlstra To: "David Hildenbrand (Arm)" Cc: Thomas Gleixner , Hao-Yu Yang , mingo@redhat.com, linux-kernel@vger.kernel.org, Andrew Morton , Eric Dumazet , linux-mm@kvack.org, Lorenzo Stoakes , "Liam R. Howlett" Subject: Re: [PATCH v2] futex: Use-after-free between futex_key_to_node_opt and vma_replace_policy Message-ID: <20260325151445.GH3738010@noisy.programming.kicks-ass.net> References: <20260313124756.52461-1-naup96721@gmail.com> <87a4vyihlx.ffs@tglx> <20260324140019.GE3738010@noisy.programming.kicks-ass.net> <87fr5pgp5x.ffs@tglx> <20260324174418.GB1850007@noisy.programming.kicks-ass.net> 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: On Tue, Mar 24, 2026 at 09:27:41PM +0100, David Hildenbrand (Arm) wrote: > So IIUC, futex_key_to_node_opt() looks up a VMA under RCU, without > holding the mmap lock. Concurrent mmap-write lock is detected by using > the mmap_lock_speculate_try_begin()/mmap_lock_speculate_retry() seqcount. > > After looking up the VMA, we access the VMA policy. > > vma_policy() does a straight vma->vm_policy. > > What prevents the compiler here to do some load tearing while it is > getting modified by mbind()? Or what stops the writer side to to some > store tearing? > > Shouldn't we be using at least READ_ONCE/WRITE_ONCE() etc? Bah, at that point we might as well RCU the thing like so, I suppose. --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1026,7 +1026,7 @@ static int vma_replace_policy(struct vm_ } old = vma->vm_policy; - vma->vm_policy = new; /* protected by mmap_lock */ + rcu_assign_pointer(vma->vm_policy, new); /* protected by mmap_lock */ mpol_put(old); return 0; diff --git a/kernel/futex/core.c b/kernel/futex/core.c index 4bacf5565368..6336a80e3dca 100644 --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -342,7 +342,7 @@ static int __futex_key_to_node(struct mm_struct *mm, unsigned long addr) if (!vma) return FUTEX_NO_NODE; - mpol = vma_policy(vma); + mpol = rcu_dereference_raw(vma->vm_policy); if (!mpol) return FUTEX_NO_NODE;