libbpf / bpftool

Automated upstream mirror for bpftool stand-alone build.
Other
377 stars 69 forks source link

bpftool 7.4.0 prog load Segmentation fault (core dumped) #145

Closed sta-c0000 closed 3 months ago

sta-c0000 commented 3 months ago

Hello, Starting with bpftool:amd64 7.4.0+6.8.9-1 on Debian unstable (now 7.4.0+6.8.11-1) bpftool began crashing with a segmentation fault and core-dump when attempting to load a simple bpf program.

Now it works if I re-compile the bpf object file with -g (debug info). However the old bpf object file had been working for a few years on multiple linux versions /arches. Must all bpf programs be compiled with -g now? It makes the file much larger. Perhaps prog load should still not core-dump and return a message instead?

If curious, here is the bpf object file: so_mark_giduid.bpf.o

bpftool prog load so_mark_giduid.bpf.o /sys/fs/bpf/testing type cgroup/sock
Segmentation fault (core dumped)

Thank you.

Edit: add minimal reproduction, minimal.bpf.c:

#include "vmlinux.h"
#include <bpf/bpf_helpers.h>

SEC("cgroup/sock")
int so_mark(struct bpf_sock *sk) {
  sk->mark = 1;
  return 1;
}

char __license[] SEC("license") = "GPL";
clang --target=bpf -O -c minimal.bpf.c -o minimal.bpf.o
bpftool prog load minimal.bpf.o /sys/fs/bpf/minimal type cgroup/sock
Segmentation fault (core dumped)

Edit 2: possibly related to: [PATCH bpf-next v2] libbpf: Prevent null-pointer dereference when prog to load has no BTF ...not in any stable kernels yet (neither 6.8.11 nor 6.9.2 at time of writing)

qmonnet commented 3 months ago

Hi, and thanks for the report! Yes, this sounds very much like the bug we fixed upstream with the patch you found. Have you tried to reproduce with the latest bpftool version? You can compile from the kernel repo or from this GitHub repo. I think that even the 7.4 release binaries from this repo should contain the fix.

not in any stable kernels yet

It was queued today for both 6.8 and 6.9 branches, I got Greg's emails less than 2 hours ago. But ideally distributions should package from this GitHub repo instead, this would avoid this sort of issues.

sta-c0000 commented 3 months ago

My apologies, I should have spent more time searching (to find that patch that is now coming down the pipes) and testing: yes, the release binary here works! Thank you for your time.