From: Hao-Yu Yang <naup96721@gmail.com>
To: Eric Dumazet <edumazet@google.com>
Cc: security@kernel.org, tglx@kernel.org, mingo@redhat.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] futex: Use-after-free between futex_key_to_node_opt and vma_replace_policy
Date: Fri, 13 Mar 2026 20:42:31 +0800 [thread overview]
Message-ID: <abQGN/Dmnf4Kf7n1@naup-virtual-machine> (raw)
In-Reply-To: <CANn89iKbKYNzPd5NQKsr+19WgBpTOouOsd6CcF4qKdpLS1RYwg@mail.gmail.com>
On Fri, Mar 13, 2026 at 01:26:21PM +0100, Eric Dumazet wrote:
> On Fri, Mar 13, 2026 at 1:08 PM Hao-Yu Yang <naup96721@gmail.com> 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.
> >
> > patch just initial attempt to patch and need more discussion.
> > I think we need to remove this path or add some lock.
> >
> > Fixes: c042c505210d ("futex: Implement FUTEX2_MPOL")
> > Reported-by: Hao-Yu Yang <naup96721@gmail.com>
> > Signed-off-by: Hao-Yu Yang <naup96721@gmail.com>
> > ---
> > kernel/futex/core.c | 23 -----------------------
> > 1 file changed, 23 deletions(-)
>
> Good catch !
>
> Adding rcu to __mpol_put() is really a no brainer.
>
> Thanks.
>
> diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
> index 0fe96f3ab3ef02e902e1676e750c2006ecd6147f..65c732d440d2f4e4566204429f1e5e7487ab8f91
> 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 0e5175f1c767d81394276559b9610c24d854f5bc..6dc61a3d4a32f74a06bf005acfd82d4a43112348
> 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");
Thanks for your review. I have send patch2. If this patch is good. I will cc to stable@vger.kernel.org
next prev parent reply other threads:[~2026-03-13 12:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 12:05 Hao-Yu Yang
2026-03-13 12:26 ` Eric Dumazet
2026-03-13 12:42 ` Hao-Yu Yang [this message]
2026-03-13 12:47 ` Eric Dumazet
2026-03-13 12:50 ` 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=abQGN/Dmnf4Kf7n1@naup-virtual-machine \
--to=naup96721@gmail.com \
--cc=edumazet@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=security@kernel.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
all inboxes | Powered by JetHome®