Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: put uprobe link's path and task in release callback

There is no need to delay putting either path or task to deallocation
step. It can be done right after bpf_uprobe_unregister. Between release
and dealloc, there could be still some running BPF programs, but they
don't access either task or path, only data in link->uprobes, so it is
safe to do.

On the other hand, doing path_put() in dealloc callback makes this
dealloc sleepable because path_put() itself might sleep. Which is
problematic due to the need to call uprobe's dealloc through call_rcu(),
which is what is done in the next bug fix patch. So solve the problem by
releasing these resources early.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20240328052426.3042617-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
e9c856ca 03796540

+3 -3
+3 -3
kernel/trace/bpf_trace.c
··· 3157 3157 3158 3158 umulti_link = container_of(link, struct bpf_uprobe_multi_link, link); 3159 3159 bpf_uprobe_unregister(&umulti_link->path, umulti_link->uprobes, umulti_link->cnt); 3160 + if (umulti_link->task) 3161 + put_task_struct(umulti_link->task); 3162 + path_put(&umulti_link->path); 3160 3163 } 3161 3164 3162 3165 static void bpf_uprobe_multi_link_dealloc(struct bpf_link *link) ··· 3167 3164 struct bpf_uprobe_multi_link *umulti_link; 3168 3165 3169 3166 umulti_link = container_of(link, struct bpf_uprobe_multi_link, link); 3170 - if (umulti_link->task) 3171 - put_task_struct(umulti_link->task); 3172 - path_put(&umulti_link->path); 3173 3167 kvfree(umulti_link->uprobes); 3174 3168 kfree(umulti_link); 3175 3169 }