From 6c8e5e7d981b45619eccd22d895cec3c6afe3418 Mon Sep 17 00:00:00 2001 From: Luis Vieira Date: Wed, 16 Sep 2026 18:23:35 -0300 Subject: [PATCH] libbpf: Validate ELF symbol table entry size elf_sym_iter_new() calculates the number of symbols by dividing the symbol table data size by sh_entsize. A malformed ELF file with a zero sh_entsize causes a division by zero. Reject symbol table sections with a zero entry size before calculating the number of symbols. Signed-off-by: Luis Vieira Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20260916-libbpf-elf-entsize-fix-v1-1-cf181da33eab@gmail.com --- src/elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elf.c b/src/elf.c index fe136d0..700c391 100644 --- a/src/elf.c +++ b/src/elf.c @@ -115,7 +115,7 @@ static int elf_sym_iter_new(struct elf_sym_iter *iter, return -ENOENT; } - if (!gelf_getshdr(scn, &sh)) + if (!gelf_getshdr(scn, &sh) || !sh.sh_entsize) return -EINVAL; iter->strtabidx = sh.sh_link;