Skip to content

Commit 9295678

Browse files
cupermirAlexei Starovoitov
authored andcommitted
selftests/bpf: MUL range computation tests.
Added a test for bound computation in MUL when non constant values are used and both registers have bounded ranges. Signed-off-by: Cupertino Miranda <cupertino.miranda@oracle.com> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Acked-by: Andrii Nakryiko <andrii.nakryiko@gmail.com> Cc: Yonghong Song <yonghong.song@linux.dev> Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com> Cc: David Faust <david.faust@oracle.com> Cc: Jose Marchesi <jose.marchesi@oracle.com> Cc: Elena Zannoni <elena.zannoni@oracle.com> Link: https://lore.kernel.org/r/20240506141849.185293-7-cupertino.miranda@oracle.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 41d047a commit 9295678

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tools/testing/selftests/bpf/progs/verifier_bounds.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,27 @@ __naked void non_const_or_src_dst(void)
927927
: __clobber_all);
928928
}
929929

930+
SEC("socket")
931+
__description("bounds check for non const mul regs")
932+
__success __log_level(2)
933+
__msg("5: (2f) r0 *= r6 ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=3825,var_off=(0x0; 0xfff))")
934+
__naked void non_const_mul_regs(void)
935+
{
936+
asm volatile (" \
937+
call %[bpf_get_prandom_u32]; \
938+
r6 = r0; \
939+
call %[bpf_get_prandom_u32]; \
940+
r6 &= 0xff; \
941+
r0 &= 0x0f; \
942+
r0 *= r6; \
943+
exit; \
944+
" :
945+
: __imm(bpf_map_lookup_elem),
946+
__imm_addr(map_hash_8b),
947+
__imm(bpf_get_prandom_u32)
948+
: __clobber_all);
949+
}
950+
930951
SEC("socket")
931952
__description("bounds checks after 32-bit truncation. test 1")
932953
__success __failure_unpriv __msg_unpriv("R0 leaks addr")

0 commit comments

Comments
 (0)