Sadly, the tests aren't really worth much here - the bug was in the _kernel_ not the eBPF code! Once again - we'd need to run our tests on the affected kernels to see the problem. We're not there yet, our automatic testing infra runs on another set of kernels than production. Oops on our side.
But the fact is - testing new eBPF features is hard. You need to run a rich eBPF bytecode, on a modern kernel. I think the proper approach is to run usermode linux, and run tests _inside_ of it. Not sure how hard would that be to pull it off though.
Approach similar to this project: https://source.android.com/devices/architecture/kernel/netwo...
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...
Tests for the corner case that has caused the problem have been added shortly after it was fixed:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...
The other problem is that eBPF is a far way from KISS. But then that’s what’s needed for power and performance.
EDIT after RTFA: and security against spectre and friends.
EDIT: I’m curious if a down voter can provide a piece of code that tests whether two compilates are equivalent.
The root cause of the bug in the article was introduced by a patch to automatically modify an arbitrary program to harden against spectre.
assert func(params) == rewrite(func)(params)
for some reasonable set of func and params. Totally enough to catch problems like this. I'd say [unit-]testing that subtraction operator works is not that hard.It would help the discussion if you read the TFA (edit: more carefully).
Rewrite() in this case modified the params program to harden it against Spectre.
What you do is put together a long list of sample functions and sample arguments that covers the expected edge cases and then test those for equivalence. Hardly impossible. Just takes time. Not bulletproof but better than nothing.
You can just run the original and rewritten code in an eBPF VM with mock inputs and compare.