summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorYuan Chen <chenyuan@kylinos.cn>2025-06-18 09:19:33 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-07-17 18:27:41 +0200
commitd6c6216a7e85107534e8d6b667409c99833b3b7e (patch)
treee49dd4a84ef79b95229cc2d0a5766779132d372a /tools
parent451b9495fed263301378cb26f084ff83a6bab153 (diff)
downloadlinux-d6c6216a7e85107534e8d6b667409c99833b3b7e.tar.gz
linux-d6c6216a7e85107534e8d6b667409c99833b3b7e.tar.bz2
linux-d6c6216a7e85107534e8d6b667409c99833b3b7e.zip
libbpf: Fix null pointer dereference in btf_dump__free on allocation failure
[ Upstream commit aa485e8789d56a4573f7c8d000a182b749eaa64d ] 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: 351131b51c7a ("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: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/lib/bpf/btf_dump.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 2342aec3c5a3..d6818e22503c 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -193,6 +193,9 @@ static void btf_dump_free_names(struct hashmap *map)
size_t bkt;
struct hashmap_entry *cur;
+ if (!map)
+ return;
+
hashmap__for_each_entry(map, cur, bkt)
free((void *)cur->key);