Re: [PATCH v2] uprobes: Free utask on dup_return_instance() failure
From: Masami Hiramatsu (Google)
Date: Sat Nov 28 2026 - 07:33:22 EST
Hi Keke,
Sorry for leaving this patch unattended for so long.
On Sat, 22 Aug 2026 23:09:06 +0800
Keke Ming <ming.jvle@xxxxxxxxx> wrote:
> dup_utask() installs the new uprobe_task in t->utask before copying
> return_instances. If dup_return_instance() fails, the partially copied
> utask is left attached to the child task.
>
> Free the partially copied utask before returning -ENOMEM.
>
> Also, dup_return_instance() copies the return_instance before fixing
> up extra_consumers.
>
> Here, if no deep copy is needed, clear the copied extra_consumers
> pointer.
Thanks for the update.
Looking closely at v2, this patch actually bundles two distinct changes
and needs to be split (so that each one can focus on single issue):
1. Clearing ri->extra_consumers = NULL in dup_return_instance():
This fixes a real, independent double-free / use-after-free bug that
can happen on normal fork() even without any allocation failure.
ri_pool_push() resets ri->cons_cnt to 0 while keeping
ri->extra_consumers allocated for later reuse via krealloc(). When
such a pooled return_instance is reused with cons_cnt <= 1 and the
task forks, kmemdup() copies old->extra_consumers into the child's
return_instance (shallow copied), causing both parent and child to
alias the same heap buffer.
Please split this fix into its own standalone patch with an accurate
subject and changelog explaining the ri_pool_push() reuse scenario
and the resulting double-free / UAF. That should have:
Fixes: 8622e45b5da1 ("uprobes: Reuse return_instances between multiple uretprobes within task")
Cc: stable@xxxxxxxxxxxxxxx
2. Calling uprobe_free_utask(t) on dup_return_instance() failure in
dup_utask():
As Oleg pointed out on the v1 thread, freeing t->utask inside
dup_utask() alone is not sufficient because uprobe_copy_process()
returns void after the "No more failure paths" point in
copy_process() (and mm_release() already calls uprobe_free_utask()
on exit). According to the discussion, I think you will implement
option B. In this case, please add below Fixes tag.
Fixes: 248d3a7b2f10 ("uprobes: Change uprobe_copy_process() to dup return_instances")
Thank you,
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>