Skip to contentSkip to conversation

ftrace: Free the trampoline when ftrace_startup() fails

PATCH In review Miroslav Benes 2 participants 3 messages Aug 31, 2020 – Sep 18, 2020

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

PATCH 1/1 ftrace: Free the trampoline when ftrace_startup() fails

Commit fc0ea795f53c ("ftrace: Add symbols for ftrace trampolines") missed to remove ops from new ftrace_ops_trampoline_list in ftrace_startup() if ftrace_hash_ipmodify_enable() fails there. It may lead to BUG if such ops come from a module which may be removed.

Moreover, the trampoline itself is not freed in this case.

Fix it by calling ftrace_trampoline_free() during the rollback.

Fixes fc0ea795f53c ("ftrace: Add symbols for ftrace trampolines")

---

It would be fair to add

Fixes f8b8be8a310a ("ftrace, kprobes: Support IPMODIFY flag to find IP modify conflict")

too. The situation was a bit more complicated back then though since RCU-tasks support was missing.

 kernel/trace/ftrace.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/ftrace.c +2 -0
index 275441254bb5..656d7cb5a78c 100644
@@ -2862,6 +2862,8 @@ int ftrace_startup(struct ftrace_ops *ops, int command)
 		__unregister_ftrace_function(ops);
 		ftrace_start_up--;
 		ops->flags &= ~FTRACE_OPS_FL_ENABLED;
+		if (ops->flags & FTRACE_OPS_FL_DYNAMIC)
+			ftrace_trampoline_free(ops);
 		return ret;
 	}
 
Signature · 1 line
2.28.0
#1 lore raw

I used Masami's address which did not work. Sorry about that. Should be ok now.

Quoted 39 lines · Miroslav Benes

Commit fc0ea795f53c ("ftrace: Add symbols for ftrace trampolines") missed to remove ops from new ftrace_ops_trampoline_list in ftrace_startup() if ftrace_hash_ipmodify_enable() fails there. It may lead to BUG if such ops come from a module which may be removed.

Moreover, the trampoline itself is not freed in this case.

Fix it by calling ftrace_trampoline_free() during the rollback.

Fixes fc0ea795f53c ("ftrace: Add symbols for ftrace trampolines")

---

It would be fair to add

Fixes f8b8be8a310a ("ftrace, kprobes: Support IPMODIFY flag to find IP modify conflict")

too. The situation was a bit more complicated back then though since RCU-tasks support was missing.

 kernel/trace/ftrace.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/ftrace.c +2 -0
index 275441254bb5..656d7cb5a78c 100644
@@ -2862,6 +2862,8 @@ int ftrace_startup(struct ftrace_ops *ops, int command)
 		__unregister_ftrace_function(ops);
 		ftrace_start_up--;
 		ops->flags &= ~FTRACE_OPS_FL_ENABLED;
+		if (ops->flags & FTRACE_OPS_FL_DYNAMIC)
+			ftrace_trampoline_free(ops);
 		return ret;
 	}
 
Signature · 1 line
2.28.0
maintainer
#2 lore raw
Quoted 2 lines · On Mon, 31 Aug 2020 14:56:57 +0200 (CEST) Miroslav Benes <[email protected]> wrote:

I used Masami's address which did not work. Sorry about that. Should be ok now.

Thanks Miroslav,

I've queued this up to be tested and pushed as urgent.

-- Steve

Quoted 16 lines · Miroslav Benes
Quoted 14 lines

Commit fc0ea795f53c ("ftrace: Add symbols for ftrace trampolines") missed to remove ops from new ftrace_ops_trampoline_list in ftrace_startup() if ftrace_hash_ipmodify_enable() fails there. It may lead to BUG if such ops come from a module which may be removed.

Moreover, the trampoline itself is not freed in this case.

Fix it by calling ftrace_trampoline_free() during the rollback.

Fixes fc0ea795f53c ("ftrace: Add symbols for ftrace trampolines")

---