selftests/bpf: add testcase to verifier_bounds.c for BPF_JNE
authorMenglong Dong <menglong8.dong@gmail.com>
Tue, 19 Dec 2023 13:48:00 +0000 (21:48 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 20 Dec 2023 01:18:56 +0000 (17:18 -0800)
commit463ea64eb008b7abb63245ed69446b404bf042b1
tree0d1fa15dd3ee74bc0af37143406f7d19e8a3dddc
parent31d9cc96b1e3b28daf74938cb1233231474bbcf6
selftests/bpf: add testcase to verifier_bounds.c for BPF_JNE

Add testcase for the logic that the verifier tracks the BPF_JNE for regs.
The assembly function "reg_not_equal_const()" and "reg_equal_const" that
we add is exactly converted from the following case:

  u32 a = bpf_get_prandom_u32();
  u64 b = 0;

  a %= 8;
  /* the "a > 0" here will be optimized to "a != 0" */
  if (a > 0) {
    /* now the range of a should be [1, 7] */
    bpf_skb_store_bytes(skb, 0, &b, a, 0);
  }

Signed-off-by: Menglong Dong <menglong8.dong@gmail.com>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20231219134800.1550388-5-menglong8.dong@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/progs/verifier_bounds.c