From c51829bb6e921337014d9ac3712b0b7e8cae9f3d Mon Sep 17 00:00:00 2001 From: Andrii Nakryiko Date: Wed, 29 May 2019 10:36:06 -0700 Subject: [PATCH] libbpf: check map name retrieved from ELF Validate there was no error retrieving symbol name corresponding to a BPF map. Acked-by: Song Liu Signed-off-by: Andrii Nakryiko Signed-off-by: Daniel Borkmann --- tools/lib/bpf/libbpf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index fb296eadc3f2..60ec9694923a 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -920,6 +920,11 @@ bpf_object__init_maps(struct bpf_object *obj, int flags) map_name = elf_strptr(obj->efile.elf, obj->efile.strtabidx, sym.st_name); + if (!map_name) { + pr_warning("failed to get map #%d name sym string for obj %s\n", + map_idx, obj->path); + return -LIBBPF_ERRNO__FORMAT; + } obj->maps[map_idx].libbpf_type = LIBBPF_MAP_UNSPEC; obj->maps[map_idx].offset = sym.st_value;