Skip to content

Commit 42be23e

Browse files
eddyz87anakryiko
authored andcommitted
libbpf: Verify that arena map exists when adding arena relocations
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 <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent beb1097 commit 42be23e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4582,6 +4582,11 @@ static int bpf_program__record_reloc(struct bpf_program *prog,
45824582

45834583
/* arena data relocation */
45844584
if (shdr_idx == obj->efile.arena_data_shndx) {
4585+
if (obj->arena_map_idx < 0) {
4586+
pr_warn("prog '%s': bad arena data relocation at insn %u, no arena maps defined\n",
4587+
prog->name, insn_idx);
4588+
return -LIBBPF_ERRNO__RELOC;
4589+
}
45854590
reloc_desc->type = RELO_DATA;
45864591
reloc_desc->insn_idx = insn_idx;
45874592
reloc_desc->map_idx = obj->arena_map_idx;

0 commit comments

Comments
 (0)