ftrace reads the code it patches with copy_from_kernel_nofault(). A program which makes it fail breaks the detach of fentry on x86: unregister_fentry() update_ftrace_direct_del() returns 0 ftrace_replace_code() ftrace_bug(), no text poke ftrace_verify_code() -EFAULT bpf_tramp_image_put() the function still calls the freed image On arm64 ftrace reads and writes the code with aarch64_insn_read() and aarch64_insn_patch_text_nosync(), which calls aarch64_insn_write(). They are traceable without KPROBES. The same holds for them. Two more functions break BPF after a skip: target error after the skip ----------------------------- ------- --------------------------------- copy_to_kernel_nofault() -EFAULT arm64, with KPROBES too: __aarch64_insn_write() fails. ftrace_bug(), no text poke. text_poke_memcpy() ignores it. bpf_arch_text_copy() returns dst. The new prog is all BRK insns tracepoint_probe_unregister() -ENOENT bpf_raw_tp_link_release() ignores it. __bpf_trace_run() reads the freed link Do not tag these six. Signed-off-by: Anton Protopopov --- tools/bpf/resolve_btfids/fmodret.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c index 7d26a5c9b028..b425208702b4 100644 --- a/tools/bpf/resolve_btfids/fmodret.c +++ b/tools/bpf/resolve_btfids/fmodret.c @@ -87,6 +87,24 @@ static bool has_bpf_types(const struct btf *btf, const struct btf_type *func) return false; } +static bool excluded_by_name(const char *name) +{ + static const char *const names[] = { + "copy_from_kernel_nofault", + "copy_to_kernel_nofault", + "aarch64_insn_read", + "aarch64_insn_write", + "aarch64_insn_patch_text_nosync", + "tracepoint_probe_unregister", + }; + unsigned int i; + + for (i = 0; i < sizeof(names) / sizeof(names[0]); i++) + if (!strcmp(name, names[i])) + return true; + return false; +} + /* Find kfuncs and helpers */ static bool *find_bpf_funcs(const struct btf *btf) { @@ -290,6 +308,8 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose) func = image_func(&img, name); if (!func || !strcmp(func->section, ".init.text")) continue; + if (excluded_by_name(name)) + continue; nr_scanned++; err = scan_func(scan, func, &values); if (err == -EINVAL) { -- 2.43.0