Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Fix hypothetical STT_SECTION extern NULL deref case

Fix theoretical NULL dereference in linker when resolving *extern*
STT_SECTION symbol against not-yet-existing ELF section. Not sure if
it's possible in practice for valid ELF object files (this would require
embedded assembly manipulations, at which point BTF will be missing),
but fix the s/dst_sym/dst_sec/ typo guarding this condition anyways.

Fixes: faf6ed321cf6 ("libbpf: Add BPF static linker APIs")
Fixes: a46349227cd8 ("libbpf: Add linker extern resolution support for functions and global variables")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20250220002821.834400-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
e0525cd7 b4a8b5bb

+1 -1
+1 -1
tools/lib/bpf/linker.c
··· 2163 2163 2164 2164 obj->sym_map[src_sym_idx] = dst_sym_idx; 2165 2165 2166 - if (sym_type == STT_SECTION && dst_sym) { 2166 + if (sym_type == STT_SECTION && dst_sec) { 2167 2167 dst_sec->sec_sym_idx = dst_sym_idx; 2168 2168 dst_sym->st_value = 0; 2169 2169 }