]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
libbpf: Verify that arena map exists when adding arena relocations
authorEduard Zingerman <eddyz87@gmail.com>
Fri, 18 Jul 2025 22:20:59 +0000 (15:20 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Sat, 19 Jul 2025 00:12:50 +0000 (17:12 -0700)
Fuzzer reported a memory access error in bpf_program__record_reloc()
that happens when:
- ".addr_space.1" section exists
- there is a relocation referencing this section
- there are no arena maps defined in BTF.

Sanity checks for maps existence are already present in
bpf_program__record_reloc(), hence this commit adds another one.

[1] https://github.com/libbpf/libbpf/actions/runs/16375110681/job/46272998064

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250718222059.281526-1-eddyz87@gmail.com
tools/lib/bpf/libbpf.c

index 162ebd16a59f696d9a7a4eb6615c413651613a64..e067cb5776bda1b86162855a32cbc2d8f317b6d8 100644 (file)
@@ -4582,6 +4582,11 @@ static int bpf_program__record_reloc(struct bpf_program *prog,
 
        /* arena data relocation */
        if (shdr_idx == obj->efile.arena_data_shndx) {
+               if (obj->arena_map_idx < 0) {
+                       pr_warn("prog '%s': bad arena data relocation at insn %u, no arena maps defined\n",
+                               prog->name, insn_idx);
+                       return -LIBBPF_ERRNO__RELOC;
+               }
                reloc_desc->type = RELO_DATA;
                reloc_desc->insn_idx = insn_idx;
                reloc_desc->map_idx = obj->arena_map_idx;