Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <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>

authored by

Dimitar Kanaliev and committed by
Alexei Starovoitov
35ccd576 61f506ea

+20
+20
tools/testing/selftests/bpf/progs/verifier_movsx.c
··· 307 307 : __clobber_all); 308 308 } 309 309 310 + SEC("socket") 311 + __description("MOV32SX, S8, unsigned range_check") 312 + __success __retval(0) 313 + __naked void mov32sx_s8_range_check(void) 314 + { 315 + asm volatile (" \ 316 + call %[bpf_get_prandom_u32]; \ 317 + w0 &= 0x1; \ 318 + w0 += 0xfe; \ 319 + w0 = (s8)w0; \ 320 + if w0 < 0xfffffffe goto label_%=; \ 321 + r0 = 0; \ 322 + exit; \ 323 + label_%=: \ 324 + exit; \ 325 + " : 326 + : __imm(bpf_get_prandom_u32) 327 + : __clobber_all); 328 + } 329 + 310 330 #else 311 331 312 332 SEC("socket")