Skip to contentSkip to conversation

ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del

PATCH Applied Jiri Olsa 4 participants 6 messages Mar 2

Subsystems (3)
lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 ftrace: Add missing ftrace_lock to update_ftrace_direct_add/del

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")
---
 kernel/trace/ftrace.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/ftrace.c +2 -0
index 827fb9a0bf0d..8baf61c9be6d 100644
@@ -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,
Signature · 1 line
2.53.0
#1 lore raw
Quoted 7 lines · Jiri Olsa

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.

Quoted 7 lines
Fixes 05dc5e9c1fe1 ("ftrace: Add update_ftrace_direct_add function")
Fixes 8d2c1233f371 ("ftrace: Add update_ftrace_direct_del function")

lgtm.

Steven,
should it land through ftrace tree?

Reviewed-by Steven Rostedt (Google) on v1 1/1
#4 lore raw
In reply to Jiri Olsa
Quoted 6 lines · On Mon, 2 Mar 2026 09:16:22 +0100 Jiri Olsa <[email protected]> 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.

Quoted 7 lines
Fixes 05dc5e9c1fe1 ("ftrace: Add update_ftrace_direct_add function")
Fixes 8d2c1233f371 ("ftrace: Add update_ftrace_direct_del function")

-- Steve

Quoted 24 lines
---
 kernel/trace/ftrace.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/ftrace.c +2 -0
index 827fb9a0bf0d..8baf61c9be6d 100644
@@ -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 lore raw
In reply to Alexei Starovoitov
Quoted 2 lines · On Mon, 2 Mar 2026 07:58:11 -0800 Alexei Starovoitov…

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

#3 lore raw
Quoted 9 lines · Steven Rostedt
Quoted 2 lines · On Mon, 2 Mar 2026 07:58:11 -0800 Alexei Starovoitov…

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.

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

Hello:

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

Quoted 14 lines · 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")
Quoted 1 line

[...]

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!

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