Commit 8f160b5
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.
Also, move the code that resets ops->func and ops->trampoline to the error
path of register_ftrace_direct(); and add a helper function reset_direct()
in register_ftrace_direct() and unregister_ftrace_direct().
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]>
Reviewed-by: Jiri Olsa <[email protected]>1 parent 911ee01 commit 8f160b5
2 files changed
+14
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | 482 | | |
488 | 483 | | |
489 | 484 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5953 | 5953 | | |
5954 | 5954 | | |
5955 | 5955 | | |
| 5956 | + | |
| 5957 | + | |
| 5958 | + | |
| 5959 | + | |
| 5960 | + | |
| 5961 | + | |
| 5962 | + | |
| 5963 | + | |
| 5964 | + | |
| 5965 | + | |
| 5966 | + | |
5956 | 5967 | | |
5957 | 5968 | | |
5958 | 5969 | | |
| |||
6048 | 6059 | | |
6049 | 6060 | | |
6050 | 6061 | | |
| 6062 | + | |
| 6063 | + | |
6051 | 6064 | | |
6052 | 6065 | | |
6053 | 6066 | | |
| |||
6080 | 6093 | | |
6081 | 6094 | | |
6082 | 6095 | | |
6083 | | - | |
6084 | 6096 | | |
6085 | 6097 | | |
6086 | 6098 | | |
| |||
6090 | 6102 | | |
6091 | 6103 | | |
6092 | 6104 | | |
6093 | | - | |
| 6105 | + | |
6094 | 6106 | | |
6095 | 6107 | | |
6096 | | - | |
6097 | | - | |
6098 | | - | |
6099 | | - | |
6100 | 6108 | | |
6101 | 6109 | | |
6102 | 6110 | | |
| |||
0 commit comments