mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] uprobes: clear extra_consumers before pooling return instances
@ 2026-04-08 10:02 Keenan Dong
  2026-11-20 13:06 ` Reza Ghanbari
  2026-11-23 14:45 ` Oleg Nesterov
  0 siblings, 2 replies; 4+ messages in thread
From: Keenan Dong @ 2026-04-08 10:02 UTC (permalink / raw)
  To: peterz, mingo, acme, namhyung, mhiramat, oleg
  Cc: mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
	james.clark, andrii, linux-perf-users, linux-kernel,
	linux-trace-kernel, Keenan Dong

ri_pool_push() returns a return_instance to the per-task pool for
later reuse. The pool reset clears cons_cnt, but it leaves
extra_consumers behind.

A reused return_instance can later grow a fresh extra_consumers
array and then reach the cleanup path with a stale pointer from its
previous lifetime, leading to a double free of the recycled object.

Free and clear extra_consumers before putting the instance back into
the pool so every reused entry starts from a clean state.

Fixes: 8622e45b5da1 ("uprobes: Reuse return_instances between multiple uretprobes within task")
Reported-by: Keenan Dong <keenanat2000@gmail.com>
Signed-off-by: Keenan Dong <keenanat2000@gmail.com>
---
 kernel/events/uprobes.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 923b24b321cc..24b9884a2667 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1945,6 +1945,8 @@ unsigned long uprobe_get_trap_addr(struct pt_regs *regs)
 
 static void ri_pool_push(struct uprobe_task *utask, struct return_instance *ri)
 {
+	kfree(ri->extra_consumers);
+	ri->extra_consumers = NULL;
 	ri->cons_cnt = 0;
 	ri->next = utask->ri_pool;
 	utask->ri_pool = ri;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] uprobes: clear extra_consumers before pooling return instances
  2026-04-08 10:02 [PATCH] uprobes: clear extra_consumers before pooling return instances Keenan Dong
@ 2026-11-20 13:06 ` Reza Ghanbari
  2026-11-23 14:45 ` Oleg Nesterov
  1 sibling, 0 replies; 4+ messages in thread
From: Reza Ghanbari @ 2026-11-20 13:06 UTC (permalink / raw)
  To: Keenan Dong
  Cc: peterz, mingo, acme, namhyung, mhiramat, oleg, mark.rutland,
	alexander.shishkin, jolsa, irogers, adrian.hunter, james.clark,
	andrii, linux-perf-users, linux-kernel, linux-trace-kernel,
	ming.jvle

Hi Keenan, all,

I ran into this crash on my own and can confirm your patch fixes it, so
here is a Tested-by.

I was seeing it on an unpatched 6.18.63 (kernel.org source, built with a
Debian 13 config). With libfakechroot in /etc/ld.so.preload and a couple
of "setarch -R ls" loops running, I attach entry and return uprobes with
bpftrace to libfakechroot and to the same functions in libc, detaching
and reattaching every few seconds. The kernel oopses in handler_chain()
under krealloc() within a minute or so, which is the extra_consumers
path your patch is about. I haven't pinned down exactly which probes end
up sharing an address in this setup.

With only your patch on top of 6.18.63, the same probes ran 20
attach/detach cycles with no oops, and a fork-heavy variant ran 40 more,
also clean. 6.12.117 doesn't crash, which fits the Fixes: tag.

One more thing: Keke Ming's v2 for dup_return_instance() has a hunk that
clears extra_consumers when cons_cnt <= 1. With only your patch applied
the fork-heavy runs were clean, so I haven't seen a need for that hunk
for this crash.

I can send the reproducer and a full splat if that would help.

Tested-by: Reza Ghanbari <ghanbari.reza94@gmail.com>

