All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: Cleanup ftrace hash in bpf_trampoline_put
@ 2022-08-02 13:56 Jiri Olsa
  2022-08-04 21:57 ` Song Liu
  2022-08-05 17:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Jiri Olsa @ 2022-08-02 13:56 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: bpf, Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Steven Rostedt

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

diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
index 0f532e6a717f..ff87e38af8a7 100644
--- a/kernel/bpf/trampoline.c
+++ b/kernel/bpf/trampoline.c
@@ -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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] bpf: Cleanup ftrace hash in bpf_trampoline_put
  2022-08-02 13:56 [PATCH bpf] bpf: Cleanup ftrace hash in bpf_trampoline_put Jiri Olsa
@ 2022-08-04 21:57 ` Song Liu
  2022-08-05 17:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Song Liu @ 2022-08-04 21:57 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Steven Rostedt

On Tue, Aug 2, 2022 at 6:57 AM Jiri Olsa <jolsa@kernel.org> 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)")
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Great catch! Thanks!

Acked-by: Song Liu <song@kernel.org>

> ---
>  kernel/bpf/trampoline.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index 0f532e6a717f..ff87e38af8a7 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] bpf: Cleanup ftrace hash in bpf_trampoline_put
  2022-08-02 13:56 [PATCH bpf] bpf: Cleanup ftrace hash in bpf_trampoline_put Jiri Olsa
  2022-08-04 21:57 ` Song Liu
@ 2022-08-05 17:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-05 17:50 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: ast, daniel, andrii, bpf, kafai, songliubraving, yhs,
	john.fastabend, kpsingh, sdf, haoluo, rostedt

Hello:

This patch was applied to bpf/bpf.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

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)")
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-05 17:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-02 13:56 [PATCH bpf] bpf: Cleanup ftrace hash in bpf_trampoline_put Jiri Olsa
2022-08-04 21:57 ` Song Liu
2022-08-05 17:50 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.