selftests/bpf: Verify that check_ids() is used for scalars in regsafe()
authorEduard Zingerman <eddyz87@gmail.com>
Tue, 13 Jun 2023 15:38:24 +0000 (18:38 +0300)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 13 Jun 2023 22:15:13 +0000 (15:15 -0700)
commit18b89265572b5c899522b6c1f8698e87edfad369
treeb54adfd56be610fc6423c01aaf05b1364fb91a23
parent1ffc85d9298e0ca0137ba65c93a786143fe167b8
selftests/bpf: Verify that check_ids() is used for scalars in regsafe()

Verify that the following example is rejected by verifier:

  r9 = ... some pointer with range X ...
  r6 = ... unbound scalar ID=a ...
  r7 = ... unbound scalar ID=b ...
  if (r6 > r7) goto +1
  r7 = r6
  if (r7 > X) goto exit
  r9 += r6
  *(u64 *)r9 = Y

Also add test cases to:
- check that check_alu_op() for BPF_MOV instruction does not allocate
  scalar ID if source register is a constant;
- check that unique scalar IDs are ignored when new verifier state is
  compared to cached verifier state;
- check that two different scalar IDs in a verified state can't be
  mapped to the same scalar ID in current state.

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230613153824.3324830-5-eddyz87@gmail.com
tools/testing/selftests/bpf/progs/verifier_scalar_ids.c