Skip to content

Commit 35ccd57

Browse files
dkanalievAlexei Starovoitov
authored andcommitted
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>
1 parent 61f506e commit 35ccd57

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,26 @@ label_%=: \
307307
: __clobber_all);
308308
}
309309

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+
310330
#else
311331

312332
SEC("socket")

0 commit comments

Comments
 (0)