diff options
author | Ian Rogers <[email protected]> | 2021-05-04 16:49:10 -0700 |
---|---|---|
committer | Andrii Nakryiko <[email protected]> | 2021-05-05 11:29:33 -0700 |
commit | 9683e5775c75097c46bd24e65411b16ac6c6cbb3 (patch) | |
tree | e217f762417abfa1afc7ff057d3245763dd752d7 | |
parent | 1682d8df20aa505f6ab12c76e934b26ede39c529 (diff) |
libbpf: Add NULL check to add_dummy_ksym_var
Avoids a segv if btf isn't present. Seen on the call path
__bpf_object__open calling bpf_object__collect_externs.
Fixes: 5bd022ec01f0 (libbpf: Support extern kernel function)
Suggested-by: Stanislav Fomichev <[email protected]>
Suggested-by: Petar Penkov <[email protected]>
Signed-off-by: Ian Rogers <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
-rw-r--r-- | tools/lib/bpf/libbpf.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index e2a3cf437814..c41d9b2b59ac 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -3216,6 +3216,9 @@ static int add_dummy_ksym_var(struct btf *btf) const struct btf_var_secinfo *vs; const struct btf_type *sec; + if (!btf) + return 0; + sec_btf_id = btf__find_by_name_kind(btf, KSYMS_SEC, BTF_KIND_DATASEC); if (sec_btf_id < 0) |