Skip to contentSkip to conversation

libbpf: fix hypothetical STT_SECTION extern NULL deref case

PATCH Applied Andrii Nakryiko 2 participants 2 messages Feb 20, 2025 – Feb 21, 2025

Subsystems (2)
lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 1/1 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")
---
 tools/lib/bpf/linker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/linker.c +1 -1
index b52f71c59616..800e0ef09c37 100644
@@ -2163,7 +2163,7 @@ static int linker_append_elf_sym(struct bpf_linker *linker, struct src_obj *obj,
 
 	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;
 	}
Signature · 1 line
2.43.5
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 11 lines · On Wed, 19 Feb 2025 16:28:21 -0800 you wrote:

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")

[...]

Here is the summary with links:
- [bpf-next] libbpf: fix hypothetical STT_SECTION extern NULL deref case

    https://git.kernel.org/bpf/bpf-next/c/e0525cd72b59

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html