Skip to contentSkip to conversation

ftrace: Fix missing synchronize_rcu() removing trampoline from kallsyms

PATCH In review Adrian Hunter 3 participants 5 messages Sep 1, 2020 – Sep 18, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ftrace: Fix missing synchronize_rcu() removing trampoline from kallsyms

Add synchronize_rcu() after list_del_rcu() in ftrace_remove_trampoline_from_kallsyms() to protect readers of ftrace_ops_trampoline_list (in ftrace_get_trampoline_kallsym) which is used when kallsyms is read.

Fixes fc0ea795f53c8d ("ftrace: Add symbols for ftrace trampolines")
---
 kernel/trace/ftrace.c | 1 +
 1 file changed, 1 insertion(+)
kernel/trace/ftrace.c +1 -0
index 275441254bb5..4e64367c9774 100644
@@ -2782,6 +2782,7 @@ static void ftrace_remove_trampoline_from_kallsyms(struct ftrace_ops *ops)
 {
 	lockdep_assert_held(&ftrace_lock);
 	list_del_rcu(&ops->list);
+	synchronize_rcu();
 }
 
 /*
Signature · 1 line
2.17.1
#1 lore raw
Quoted 16 lines · Adrian Hunter

Add synchronize_rcu() after list_del_rcu() in ftrace_remove_trampoline_from_kallsyms() to protect readers of ftrace_ops_trampoline_list (in ftrace_get_trampoline_kallsym) which is used when kallsyms is read.

Fixes fc0ea795f53c8d ("ftrace: Add symbols for ftrace trampolines")
---
 kernel/trace/ftrace.c | 1 +
 1 file changed, 1 insertion(+)
kernel/trace/ftrace.c +0 -0
index 275441254bb5..4e64367c9774 100644

kernel/trace/ftrace.c static void ftrace_remove_trampoline_from_kallsyms(struct ftrace_ops *ops) · line 2786

Quoted 5 lines
kernel/trace/ftrace.c +1 -0
@@ -2782,6 +2782,7 @@ static void ftrace_remove_trampoline_from_kallsyms(struct ftrace_ops *ops)
 {
 	lockdep_assert_held(&ftrace_lock);
 	list_del_rcu(&ops->list);
+	synchronize_rcu();
 }

Hurmph, we've just done a ton of that:

ftrace_shutdown()
synchronize_rcu_tasks_rude() ftrace_trampoline_free()
ftrace_remove_trampoline_from_kallsyms()

So would it not be better to move that call before the existing synchronize_rcu_tasks stuff rather than adding another synchronize_rcu() call?

#2 lore raw
Quoted 33 lines · On 11/09/20 2:41 pm, [email protected] wrote:
Quoted 16 lines · Adrian Hunter

Add synchronize_rcu() after list_del_rcu() in ftrace_remove_trampoline_from_kallsyms() to protect readers of ftrace_ops_trampoline_list (in ftrace_get_trampoline_kallsym) which is used when kallsyms is read.

Fixes fc0ea795f53c8d ("ftrace: Add symbols for ftrace trampolines")
---
 kernel/trace/ftrace.c | 1 +
 1 file changed, 1 insertion(+)
kernel/trace/ftrace.c +0 -0
index 275441254bb5..4e64367c9774 100644

kernel/trace/ftrace.c static void ftrace_remove_trampoline_from_kallsyms(struct ftrace_ops *ops) · line 2786

Quoted 5 lines
kernel/trace/ftrace.c +1 -0
@@ -2782,6 +2782,7 @@ static void ftrace_remove_trampoline_from_kallsyms(struct ftrace_ops *ops)
 {
 	lockdep_assert_held(&ftrace_lock);
 	list_del_rcu(&ops->list);
+	synchronize_rcu();
 }

Hurmph, we've just done a ton of that:

ftrace_shutdown()
synchronize_rcu_tasks_rude() ftrace_trampoline_free()
ftrace_remove_trampoline_from_kallsyms()

Quoted 3 lines

So would it not be better to move that call before the existing synchronize_rcu_tasks stuff rather than adding another synchronize_rcu() call?

Doesn't that mean removing the symbol while the trampoline is potentially still in use?

Could follow up the fix with a patch to allocate list nodes instead, and use call_rcu() to free it, so another synchronize_rcu() is not needed.

#3 lore raw
Quoted 34 lines · Adrian Hunter
Quoted 33 lines · On 11/09/20 2:41 pm, [email protected] wrote:
Quoted 16 lines · Adrian Hunter

Add synchronize_rcu() after list_del_rcu() in ftrace_remove_trampoline_from_kallsyms() to protect readers of ftrace_ops_trampoline_list (in ftrace_get_trampoline_kallsym) which is used when kallsyms is read.

Fixes fc0ea795f53c8d ("ftrace: Add symbols for ftrace trampolines")
---
 kernel/trace/ftrace.c | 1 +
 1 file changed, 1 insertion(+)
kernel/trace/ftrace.c +0 -0
index 275441254bb5..4e64367c9774 100644

kernel/trace/ftrace.c static void ftrace_remove_trampoline_from_kallsyms(struct ftrace_ops *ops) · line 2786

Quoted 5 lines
kernel/trace/ftrace.c +1 -0
@@ -2782,6 +2782,7 @@ static void ftrace_remove_trampoline_from_kallsyms(struct ftrace_ops *ops)
 {
 	lockdep_assert_held(&ftrace_lock);
 	list_del_rcu(&ops->list);
+	synchronize_rcu();
 }

Hurmph, we've just done a ton of that:

ftrace_shutdown()
synchronize_rcu_tasks_rude() ftrace_trampoline_free()
ftrace_remove_trampoline_from_kallsyms()

Quoted 6 lines
Quoted 3 lines

So would it not be better to move that call before the existing synchronize_rcu_tasks stuff rather than adding another synchronize_rcu() call?

Doesn't that mean removing the symbol while the trampoline is potentially still in use?

Hurm.. potentially yes. OK, lets do this first.

maintainer
#4 lore raw
Quoted 5 lines · On Fri, 11 Sep 2020 15:26:24 +0200 [email protected] wrote:
Quoted 3 lines

Doesn't that mean removing the symbol while the trampoline is potentially still in use?

Hurm.. potentially yes. OK, lets do this first.

OK, I queued this up to be tested and sent out for urgent.

-- Steve