Skip to content

Commit 3355695

Browse files
committed
ftrace: Fix BPF fexit with livepatch
When livepatch is attached to the same function as bpf trampoline with a fexit program, bpf trampoline code calls register_ftrace_direct() twice. The first time will fail with -EAGAIN, and the second time it will succeed. This requires register_ftrace_direct() to unregister the address on the first attempt. Otherwise, the bpf trampoline cannot attach. Here is an easy way to reproduce this issue: insmod samples/livepatch/livepatch-sample.ko bpftrace -e 'fexit:cmdline_proc_show {}' ERROR: Unable to attach probe: fexit:vmlinux:cmdline_proc_show... Fix this by cleaning up the hash when register_ftrace_function_nolock hits errors. Fixes: d05cb47 ("ftrace: Fix modification of direct_function hash while in use") Cc: [email protected] # v6.6+ Reported-by: Andrey Grodzovsky <[email protected]> Closes: https://lore.kernel.org/live-patching/[email protected]/ Cc: Steven Rostedt (Google) <[email protected]> Cc: Masami Hiramatsu (Google) <[email protected]> Acked-and-tested-by: Andrey Grodzovsky <[email protected]> Signed-off-by: Song Liu <[email protected]>
1 parent d4664e4 commit 3355695

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kernel/trace/ftrace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6048,6 +6048,8 @@ int register_ftrace_direct(struct ftrace_ops *ops, unsigned long addr)
60486048
ops->direct_call = addr;
60496049

60506050
err = register_ftrace_function_nolock(ops);
6051+
if (err)
6052+
remove_direct_functions_hash(hash, addr);
60516053

60526054
out_unlock:
60536055
mutex_unlock(&direct_mutex);

0 commit comments

Comments
 (0)