bpf: Cleanup ftrace hash in bpf_trampoline_put
authorJiri Olsa <jolsa@kernel.org>
Tue, 2 Aug 2022 13:56:51 +0000 (15:56 +0200)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 5 Aug 2022 16:43:58 +0000 (09:43 -0700)
We need to release possible hash from trampoline fops object
before removing it, otherwise we leak it.

Fixes: 00963a2e75a8 ("bpf: Support bpf_trampoline on functions with IPMODIFY (e.g. livepatch)")
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/bpf/20220802135651.1794015-1-jolsa@kernel.org
kernel/bpf/trampoline.c

index 0f532e6..ff87e38 100644 (file)
@@ -841,7 +841,10 @@ void bpf_trampoline_put(struct bpf_trampoline *tr)
         * multiple rcu callbacks.
         */
        hlist_del(&tr->hlist);
-       kfree(tr->fops);
+       if (tr->fops) {
+               ftrace_free_filter(tr->fops);
+               kfree(tr->fops);
+       }
        kfree(tr);
 out:
        mutex_unlock(&trampoline_mutex);