Verification fails for program of sample extension type. #455
-
While working on #342 I encountered an issue where verification fails on an eBPF program of the sample_extension type. To repro please checkout https://github.com/shankarseal/ebpf-for-windows/tree/utility_functions and build the solution. Then run unit_tests.exe verify_test1. The source code is annotated with comments on what causes the verification to succeed and what to fail. In short, the verifier fails with the following report
where prototype of the helper function is:
The 3rd parameter to this function is return value from another helper function. If the local variable storing this value is either initialized to 0 or if this is the last helper function of the program then verification succeeds. I need help to investigate this further. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Code has this:
Verification fails because the verifier believes that values[0] could be false while values[1] could be true, in which case the 3rd parameter is uninitialized memory. |
Beta Was this translation helpful? Give feedback.
-
It worked by chance because in the passing case (sample_ext) but not in the failing case (sample_ext/1), the compiler put a "r0 = 42" instruction after the call to bpf_map_lookup_elem, which meant it was initialized to 42 since that register was copied to the 3rd argument. In the failing case, r0 held the result of bpf_map_lookup_elem which was not an integer. So the byte code would verify even if the source code had a bug. The verified code was safe but probably didn't do what you wanted it to do. BTW, the fact that the output only showed the first two args to sample_ebpf_extension_replace is a display bug, fixed in vbpf/ebpf-verifier#253 |
Beta Was this translation helpful? Give feedback.
It worked by chance because in the passing case (sample_ext) but not in the failing case (sample_ext/1), the compiler put a "r0 = 42" instruction after the call to bpf_map_lookup_elem, which meant it was initialized to 42 since that register was copied to the 3rd argument. In the failing case, r0 held the result of bpf_map_lookup_elem which was not an integer. So the byte code would verify even if the source code had a bug. The verified code was safe but probably didn't do what you wanted it to do.
BTW, the fact that the output only showed the first two args to sample_ebpf_extension_replace is a display bug, fixed in vbpf/ebpf-verifier#253