Skip to content

Commit 0cf981d

Browse files
anakryikoIngo Molnar
authored andcommitted
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
1 parent 636666a commit 0cf981d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/events/uprobes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,12 +2116,12 @@ static void cleanup_return_instances(struct uprobe_task *utask, bool chained,
21162116

21172117
while (ri && !arch_uretprobe_is_alive(ri, ctx, regs)) {
21182118
ri_next = ri->next;
2119+
rcu_assign_pointer(utask->return_instances, ri_next);
21192120
utask->depth--;
21202121

21212122
free_ret_instance(ri, true /* cleanup_hprobe */);
21222123
ri = ri_next;
21232124
}
2124-
rcu_assign_pointer(utask->return_instances, ri);
21252125
}
21262126

21272127
static void prepare_uretprobe(struct uprobe *uprobe, struct pt_regs *regs,

0 commit comments

Comments
 (0)