Skip to content

Commit f767593

Browse files
committed
libbpf: Verify section type in btf_find_elf_sections
JIRA: https://issues.redhat.com/browse/RHEL-110274 commit 8582d9a Author: Ihor Solodrai <[email protected]> Date: Thu Apr 10 11:28:23 2025 -0700 libbpf: Verify section type in btf_find_elf_sections A valid ELF file may contain a SHT_NOBITS .BTF section. This case is not handled correctly in btf_parse_elf, which leads to a segfault. Before attempting to load BTF section data, check that the section type is SHT_PROGBITS, which is the expected type for BTF data. Fail with an error if the type is different. Bug report: libbpf/libbpf#894 v1: https://lore.kernel.org/bpf/[email protected]/ Signed-off-by: Ihor Solodrai <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Viktor Malik <[email protected]>
1 parent 35af19e commit f767593

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tools/lib/bpf/btf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,12 @@ static int btf_find_elf_sections(Elf *elf, const char *path, struct btf_elf_secs
11471147
else
11481148
continue;
11491149

1150+
if (sh.sh_type != SHT_PROGBITS) {
1151+
pr_warn("unexpected section type (%d) of section(%d, %s) from %s\n",
1152+
sh.sh_type, idx, name, path);
1153+
goto err;
1154+
}
1155+
11501156
data = elf_getdata(scn, 0);
11511157
if (!data) {
11521158
pr_warn("failed to get section(%d, %s) data from %s\n",

0 commit comments

Comments
 (0)