diff options
author | Andrii Nakryiko <andrii@kernel.org> | 2021-11-03 10:32:09 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2021-11-03 13:25:37 -0700 |
commit | 833907876be55205d0ec153dcd819c014404ee16 (patch) | |
tree | 49685afb5fb776e712a385d376c428ef30c910a7 /tools/lib/bpf/libbpf.c | |
parent | 8388092b2551f7ae34dad800ce828779f7c948c9 (diff) | |
download | lwn-833907876be55205d0ec153dcd819c014404ee16.tar.gz lwn-833907876be55205d0ec153dcd819c014404ee16.zip |
libbpf: Detect corrupted ELF symbols section
Prevent divide-by-zero if ELF is corrupted and has zero sh_entsize.
Reported by oss-fuzz project.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20211103173213.1376990-2-andrii@kernel.org
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index a1bea1953df6..71f5a009010a 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -3555,7 +3555,7 @@ static int bpf_object__collect_externs(struct bpf_object *obj) scn = elf_sec_by_idx(obj, obj->efile.symbols_shndx); sh = elf_sec_hdr(obj, scn); - if (!sh) + if (!sh || sh->sh_entsize != sizeof(Elf64_Sym)) return -LIBBPF_ERRNO__FORMAT; dummy_var_btf_id = add_dummy_ksym_var(obj->btf); |