Skip to contentSkip to conversation

bpf: Cleanup ftrace hash in bpf_trampoline_put

PATCH Applied Jiri Olsa 3 participants 3 messages Aug 2, 2022 – Aug 5, 2022

Subsystems (2)
lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 bpf: Cleanup ftrace hash in bpf_trampoline_put

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)")
---
 kernel/bpf/trampoline.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/bpf/trampoline.c +4 -1
index 0f532e6a717f..ff87e38af8a7 100644
@@ -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);
Signature · 1 line
2.37.1
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jiri Olsa

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)")

Great catch! Thanks!

Quoted 23 lines
---
 kernel/bpf/trampoline.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/bpf/trampoline.c +4 -2
index 0f532e6a717f..ff87e38af8a7 100644
@@ -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);
--

2.37.1

#2 lore raw
In reply to Jiri Olsa
This patch was applied to bpf/bpf.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf.git (master)
by Andrii Nakryiko <[email protected]>:

Quoted 8 lines · On Tue, 2 Aug 2022 15:56:51 +0200 you wrote:

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)")
---
 kernel/bpf/trampoline.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Here is the summary with links:
- [bpf] bpf: Cleanup ftrace hash in bpf_trampoline_put

    https://git.kernel.org/bpf/bpf/c/62d468e5e100

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html