Thanks,
Reza

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] uprobes: clear extra_consumers before pooling return instances
  2026-04-08 10:02 [PATCH] uprobes: clear extra_consumers before pooling return instances Keenan Dong
  2026-11-20 13:06 ` Reza Ghanbari
@ 2026-11-23 14:45 ` Oleg Nesterov
  2026-11-23 17:32   ` Oleg Nesterov
  1 sibling, 1 reply; 4+ messages in thread
From: Oleg Nesterov @ 2026-11-23 14:45 UTC (permalink / raw)
  To: Keenan Dong, Andrii Nakryiko
  Cc: peterz, mingo, acme, namhyung, mhiramat, mark.rutland,
	alexander.shishkin, jolsa, irogers, adrian.hunter, james.clark,
	linux-perf-users, linux-kernel, linux-trace-kernel

Andrii, can you take a look? I never understood this code in details,
and today I forgot everything...

On 04/08, Keenan Dong wrote:
>
> ri_pool_push() returns a return_instance to the per-task pool for
> later reuse. The pool reset clears cons_cnt, but it leaves
> extra_consumers behind.

So at first glance this doesn't look right no matter what...

> A reused return_instance can later grow a fresh extra_consumers
> array and then reach the cleanup path with a stale pointer from its
> previous lifetime, leading to a double free of the recycled object.

Can you add more details to explain the possible double free?
This is not immediately obvious, at least not to me.

Oleg.

> Free and clear extra_consumers before putting the instance back into
> the pool so every reused entry starts from a clean state.
> 
> Fixes: 8622e45b5da1 ("uprobes: Reuse return_instances between multiple uretprobes within task")
> Reported-by: Keenan Dong <keenanat2000@gmail.com>
> Signed-off-by: Keenan Dong <keenanat2000@gmail.com>
> ---
>  kernel/events/uprobes.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 923b24b321cc..24b9884a2667 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1945,6 +1945,8 @@ unsigned long uprobe_get_trap_addr(struct pt_regs *regs)
>  
>  static void ri_pool_push(struct uprobe_task *utask, struct return_instance *ri)
>  {
> +	kfree(ri->extra_consumers);
> +	ri->extra_consumers = NULL;
>  	ri->cons_cnt = 0;
>  	ri->next = utask->ri_pool;
>  	utask->ri_pool = ri;
> -- 
> 2.43.0
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] uprobes: clear extra_consumers before pooling return instances
  2026-11-23 14:45 ` Oleg Nesterov
@ 2026-11-23 17:32   ` Oleg Nesterov
  0 siblings, 0 replies; 4+ messages in thread
From: Oleg Nesterov @ 2026-11-23 17:32 UTC (permalink / raw)
  To: Keenan Dong, Andrii Nakryiko
  Cc: peterz, mingo, acme, namhyung, mhiramat, mark.rutland,
	alexander.shishkin, jolsa, irogers, adrian.hunter, james.clark,
	linux-perf-users, linux-kernel, linux-trace-kernel

On 11/23, Oleg Nesterov wrote:
>
> Andrii, can you take a look? I never understood this code in details,
> and today I forgot everything...
>
> On 04/08, Keenan Dong wrote:
> >
> > ri_pool_push() returns a return_instance to the per-task pool for
> > later reuse. The pool reset clears cons_cnt, but it leaves
> > extra_consumers behind.
>
> So at first glance this doesn't look right no matter what...
>
> > A reused return_instance can later grow a fresh extra_consumers
> > array and then reach the cleanup path with a stale pointer from its
> > previous lifetime, leading to a double free of the recycled object.
>
> Can you add more details to explain the possible double free?
> This is not immediately obvious, at least not to me.

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?

Damn this code is too complex for me ;) Anyway, I think the changelog
should say more.

Oleg.

> > --- a/kernel/events/uprobes.c
> > +++ b/kernel/events/uprobes.c
> > @@ -1945,6 +1945,8 @@ unsigned long uprobe_get_trap_addr(struct pt_regs *regs)
> >  
> >  static void ri_pool_push(struct uprobe_task *utask, struct return_instance *ri)
> >  {
> > +	kfree(ri->extra_consumers);
> > +	ri->extra_consumers = NULL;
> >  	ri->cons_cnt = 0;
> >  	ri->next = utask->ri_pool;
> >  	utask->ri_pool = ri;
> > -- 
> > 2.43.0
> > 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-23 17:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-08 10:02 [PATCH] uprobes: clear extra_consumers before pooling return instances Keenan Dong
2026-11-20 13:06 ` Reza Ghanbari
2026-11-23 14:45 ` Oleg Nesterov
2026-11-23 17:32   ` Oleg Nesterov

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®