diff options
author | Dimitar Kanaliev <[email protected]> | 2024-10-14 15:11:55 +0300 |
---|---|---|
committer | Alexei Starovoitov <[email protected]> | 2024-10-15 11:16:25 -0700 |
commit | 35ccd576a23ce495b4064f4a3445626de790cd23 (patch) | |
tree | e182ec5e34751574f8d6d7a69ddb8f77a40bc0c4 | |
parent | 61f506eacc77a9dad510fce92477af72be82c89d (diff) |
selftests/bpf: Add test for sign extension in coerce_subreg_to_size_sx()
Add a test for unsigned ranges after signed extension instruction. This
case isn't currently covered by existing tests in verifier_movsx.c.
Acked-by: Shung-Hsi Yu <[email protected]>
Signed-off-by: Dimitar Kanaliev <[email protected]>
Acked-by: Yonghong Song <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>
-rw-r--r-- | tools/testing/selftests/bpf/progs/verifier_movsx.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/verifier_movsx.c b/tools/testing/selftests/bpf/progs/verifier_movsx.c index 0cb879c609c5..994bbc346d25 100644 --- a/tools/testing/selftests/bpf/progs/verifier_movsx.c +++ b/tools/testing/selftests/bpf/progs/verifier_movsx.c @@ -307,6 +307,26 @@ label_%=: \ : __clobber_all); } +SEC("socket") +__description("MOV32SX, S8, unsigned range_check") +__success __retval(0) +__naked void mov32sx_s8_range_check(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + w0 &= 0x1; \ + w0 += 0xfe; \ + w0 = (s8)w0; \ + if w0 < 0xfffffffe goto label_%=; \ + r0 = 0; \ + exit; \ +label_%=: \ + exit; \ + " : + : __imm(bpf_get_prandom_u32) + : __clobber_all); +} + #else SEC("socket") |