All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] libbpf: Fix segfault in light skeleton for objects without BTF
@ 2021-09-30  6:16 Kumar Kartikeya Dwivedi
  2021-09-30 22:54 ` Daniel Borkmann
  0 siblings, 1 reply; 2+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2021-09-30  6:16 UTC (permalink / raw)
  To: bpf

When fed an empty BPF object, bpftool gen skeleton -L crashes at
btf__set_fd since it assumes presence of obj->btf, however for the
sequence below clang adds no .BTF section (hence no BTF).

Reproducer:
$ touch a.bpf.c
$ clang -O2 -g -target bpf -c a.bpf.c
$ bpftool gen skeleton -L a.bpf.o
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
/* THIS FILE IS AUTOGENERATED! */

struct a_bpf {
	struct bpf_loader_ctx ctx;
Segmentation fault (core dumped)

The same occurs for files compiled without BTF info, i.e. without
clang's -g flag.

Fixes: 67234743736a (libbpf: Generate loader program out of BPF ELF file.)
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
 tools/lib/bpf/libbpf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 0f85d441fca3..b6b130171b86 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7031,7 +7031,8 @@ int bpf_object__load_xattr(struct bpf_object_load_attr *attr)

 	if (obj->gen_loader) {
 		/* reset FDs */
-		btf__set_fd(obj->btf, -1);
+		if (obj->btf)
+			btf__set_fd(obj->btf, -1);
 		for (i = 0; i < obj->nr_maps; i++)
 			obj->maps[i].fd = -1;
 		if (!err)
--
2.33.0


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

* Re: [PATCH bpf] libbpf: Fix segfault in light skeleton for objects without BTF
  2021-09-30  6:16 [PATCH bpf] libbpf: Fix segfault in light skeleton for objects without BTF Kumar Kartikeya Dwivedi
@ 2021-09-30 22:54 ` Daniel Borkmann
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2021-09-30 22:54 UTC (permalink / raw)
  To: Kumar Kartikeya Dwivedi, bpf

On 9/30/21 8:16 AM, Kumar Kartikeya Dwivedi wrote:
> When fed an empty BPF object, bpftool gen skeleton -L crashes at
> btf__set_fd since it assumes presence of obj->btf, however for the
> sequence below clang adds no .BTF section (hence no BTF).
> 
> Reproducer:
> $ touch a.bpf.c
> $ clang -O2 -g -target bpf -c a.bpf.c
> $ bpftool gen skeleton -L a.bpf.o
> /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
> /* THIS FILE IS AUTOGENERATED! */
> 
> struct a_bpf {
> 	struct bpf_loader_ctx ctx;
> Segmentation fault (core dumped)
> 
> The same occurs for files compiled without BTF info, i.e. without
> clang's -g flag.
> 
> Fixes: 67234743736a (libbpf: Generate loader program out of BPF ELF file.)
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>

Looks like patchwork-bot is on vacation right now, this was applied thanks!

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

end of thread, other threads:[~2021-09-30 22:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-30  6:16 [PATCH bpf] libbpf: Fix segfault in light skeleton for objects without BTF Kumar Kartikeya Dwivedi
2021-09-30 22:54 ` Daniel Borkmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.