Conversation
16704ad to
837a3cc
Compare
|
hi @daym , thanks for this proposal. Unless the PR adds new interesting functionality or solves an issue, I'm usually reluctant to change things just because. Maybe the Makefile is not beautiful, but it works for compiling the modules on all the architectures Debian support. So the first question is in what architectures have you tested your changes. We need to support the existing array or archs. On the other hand, the Makefile seems to have a problem with the double backslash ~ $ make KERNEL_DIR=../linux-6.0/ KERNEL_HEADERS=../linux-6.0/ ARCH=x86
Makefile:22: *** recipe commences before first target. Stop.Once fixed, it fails to compile: ~ $ make V=1 KERNEL_DIR=../linux-6.0/ KERNEL_HEADERS=../linux-6.0/ ARCH=x86
make -C ../linux-6.0/ M=/opensnitch/ebpf_prog CC=clang
make[1]: Entering directory '/opensnitch/linux-6.0'
echo >&2; \
echo >&2 " ERROR: Kernel configuration is invalid."; \
echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
echo >&2 ; \
/bin/false)
warning: the compiler differs from the one used to build the kernel
The kernel was built by: gcc (Debian 10.2.1-6) 10.2.1 20210110
You are using: Debian clang version 11.0.1-2
WARNING: Symbol version dump "Module.symvers" is missing.
Modules may not have dependencies or modversions.
You may get many unresolved symbol warnings.
MODPOST /opensnitch/ebpf_prog/Module.symvers
make[1]: Leaving directory '/opensnitch/linux-6.0'This is a pbuilder chroot, i686 arch. Other compilation scenarios are lxc containers for example. |
|
Hi, the background is we are trying to package opensnitch for GNU Guix, see https://codeberg.org/guix/guix/pulls/2368 The reason why we even touched it is because it's including kernel headers using manual |
|
#712 |
|
I have updated this PR after learning a lot more about eBPF in the mean time :) BPF is an architecture, so one can just use a compiler targeting that architecture. BPF with CO-RE: BTF relocation resolves struct field offsets at load time, so compiled objects handle field offset changes without recompilation. That means the .o files will work with newer Linux kernels than the one we built for, as long as those new versions only change field offsets (which is likely). opensnitch uses some Linux kernel structs (obviously), so I have added the required struct definitions (with only the required fields) into I have removed generated files in favor of using libbpf. Advantages:
Disadvantages:
Flags removed:
|
Add minimal hand-written vmlinux.h containing only the kernel struct definitions OpenSnitch accesses (sock, task_struct, sockaddr_in, etc.). BTF relocation resolves struct field offsets at load time, so compiled objects handle field offset changes without recompilation. Replace vendored libbpf headers with system libbpf via pkg-config. System libbpf is maintained by the distribution. Map ARCH to _TARGET_ARCH* values. libbpf's bpf_tracing.h requires these for correct register access macros per architecture.
|
On x86_64 works fine. On aarch64/debian 11/kernels 5.10/6.1 fails compiling with a minor issue, and opensnitchd-procs.o fails loading, due to btf issues. Did you compile and test the modules on these archs? I'll test on more modern versions |
In the future we'll need to access nsproxy, cgroup and other structs and fields, so it'd be better to use the full vmlinux.h to compile the modules. Or document explicitely how to add the structs, but personally I'd prefer to avoid it. |
|
Some tests: x86_64 (Debian 14, clang version 21.1.8): Ok:
No ok:
aarch64 (clang 14.0.6, debian 13.3):
i686: will be not supported anymore I think. MX kernel 6.1.0 is not shipped with the item CONFIG_DEBUG_INFO_BTF configured. regardless of how we compile the procs module for aarch64, the cmdline is usually incorrect, so until we find a proper fix, it'll be better to read it from /proc. So basically, we lose support for older kernels, but in return we gain better compatibility with newer ones. |
It's probably easier to use the official eBPF CO-RE build system to build EBPF modules.
That's what this PR does.