|
28 | 28 | #include <linux/cpumask.h> |
29 | 29 | #include <linux/bpf_mem_alloc.h> |
30 | 30 | #include <net/xdp.h> |
| 31 | +#include <linux/trace_events.h> |
| 32 | +#include <linux/kallsyms.h> |
31 | 33 |
|
32 | 34 | #include "disasm.h" |
33 | 35 |
|
@@ -21154,11 +21156,13 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, |
21154 | 21156 | { |
21155 | 21157 | bool prog_extension = prog->type == BPF_PROG_TYPE_EXT; |
21156 | 21158 | bool prog_tracing = prog->type == BPF_PROG_TYPE_TRACING; |
| 21159 | + char trace_symbol[KSYM_SYMBOL_LEN]; |
21157 | 21160 | const char prefix[] = "btf_trace_"; |
| 21161 | + struct bpf_raw_event_map *btp; |
21158 | 21162 | int ret = 0, subprog = -1, i; |
21159 | 21163 | const struct btf_type *t; |
21160 | 21164 | bool conservative = true; |
21161 | | - const char *tname; |
| 21165 | + const char *tname, *fname; |
21162 | 21166 | struct btf *btf; |
21163 | 21167 | long addr = 0; |
21164 | 21168 | struct module *mod = NULL; |
@@ -21289,10 +21293,34 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, |
21289 | 21293 | return -EINVAL; |
21290 | 21294 | } |
21291 | 21295 | tname += sizeof(prefix) - 1; |
21292 | | - t = btf_type_by_id(btf, t->type); |
21293 | | - if (!btf_type_is_ptr(t)) |
21294 | | - /* should never happen in valid vmlinux build */ |
| 21296 | + |
| 21297 | + /* The func_proto of "btf_trace_##tname" is generated from typedef without argument |
| 21298 | + * names. Thus using bpf_raw_event_map to get argument names. |
| 21299 | + */ |
| 21300 | + btp = bpf_get_raw_tracepoint(tname); |
| 21301 | + if (!btp) |
21295 | 21302 | return -EINVAL; |
| 21303 | + fname = kallsyms_lookup((unsigned long)btp->bpf_func, NULL, NULL, NULL, |
| 21304 | + trace_symbol); |
| 21305 | + bpf_put_raw_tracepoint(btp); |
| 21306 | + |
| 21307 | + if (fname) |
| 21308 | + ret = btf_find_by_name_kind(btf, fname, BTF_KIND_FUNC); |
| 21309 | + |
| 21310 | + if (!fname || ret < 0) { |
| 21311 | + bpf_log(log, "Cannot find btf of tracepoint template, fall back to %s%s.\n", |
| 21312 | + prefix, tname); |
| 21313 | + t = btf_type_by_id(btf, t->type); |
| 21314 | + if (!btf_type_is_ptr(t)) |
| 21315 | + /* should never happen in valid vmlinux build */ |
| 21316 | + return -EINVAL; |
| 21317 | + } else { |
| 21318 | + t = btf_type_by_id(btf, ret); |
| 21319 | + if (!btf_type_is_func(t)) |
| 21320 | + /* should never happen in valid vmlinux build */ |
| 21321 | + return -EINVAL; |
| 21322 | + } |
| 21323 | + |
21296 | 21324 | t = btf_type_by_id(btf, t->type); |
21297 | 21325 | if (!btf_type_is_func_proto(t)) |
21298 | 21326 | /* should never happen in valid vmlinux build */ |
|
0 commit comments