summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Nakryiko <andrii@kernel.org>2025-02-19 16:28:21 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-04-10 14:37:30 +0200
commitb55c4702751149b7241bdacdcb83a14e7629336b (patch)
tree67ace6f3095029cbd8b9e12cd8aa273abe117120
parent5db897802c39dec7c2df6a8988bc64b029903dfe (diff)
downloadlinux-b55c4702751149b7241bdacdcb83a14e7629336b.tar.gz
linux-b55c4702751149b7241bdacdcb83a14e7629336b.tar.bz2
linux-b55c4702751149b7241bdacdcb83a14e7629336b.zip
libbpf: Fix hypothetical STT_SECTION extern NULL deref case
[ Upstream commit e0525cd72b5979d8089fe524a071ea93fd011dc9 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--tools/lib/bpf/linker.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c
index 736ebceea233..a3a190d13db8 100644
--- a/tools/lib/bpf/linker.c
+++ b/tools/lib/bpf/linker.c
@@ -1974,7 +1974,7 @@ add_sym:
obj->sym_map[src_sym_idx] = dst_sym_idx;
- if (sym_type == STT_SECTION && dst_sym) {
+ if (sym_type == STT_SECTION && dst_sec) {
dst_sec->sec_sym_idx = dst_sym_idx;
dst_sym->st_value = 0;
}