public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del
@ 2026-03-02  8:16 Jiri Olsa
  2026-03-02 15:58 ` Alexei Starovoitov
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jiri Olsa @ 2026-03-02  8:16 UTC (permalink / raw)
  To: Steven Rostedt, Alexei Starovoitov
  Cc: Ihor Solodrai, Kumar Kartikeya Dwivedi, bpf, linux-kernel,
	linux-trace-kernel, Daniel Borkmann, Andrii Nakryiko,
	Menglong Dong, Song Liu

Ihor and Kumar reported splat from ftrace_get_addr_curr [1], which happened
because of the missing ftrace_lock in update_ftrace_direct_add/del functions
allowing concurrent access to ftrace internals.

The ftrace_update_ops function must be guarded by ftrace_lock, adding that.

Fixes: 05dc5e9c1fe1 ("ftrace: Add update_ftrace_direct_add function")
Fixes: 8d2c1233f371 ("ftrace: Add update_ftrace_direct_del function")
Reported-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Reported-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Closes: https://lore.kernel.org/bpf/1b58ffb2-92ae-433a-ba46-95294d6edea2@linux.dev/
Tested-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 kernel/trace/ftrace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 827fb9a0bf0d..8baf61c9be6d 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -6404,6 +6404,7 @@ int update_ftrace_direct_add(struct ftrace_ops *ops, struct ftrace_hash *hash)
 			new_filter_hash = old_filter_hash;
 		}
 	} else {
+		guard(mutex)(&ftrace_lock);
 		err = ftrace_update_ops(ops, new_filter_hash, EMPTY_HASH);
 		/*
 		 * new_filter_hash is dup-ed, so we need to release it anyway,
@@ -6530,6 +6531,7 @@ int update_ftrace_direct_del(struct ftrace_ops *ops, struct ftrace_hash *hash)
 			ops->func_hash->filter_hash = NULL;
 		}
 	} else {
+		guard(mutex)(&ftrace_lock);
 		err = ftrace_update_ops(ops, new_filter_hash, EMPTY_HASH);
 		/*
 		 * new_filter_hash is dup-ed, so we need to release it anyway,
-- 
2.53.0


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

* Re: [PATCH bpf] ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del
  2026-03-02  8:16 [PATCH bpf] ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del Jiri Olsa
@ 2026-03-02 15:58 ` Alexei Starovoitov
  2026-03-02 17:47   ` Steven Rostedt
  2026-03-02 16:12 ` Steven Rostedt
  2026-03-02 18:00 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Alexei Starovoitov @ 2026-03-02 15:58 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Steven Rostedt, Alexei Starovoitov, Ihor Solodrai,
	Kumar Kartikeya Dwivedi, bpf, LKML, linux-trace-kernel,
	Daniel Borkmann, Andrii Nakryiko, Menglong Dong, Song Liu

On Mon, Mar 2, 2026 at 12:16 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Ihor and Kumar reported splat from ftrace_get_addr_curr [1], which happened
> because of the missing ftrace_lock in update_ftrace_direct_add/del functions
> allowing concurrent access to ftrace internals.
>
> The ftrace_update_ops function must be guarded by ftrace_lock, adding that.
>
> Fixes: 05dc5e9c1fe1 ("ftrace: Add update_ftrace_direct_add function")
> Fixes: 8d2c1233f371 ("ftrace: Add update_ftrace_direct_del function")
> Reported-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> Reported-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> Closes: https://lore.kernel.org/bpf/1b58ffb2-92ae-433a-ba46-95294d6edea2@linux.dev/
> Tested-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

lgtm.

Steven,
should it land through ftrace tree?

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

* Re: [PATCH bpf] ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del
  2026-03-02  8:16 [PATCH bpf] ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del Jiri Olsa
  2026-03-02 15:58 ` Alexei Starovoitov
@ 2026-03-02 16:12 ` Steven Rostedt
  2026-03-02 18:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2026-03-02 16:12 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Alexei Starovoitov, Ihor Solodrai, Kumar Kartikeya Dwivedi, bpf,
	linux-kernel, linux-trace-kernel, Daniel Borkmann,
	Andrii Nakryiko, Menglong Dong, Song Liu

On Mon,  2 Mar 2026 09:16:22 +0100
Jiri Olsa <jolsa@kernel.org> wrote:

> Ihor and Kumar reported splat from ftrace_get_addr_curr [1], which happened
> because of the missing ftrace_lock in update_ftrace_direct_add/del functions
> allowing concurrent access to ftrace internals.
> 
> The ftrace_update_ops function must be guarded by ftrace_lock, adding that.
> 
> Fixes: 05dc5e9c1fe1 ("ftrace: Add update_ftrace_direct_add function")
> Fixes: 8d2c1233f371 ("ftrace: Add update_ftrace_direct_del function")
> Reported-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> Reported-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> Closes: https://lore.kernel.org/bpf/1b58ffb2-92ae-433a-ba46-95294d6edea2@linux.dev/
> Tested-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>

