On Mon, Jun 17, 2019 at 06:57PM, Alexei Starovoitov wrote: > On 6/17/19 9:39 AM, Andrii Nakryiko wrote: > > On Sat, Jun 15, 2019 at 12:12 PM Alexei Starovoitov <ast@xxxxxxxxxx> wrote: > >> > >> v2->v3: fixed issues in backtracking pointed out by Andrii. > >> The next step is to add a lot more tests for backtracking. > >> > > > > Tests would be great, verifier complexity is at the level, where it's > > very easy to miss issues. > > > > Was fuzzying approach ever discussed for BPF verifier? I.e., have a > > fuzzer to generate both legal and illegal random small programs. Then > > re-implement verifier as user-level program with straightforward > > recursive exhaustive verification (so no state pruning logic, no > > precise/coarse, etc, just register/stack state tracking) of all > > possible branches. If kernel verifier's verdict differs from > > user-level verifier's verdict - flag that as a test case and figure > > out why they differ. Obviously that would work well only for small > > programs, but that should be a good first step already. > > > > In addition, if this is done, that user-land verifier can be a HUGE > > help to BPF application developers, as libbpf would (potentially) be > > able to generate better error messages using it as well. > > In theory that sounds good, but doesn't work in practice. > The kernel verifier keeps changing faster than user space can catch up. > It's also relying on loaded maps and all sorts of callbacks that > check context, allowed helpers, maps, combinations of them from all > over the kernel. > The last effort to build kernel verifier as-is into .o and link > with kmalloc/map wrappers in user space was here: > https://github.com/iovisor/bpf-fuzzer > It was fuzzing the verifier and was able to find few minor bugs. > But it quickly bit rotted. We've been working (with Xiao Han, cc'ed) on an update of bpf-fuzzer. It helped us find a few issues in the verifier (mostly thanks to warn_on("verifier bug")s). I'll probably send a patchset to the main repository in the next few weeks. Updating the glue code (userspace wrappers) is okay so far, as long as done regularly. [...] > > I think syzbot is still generating bpf programs. iirc it found > one bug in the past in the verifier core. syzkaller's template description of BPF programs is very limited. It produces valid BPF instructions, but loaded programs make little sense, are trivial or invalid, and don't go very far in the verifier. We probably can't rely on syzkaller to be effective for the verifier. > I think the only way to make verifier more robust is to keep > adding new test cases manually. > Most interesting bugs we found by humans. Tests and reviews are definitely the most effective ways to find bugs, despite the above two fuzzers. The verifier is complex enough that the random approach of fuzzers has a hard time covering the code. Paul