Skip to content

Commit c54504b

Browse files
committed
libbpf: Verify section type in btf_find_elf_sections
JIRA: https://issues.redhat.com/browse/RHEL-78203 commit 8582d9a Author: Ihor Solodrai <ihor.solodrai@linux.dev> 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/20250408184104.3962949-1-ihor.solodrai@linux.dev/ Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20250410182823.1591681-1-ihor.solodrai@linux.dev Signed-off-by: Viktor Malik <vmalik@redhat.com>
1 parent 9dceb30 commit c54504b

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
@@ -1148,6 +1148,12 @@ static int btf_find_elf_sections(Elf *elf, const char *path, struct btf_elf_secs
11481148
else
11491149
continue;
11501150

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

0 commit comments

Comments
 (0)