]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Add test for sign extension in coerce_subreg_to_size_sx()
authorDimitar Kanaliev <dimitar.kanaliev@siteground.com>
Mon, 14 Oct 2024 12:11:55 +0000 (15:11 +0300)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 15 Oct 2024 18:16:25 +0000 (11:16 -0700)
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 <shung-hsi.yu@suse.com>
Signed-off-by: Dimitar Kanaliev <dimitar.kanaliev@siteground.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20241014121155.92887-4-dimitar.kanaliev@siteground.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/progs/verifier_movsx.c

index 0cb879c609c5705d403ddd2a2e0c68072a25bc12..994bbc346d25d7d37c678bdbf2290ff297ec7af1 100644 (file)
@@ -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")