-- Steve

> ---
>  kernel/trace/ftrace.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 827fb9a0bf0d..8baf61c9be6d 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -6404,6 +6404,7 @@ int update_ftrace_direct_add(struct ftrace_ops *ops, struct ftrace_hash *hash)
>  			new_filter_hash = old_filter_hash;
>  		}
>  	} else {
> +		guard(mutex)(&ftrace_lock);
>  		err = ftrace_update_ops(ops, new_filter_hash, EMPTY_HASH);
>  		/*
>  		 * new_filter_hash is dup-ed, so we need to release it anyway,
> @@ -6530,6 +6531,7 @@ int update_ftrace_direct_del(struct ftrace_ops *ops, struct ftrace_hash *hash)
>  			ops->func_hash->filter_hash = NULL;
>  		}
>  	} else {
> +		guard(mutex)(&ftrace_lock);
>  		err = ftrace_update_ops(ops, new_filter_hash, EMPTY_HASH);
>  		/*
>  		 * new_filter_hash is dup-ed, so we need to release it anyway,


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

* Re: [PATCH bpf] ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del
  2026-03-02 15:58 ` Alexei Starovoitov
@ 2026-03-02 17:47   ` Steven Rostedt
  2026-03-02 17:53     ` Alexei Starovoitov
  0 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2026-03-02 17:47 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Jiri Olsa, Alexei Starovoitov, Ihor Solodrai,
	Kumar Kartikeya Dwivedi, bpf, LKML, linux-trace-kernel,
	Daniel Borkmann, Andrii Nakryiko, Menglong Dong, Song Liu

On Mon, 2 Mar 2026 07:58:11 -0800
Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:

> Steven,
> should it land through ftrace tree?

I added my review by tag. It's small enough that you can take it through
your tree.

Thanks,

-- Steve

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

* Re: [PATCH bpf] ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del
  2026-03-02 17:47   ` Steven Rostedt
@ 2026-03-02 17:53     ` Alexei Starovoitov
  0 siblings, 0 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2026-03-02 17:53 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Jiri Olsa, Alexei Starovoitov, Ihor Solodrai,
	Kumar Kartikeya Dwivedi, bpf, LKML, linux-trace-kernel,
	Daniel Borkmann, Andrii Nakryiko, Menglong Dong, Song Liu

On Mon, Mar 2, 2026 at 9:47 AM Steven Rostedt <rostedt@kernel.org> wrote:
>
> On Mon, 2 Mar 2026 07:58:11 -0800
> Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
>
> > Steven,
> > should it land through ftrace tree?
>
> I added my review by tag. It's small enough that you can take it through
> your tree.

Ok. Applied.

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

* Re: [PATCH bpf] ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del
  2026-03-02  8:16 [PATCH bpf] ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del Jiri Olsa
  2026-03-02 15:58 ` Alexei Starovoitov
  2026-03-02 16:12 ` Steven Rostedt
@ 2026-03-02 18:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-02 18:00 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: rostedt, ast, ihor.solodrai, memxor, bpf, linux-kernel,
	linux-trace-kernel, daniel, andrii, menglong8.dong, song

Hello:

This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Mon,  2 Mar 2026 09:16:22 +0100 you wrote:
> Ihor and Kumar reported splat from ftrace_get_addr_curr [1], which happened
> because of the missing ftrace_lock in update_ftrace_direct_add/del functions
> allowing concurrent access to ftrace internals.
> 
> The ftrace_update_ops function must be guarded by ftrace_lock, adding that.
> 
> Fixes: 05dc5e9c1fe1 ("ftrace: Add update_ftrace_direct_add function")
> Fixes: 8d2c1233f371 ("ftrace: Add update_ftrace_direct_del function")
> Reported-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> Reported-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> Closes: https://lore.kernel.org/bpf/1b58ffb2-92ae-433a-ba46-95294d6edea2@linux.dev/
> Tested-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> 
> [...]

Here is the summary with links:
  - [bpf] ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del
    https://git.kernel.org/bpf/bpf/c/3ebc98c1ae7e

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] 6+ messages in thread

end of thread, other threads:[~2026-03-02 18:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-02  8:16 [PATCH bpf] ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del Jiri Olsa
2026-03-02 15:58 ` Alexei Starovoitov
2026-03-02 17:47   ` Steven Rostedt
2026-03-02 17:53     ` Alexei Starovoitov
2026-03-02 16:12 ` Steven Rostedt
2026-03-02 18:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox