Skip to content

Commit 35b9211

Browse files
anakryikoborkmann
authored andcommitted
libbpf: Fix realloc usage in bpf_core_find_cands
Fix bug requesting invalid size of reallocated array when constructing CO-RE relocation candidate list. This can cause problems if there are many potential candidates and a very fine-grained memory allocator bucket sizes are used. Fixes: ddc7c30 ("libbpf: implement BPF CO-RE offset relocation algorithm") Reported-by: William Smith <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent d7a2527 commit 35b9211

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3869,7 +3869,9 @@ static struct ids_vec *bpf_core_find_cands(const struct btf *local_btf,
38693869
if (strncmp(local_name, targ_name, local_essent_len) == 0) {
38703870
pr_debug("[%d] %s: found candidate [%d] %s\n",
38713871
local_type_id, local_name, i, targ_name);
3872-
new_ids = realloc(cand_ids->data, cand_ids->len + 1);
3872+
new_ids = reallocarray(cand_ids->data,
3873+
cand_ids->len + 1,
3874+
sizeof(*cand_ids->data));
38733875
if (!new_ids) {
38743876
err = -ENOMEM;
38753877
goto err_out;

0 commit comments

Comments
 (0)