mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] libbpf: Fix null pointer dereference in btf_dump__free on allocation failure
@ 2025-06-18  1:19 chenyuan
  2025-06-23 18:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: chenyuan @ 2025-06-18  1:19 UTC (permalink / raw)
  To: ast; +Cc: andrii.nakryiko, bpf, linux-kernel, chenyuan_fl, chenyuan

From: chenyuan <chenyuan@kylinos.cn>

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.

Fix: 351131b51c7a ("libbpf: add btf_dump API for BTF-to-C conversion")
Signed-off-by: chenyuan <chenyuan@kylinos.cn>
---
 tools/lib/bpf/btf_dump.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 7c2f1f13f958..f09f25eccf3c 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -227,6 +227,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->pkey);
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-23 18:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-18  1:19 [PATCH v2] libbpf: Fix null pointer dereference in btf_dump__free on allocation failure chenyuan
2025-06-23 18:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®