提交 a8fee962 编写于 作者: A Andrii Nakryiko 提交者: Alexei Starovoitov

libbpf: Avoid NULL deref when initializing map BTF info

If BPF object doesn't have an BTF info, don't attempt to search for BTF
types describing BPF map key or value layout.

Fixes: 262cfb74 ("libbpf: Init btf_{key,value}_type_id on internal map open")
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Acked-by: NYonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20220320001911.3640917-1-andrii@kernel.org
上级 9492450f
...@@ -4197,6 +4197,9 @@ static int bpf_map_find_btf_info(struct bpf_object *obj, struct bpf_map *map) ...@@ -4197,6 +4197,9 @@ static int bpf_map_find_btf_info(struct bpf_object *obj, struct bpf_map *map)
__u32 key_type_id = 0, value_type_id = 0; __u32 key_type_id = 0, value_type_id = 0;
int ret; int ret;
if (!obj->btf)
return -ENOENT;
/* if it's BTF-defined map, we don't need to search for type IDs. /* if it's BTF-defined map, we don't need to search for type IDs.
* For struct_ops map, it does not need btf_key_type_id and * For struct_ops map, it does not need btf_key_type_id and
* btf_value_type_id. * btf_value_type_id.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册