mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: Validate ELF symbol table entry size
@ 2026-09-16 21:23 Luis Vieira
  2026-09-16 22:00 ` bot+bpf-ci
  0 siblings, 1 reply; 2+ messages in thread
From: Luis Vieira @ 2026-09-16 21:23 UTC (permalink / raw)
  To: Andrii Nakryiko, Eduard Zingerman, Ihor Solodrai,
	Alexei Starovoitov, Daniel Borkmann, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis
  Cc: bpf, linux-kernel, Luis Vieira

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 <luisflavieira@gmail.com>
---
 tools/lib/bpf/elf.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/lib/bpf/elf.c b/tools/lib/bpf/elf.c
index fe136d025967..ba0b3df37a59 100644
--- a/tools/lib/bpf/elf.c
+++ b/tools/lib/bpf/elf.c
@@ -118,6 +118,11 @@ static int elf_sym_iter_new(struct elf_sym_iter *iter,
 	if (!gelf_getshdr(scn, &sh))
 		return -EINVAL;
 
+	if (!sh.sh_entsize) {
+		pr_warn("elf: symbol table section has zero entry size in '%s'\n", binary_path);
+		return -EINVAL;
+	}
+
 	iter->strtabidx = sh.sh_link;
 	iter->syms = elf_getdata(scn, 0);
 	if (!iter->syms) {

---
base-commit: 10c4f610b215bf961235141161992f010cf7e451
change-id: 20260916-libbpf-elf-entsize-fix-a0f9440e79c7

Best regards,
--  
Luis Vieira <luisflavieira@gmail.com>


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] libbpf: Validate ELF symbol table entry size
  2026-09-16 21:23 [PATCH bpf-next] libbpf: Validate ELF symbol table entry size Luis Vieira
@ 2026-09-16 22:00 ` bot+bpf-ci
  0 siblings, 0 replies; 2+ messages in thread
From: bot+bpf-ci @ 2026-09-16 22:00 UTC (permalink / raw)
  To: luisflavieira, andrii, eddyz87, ihor.solodrai, ast, daniel,
	memxor, martin.lau, song, yonghong.song, jolsa, emil
  Cc: bpf, linux-kernel, luisflavieira, ast, andrii, daniel,
	martin.lau, eddyz87, yonghong.song, mason, ihor.solodrai

[-- Attachment #1: Type: text/plain, Size: 794 bytes --]

>     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 <luisflavieira@gmail.com>

This looks like a bug fix for the elf symbol iterator. Should this include:

  Fixes: 3774705db171 ("libbpf: Add elf symbol iterator")


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/35154126900

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-16 22:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16 21:23 [PATCH bpf-next] libbpf: Validate ELF symbol table entry size Luis Vieira
2026-09-16 22:00 ` bot+bpf-ci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®