bpf: propagate precision across all frames, not just the last one
authorAndrii Nakryiko <andrii@kernel.org>
Fri, 4 Nov 2022 16:36:45 +0000 (09:36 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 4 Nov 2022 18:51:45 +0000 (11:51 -0700)
commit529409ea92d590659be487ba0839710329bd8074
tree460fdecdbde36f93fab96e0c595eb9fff6fc6a5c
parenta3b666bfa9c9edc05bca62a87abafe0936bd7f97
bpf: propagate precision across all frames, not just the last one

When equivalent completed state is found and it has additional precision
restrictions, BPF verifier propagates precision to
currently-being-verified state chain (i.e., including parent states) so
that if some of the states in the chain are not yet completed, necessary
precision restrictions are enforced.

Unfortunately, right now this happens only for the last frame (deepest
active subprogram's frame), not all the frames. This can lead to
incorrect matching of states due to missing precision marker. Currently
this doesn't seem possible as BPF verifier forces everything to precise
when validated BPF program has any subprograms. But with the next patch
lifting this restriction, this becomes problematic.

In fact, without this fix, we'll start getting failure in one of the
existing test_verifier test cases:

  #906/p precise: cross frame pruning FAIL
  Unexpected success to load!
  verification time 48 usec
  stack depth 0+0
  processed 26 insns (limit 1000000) max_states_per_insn 3 total_states 17 peak_states 17 mark_read 8

This patch adds precision propagation across all frames.

Fixes: a3ce685dd01a ("bpf: fix precision tracking")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20221104163649.121784-3-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c