Skip to content

Commit 74b0ce4

Browse files
committed
libbpf: Fix null pointer dereference in btf_dump__free on allocation failure
JIRA: https://issues.redhat.com/browse/RHEL-110274 commit aa485e8 Author: Yuan Chen <chenyuan@kylinos.cn> Date: Wed Jun 18 09:19:33 2025 +0800 libbpf: Fix null pointer dereference in btf_dump__free on allocation failure When btf_dump__new() fails to allocate memory for the internal hashmap (btf_dump->type_names), it returns an error code. However, the cleanup function btf_dump__free() does not check if btf_dump->type_names is NULL before attempting to free it. This leads to a null pointer dereference when btf_dump__free() is called on a btf_dump object. Fixes: 351131b ("libbpf: add btf_dump API for BTF-to-C conversion") Signed-off-by: Yuan Chen <chenyuan@kylinos.cn> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20250618011933.11423-1-chenyuan_fl@163.com Signed-off-by: Viktor Malik <vmalik@redhat.com>
1 parent 56c1e53 commit 74b0ce4

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tools/lib/bpf/btf_dump.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ static void btf_dump_free_names(struct hashmap *map)
225225
size_t bkt;
226226
struct hashmap_entry *cur;
227227

228+
if (!map)
229+
return;
230+
228231
hashmap__for_each_entry(map, cur, bkt)
229232
free((void *)cur->pkey);
230233

0 commit comments

Comments
 (0)