From: Hao-Yu Yang <naup96721@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@kernel.org>,
mingo@redhat.com, linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
David Hillenbrand <david@kernel.org>,
Eric Dumazet <edumazet@google.com>,
linux-mm@kvack.org
Subject: Re: [PATCH v2] futex: Use-after-free between futex_key_to_node_opt and vma_replace_policy
Date: Tue, 24 Mar 2026 23:54:59 +0800 [thread overview]
Message-ID: <acKz06p/kaSw+ANn@naup-virtual-machine> (raw)
In-Reply-To: <20260324140019.GE3738010@noisy.programming.kicks-ass.net>
So this patch is correct? What i need to do?
On Tue, Mar 24, 2026 at 03:00:19PM +0100, Peter Zijlstra wrote:
> On Mon, Mar 23, 2026 at 06:24:42PM +0100, Thomas Gleixner wrote:
>
> > > 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.
>
> I hate that sparse annotation; it mostly just makes the code unreadable
> for then requiring those unwieldy rcu helper functions.
>
> Not to mention we don't actually need any of that here, because:
>
> > Especially the writer side is required so that the proper memory
> > barriers are inserted for architectures with a weakly ordered memory
> > model.
>
> The vma->vm_policy thing is written under mmap_lock held for writing,
> and the futex consumer is a speculative read lock. Specifically the
> ordering is through the associated seqcount.
>
> All that is really needed is to extend the lifetime of the mpol to the
> associated RCU period. Which is exactly what this patch does.
>
> Want me to go write up a better Changelog?
next prev parent reply other threads:[~2026-03-24 15:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260313124756.52461-1-naup96721@gmail.com>
2026-03-23 17:24 ` [PATCH v2] futex: Use-after-free between futex_key_to_node_opt and vma_replace_policy Thomas Gleixner
2026-03-23 23:43 ` Hao-Yu Yang
2026-03-23 23:46 ` Hao-Yu Yang
2026-03-24 14:00 ` Peter Zijlstra
2026-03-24 15:54 ` Hao-Yu Yang [this message]
2026-03-24 16:36 ` Thomas Gleixner
2026-03-24 17:44 ` Peter Zijlstra
2026-03-24 19:25 ` Thomas Gleixner
2026-03-24 20:27 ` David Hildenbrand (Arm)
2026-03-25 15:14 ` Peter Zijlstra
2026-03-25 15:19 ` Eric Dumazet
2026-03-25 15:22 ` Peter Zijlstra
2026-03-25 15:24 ` David Hildenbrand (Arm)
2026-03-25 15:25 ` Eric Dumazet
2026-03-26 12:42 ` Hao-Yu Yang
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=acKz06p/kaSw+ANn@naup-virtual-machine \
--to=naup96721@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=edumazet@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@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