Skip to content

Commit

Permalink
libbpf: don't crash on object files with no symbol tables
Browse files Browse the repository at this point in the history
If libbpf encounters an ELF file that has been stripped of its symbol
table, it will crash in bpf_object__add_programs() when trying to
dereference the obj->efile.symbols pointer. Add a check and return to avoid
this.

Fixes: 6245947 ("libbpf: Allow gaps in BPF program sections to support overriden weak functions")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
  • Loading branch information
tohojo authored and tsipa committed Aug 31, 2021
1 parent 528bd28 commit 5888c4e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/lib/bpf/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,9 @@ bpf_object__add_programs(struct bpf_object *obj, Elf_Data *sec_data,
const char *name;
GElf_Sym sym;

if (!symbols)
return -ENOENT;

progs = obj->programs;
nr_progs = obj->nr_programs;
nr_syms = symbols->d_size / sizeof(GElf_Sym);
Expand Down

0 comments on commit 5888c4e

Please sign in to comment.