]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
libbpf: Fix null pointer dereference in btf_dump__free on allocation failure
authorYuan Chen <chenyuan@kylinos.cn>
Wed, 18 Jun 2025 01:19:33 +0000 (09:19 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 6 Jul 2025 08:58:00 +0000 (10:58 +0200)
commite32a996582648bd0190d9edecd85f5249f9f8fa6
tree64d3442f06f3a2b4e4efb9011bae1c5fcbba4c61
parentd3615894f7073d65e3816826192a83ada29d7779
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>
tools/lib/bpf/btf_dump.c