lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Sat,  8 Jan 2022 13:47:39 +0000
From:   Yafang Shao <>
        Yafang Shao <>
Subject: [PATCH] libbpf: fix possible NULL pointer dereference when destroy skelton

When I checked the code in skelton header file generated with my own bpf
prog, I found there may be possible NULL pointer derefence when destroy
skelton. Then I checked the in-tree bpf progs, finding that is a common
issue. Let's take the generated samples/bpf/xdp_redirect_cpu.skel.h for
example. Below is the generated code in
		struct bpf_object_skeleton *s;
		s = (struct bpf_object_skeleton *)calloc(1, sizeof(*s));
		if (!s)
			goto error;
		return  -ENOMEM;

After goto error, the NULL 's' will be deferenced in

We can simply fix this issue by just adding a NULL check in

Fixes: d66562fba ("libbpf: Add BPF object skeleton support")
Signed-off-by: Yafang Shao <>
Cc: Andrii Nakryiko <>
 tools/lib/bpf/libbpf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 7c74342bb668..a07fbd59e4b8 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -11464,6 +11464,9 @@ void bpf_object__detach_skeleton(struct bpf_object_skeleton *s)
 void bpf_object__destroy_skeleton(struct bpf_object_skeleton *s)
+	if (!s)
+		return;
 	if (s->progs)
 	if (s->obj)

Powered by blists - more mailing lists