]> www.infradead.org Git - users/jedix/linux-maple.git/commit
uprobes: Ensure return_instance is detached from the list before freeing
authorAndrii Nakryiko <andrii@kernel.org>
Fri, 6 Dec 2024 00:24:16 +0000 (16:24 -0800)
committerIngo Molnar <mingo@kernel.org>
Mon, 9 Dec 2024 14:50:29 +0000 (15:50 +0100)
commit0cf981de7687b26ccc9bd4e6daa8fa6b177f91a9
tree9524a9b16393df550e98824d29b80a40cd31501f
parent636666a1c73313a0cc9a0a6671c29e2d6ebe16fb
uprobes: Ensure return_instance is detached from the list before freeing

Ensure that by the time we call free_ret_instance() to clean up an
instance of struct return_instance it isn't reachable from
utask->return_instances anymore.

free_ret_instance() is called in a few different situations, all but one
of which already are fine w.r.t. return_instance visibility:

  - uprobe_free_utask() guarantees that ri_timer() won't be called
    (through timer_delete_sync() call), and so there is no need to
    unlink anything, because entire utask is being freed;
  - uprobe_handle_trampoline() is already unlinking to-be-freed
    return_instance with rcu_assign_pointer() before calling
    free_ret_instance().

Only cleanup_return_instances() violates this property, which so far is
not causing problems due to RCU-delayed freeing of return_instance,
which we'll change in the next patch. So make sure we unlink
return_instance before passing it into free_ret_instance(), as otherwise
reuse will be unsafe.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Link: https://lore.kernel.org/r/20241206002417.3295533-4-andrii@kernel.org
kernel/events/uprobes.c