Re: [PATCH] uprobes: clear extra_consumers before pooling return instances

From: Masami Hiramatsu (Google)

Date: Mon Nov 30 2026 - 20:12:11 EST


On Tue, 24 Nov 2026 12:14:53 -0800
Andrii Nakryiko <andrii.nakryiko@xxxxxxxxx> wrote:

> On Mon, Nov 23, 2026 at 9:32 AM Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> >
> > May be this has something to do with dup_utask() -> dup_return_instance() ?
> >
> > If cons_cnt = 0 but ri->extra_consumers != NULL, then
> > dup_return_instance() -> kmemdup() will copy old->extra_consumers, but
> > but kmemdup(old->extra_consumers) won't be called?
> >
>
> I think all we need this just this:
>
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index c47b1ee266d5..f265527e6897 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -2118,6 +2118,9 @@ static struct return_instance
> *dup_return_instance(struct return_instance *old)
> kfree(ri);
> return NULL;
> }
> + } else {
> + /* old->extra_consumers can be a leftover buffer from
> ri reuse */
> + ri->extra_consumers = NULL;
> }
>
> return ri;
>
> cc'ing Keke Ming who was going to send this as a stand-alone fix
> earlier this summer.

+1. UAF/double-free happens when fork() shallow-copies a reused
return_instance with cons_cnt <= 1 in this function.

Clearing ri->extra_consumers = NULL in the else branch directly fixes
that aliasing without losing buffer reuse on the hot path.

Note that I also just replied to Keke's v2 thread [1] asking to split
this dup_return_instance() fix out into a standalone patch with
Fixes: 8622e45b5da1 and Cc: stable@xxxxxxxxxxxxxxx. When sending that
standalone patch, please also credit Keenan (Reported-by:) and Reza
(Tested-by:) from this thread.

[1] https://lore.kernel.org/all/20260822150906.528208-1-ming.jvle@xxxxxxxxx/

Thank you,

--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>