eBPF Verification Is Untenable
The whole BPF verifier and development process is so botched, it&#x27;s ridiculous. It&#x27;s like maintainers decided to make this as hard as possible out of pettiness and &quot;they have to use C APIs instead&quot; or something.<p>- Loading an eBPF module without the CAP_BPF (and in some cases without the CAP_NET_ADMIN which you need for XDP) capabilities will generate a &quot;unknown&#x2F;invalid memory access&quot; error which is super useless as an error message.<p>- In my personal opinion a bytecode format for both little endian (bpfel) and big endian (bpfeb) machines is kinda unnecessary. I mean, it&#x27;s a virtual bytecode format for a reason, right!?<p>- Compiling eBPF via clang to the bpf bytecode format without debug symbols will make every following error message down the line utterly useless. Took me a while to figure out what &quot;unknown scalar&quot; really means. If you forget that &quot;-g&quot; flag you&#x27;re totally fucked.<p>- Anything pointer related that eBPF verifier itself doesn&#x27;t support will lead to &quot;unknown scalar&quot; errors which are actually out of bounds errors most of the time (e.g. have to use if pointer &lt; size(packet) around it), which only happen in the verification process and can only be shown using the bpftool. If you miss them, good luck getting a better error message out of the kernel while loading the module.<p>- The bpftool maintainer is kind of unfriendly, he&#x27;s telling you to read a book about the bytecode format if your code doesn&#x27;t compile and you&#x27;re asking about examples on how to use pointers inside a BPF codebase because it seems to enforce specific rules in terms of what kind of method (__always_static) are allowed to modify or allocate memory. There&#x27;s a lot of limitations that are documented _nowhere_ on the internet, and seemingly all developers are supposed to know them by reading the bpftool codebase itself!? Who&#x27;s the audience for using the bpftool then? Developers of the bpftool itself?<p>- The BCC tools (bpf compiler collection) are still using examples that can&#x27;t compile on an up-to-date kernel. [1] If you don&#x27;t have the old headers, you&#x27;ll find a lot of issues that show you the specific git hash where the &quot;bpf-helpers.h&quot; file was still inside the kernel codebase.<p>- The libbpf repo contain also examples that won&#x27;t compile. Especially the xdp related ones [2]<p>- There&#x27;s also an ongoing migration of all projects (?) to xdp-tools, which seems to be redundant in terms of bpf related topics, but also has only a couple examples that somehow work [3]<p>- Literally the only userspace eBPF generation framework that worked outside a super outdated enterprise linux environment is the cilium ebpf project [4], but only because they&#x27;re using the old &quot;bpf-helpers.h&quot; file that are meanwhile removed from the kernel itself. [5] They&#x27;re also incomplete for things like the new &quot;__u128&quot; and &quot;__bpf_helper_methods&quot; syntax which are sometimes missing.<p>- The only working examples that can also be used for reference on &quot;what&#x27;s available&quot; in terms of eBPF and kernel userspace APIs is a forked repo of the bootlin project [6] which literally taught me how to use eBPF in practice.<p>- All other (official?) examples show you how to make a bpf_printk call, but _none_ of them show you how to even interact with bpf maps (whose syntax changed like 5 times over the course of the last years, and 4 of them don&#x27;t run through the verifier, obviously). They&#x27;re also somewhat documented in the wiki of the libbpf project, without further explanation on why or what [7]. Without that bootlin repo I still would have no idea other than how to make a print inside a &quot;kretprobe&quot;. Anything more advanced is totally undocumented.<p>- OpenSnitch even has a workflow that copies their own codebase inside the kernel codebase, just to make it compile - because all other ways are too redundant or too broken. Not kidding you. [8]<p>Note that none of any BPF related projects uses any kind of reliable version scheme, and none of those project uses anything &quot;modern&quot; like conan (or whatever) as a package manager. Because that would have been too easy to use, and too easy on documenting on what breaks when. &#x2F;s<p>Overall I have to say, BPF was the worst development experience I ever had. Writing a kernel module is _easier_ than writing a BPF module, because then you have at least reliable tooling. In the BPF world, anything will and can break at any unpredictable moment. If you compare that to the experience of other development environments like say, JVM or even the JS world, where debuggers that interact with JIT compilers are the norm, well ... then you&#x27;ve successfully been transferred back to the PTSD moments of the 90s.<p>Honestly I don&#x27;t know how people can use BPF and say &quot;yeah this has been a great experience and I love it&quot; and not realize how broken the tooling is on every damn level.<p>I totally recommend reading the book [9] and watching the YouTube videos of Liz Rice [10]. They&#x27;re awesome, and they show you how to tackle some of the problems I mentioned. I think that without her work, BPF would have had zero chance of success.<p>What&#x27;s missing in the BPF world is definitely better tooling, better error messages (e.g. &quot;did you forget to do this?&quot; or even &quot;unexpected statement&quot; would be sooooo much better than the current state), and an easier way to debug an eBPF program. Documentation on what&#x27;s available and what is not is also necessary, because it&#x27;s impossible to find out right now. If I am not allowed to use pointers or whatever, then say so in the beginning.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;iovisor&#x2F;bcc">https:&#x2F;&#x2F;github.com&#x2F;iovisor&#x2F;bcc</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;libbpf&#x2F;libbpf">https:&#x2F;&#x2F;github.com&#x2F;libbpf&#x2F;libbpf</a><p>[3] <a href="https:&#x2F;&#x2F;github.com&#x2F;xdp-project&#x2F;xdp-tools">https:&#x2F;&#x2F;github.com&#x2F;xdp-project&#x2F;xdp-tools</a><p>[4] <a href="https:&#x2F;&#x2F;github.com&#x2F;cilium&#x2F;ebpf&#x2F;">https:&#x2F;&#x2F;github.com&#x2F;cilium&#x2F;ebpf&#x2F;</a><p>[5] <a href="https:&#x2F;&#x2F;github.com&#x2F;cilium&#x2F;ebpf&#x2F;tree&#x2F;master&#x2F;examples&#x2F;headers">https:&#x2F;&#x2F;github.com&#x2F;cilium&#x2F;ebpf&#x2F;tree&#x2F;master&#x2F;examples&#x2F;headers</a><p>[6] <a href="https:&#x2F;&#x2F;elixir.bootlin.com&#x2F;linux&#x2F;latest&#x2F;source&#x2F;tools&#x2F;testing&#x2F;selftests&#x2F;bpf" rel="nofollow noreferrer">https:&#x2F;&#x2F;elixir.bootlin.com&#x2F;linux&#x2F;latest&#x2F;source&#x2F;tools&#x2F;testing...</a><p>[7] <a href="https:&#x2F;&#x2F;github.com&#x2F;libbpf&#x2F;libbpf&#x2F;wiki&#x2F;Libbpf-1.0-migration-guide">https:&#x2F;&#x2F;github.com&#x2F;libbpf&#x2F;libbpf&#x2F;wiki&#x2F;Libbpf-1.0-migration-g...</a><p>[8] <a href="https:&#x2F;&#x2F;github.com&#x2F;evilsocket&#x2F;opensnitch&#x2F;blob&#x2F;master&#x2F;ebpf_prog&#x2F;Makefile">https:&#x2F;&#x2F;github.com&#x2F;evilsocket&#x2F;opensnitch&#x2F;blob&#x2F;master&#x2F;ebpf_pr...</a><p>[9] <a href="https:&#x2F;&#x2F;isovalent.com&#x2F;learning-ebpf&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;isovalent.com&#x2F;learning-ebpf&#x2F;</a><p>[10] (e.g.) <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=L3_AOFSNKK8">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=L3_AOFSNKK8</a>