|
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 |
|
@@ -21785,11 +21787,13 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
|
21785 | 21787 | {
|
21786 | 21788 | bool prog_extension = prog->type == BPF_PROG_TYPE_EXT;
|
21787 | 21789 | bool prog_tracing = prog->type == BPF_PROG_TYPE_TRACING;
|
| 21790 | + char trace_symbol[KSYM_SYMBOL_LEN]; |
21788 | 21791 | const char prefix[] = "btf_trace_";
|
| 21792 | + struct bpf_raw_event_map *btp; |
21789 | 21793 | int ret = 0, subprog = -1, i;
|
21790 | 21794 | const struct btf_type *t;
|
21791 | 21795 | bool conservative = true;
|
21792 |
| - const char *tname; |
| 21796 | + const char *tname, *fname; |
21793 | 21797 | struct btf *btf;
|
21794 | 21798 | long addr = 0;
|
21795 | 21799 | struct module *mod = NULL;
|
@@ -21920,10 +21924,34 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
|
21920 | 21924 | return -EINVAL;
|
21921 | 21925 | }
|
21922 | 21926 | tname += sizeof(prefix) - 1;
|
21923 |
| - t = btf_type_by_id(btf, t->type); |
21924 |
| - if (!btf_type_is_ptr(t)) |
21925 |
| - /* should never happen in valid vmlinux build */ |
| 21927 | + |
| 21928 | + /* The func_proto of "btf_trace_##tname" is generated from typedef without argument |
| 21929 | + * names. Thus using bpf_raw_event_map to get argument names. |
| 21930 | + */ |
| 21931 | + btp = bpf_get_raw_tracepoint(tname); |
| 21932 | + if (!btp) |
21926 | 21933 | return -EINVAL;
|
| 21934 | + fname = kallsyms_lookup((unsigned long)btp->bpf_func, NULL, NULL, NULL, |
| 21935 | + trace_symbol); |
| 21936 | + bpf_put_raw_tracepoint(btp); |
| 21937 | + |
| 21938 | + if (fname) |
| 21939 | + ret = btf_find_by_name_kind(btf, fname, BTF_KIND_FUNC); |
| 21940 | + |
| 21941 | + if (!fname || ret < 0) { |
| 21942 | + bpf_log(log, "Cannot find btf of tracepoint template, fall back to %s%s.\n", |
| 21943 | + prefix, tname); |
| 21944 | + t = btf_type_by_id(btf, t->type); |
| 21945 | + if (!btf_type_is_ptr(t)) |
| 21946 | + /* should never happen in valid vmlinux build */ |
| 21947 | + return -EINVAL; |
| 21948 | + } else { |
| 21949 | + t = btf_type_by_id(btf, ret); |
| 21950 | + if (!btf_type_is_func(t)) |
| 21951 | + /* should never happen in valid vmlinux build */ |
| 21952 | + return -EINVAL; |
| 21953 | + } |
| 21954 | + |
21927 | 21955 | t = btf_type_by_id(btf, t->type);
|
21928 | 21956 | if (!btf_type_is_func_proto(t))
|
21929 | 21957 | /* should never happen in valid vmlinux build */
|
|
0 commit comments