Skip to content

Commit 61f506e

Browse files
dkanalievAlexei Starovoitov
authored andcommitted
selftests/bpf: Add test for truncation after sign extension in coerce_reg_to_size_sx()
Add test that checks whether unsigned ranges deduced by the verifier for sign extension instruction is correct. Without previous patch that fixes truncation in coerce_reg_to_size_sx() this test fails. 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-3-dimitar.kanaliev@siteground.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent ae67b9f commit 61f506e

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
@@ -287,6 +287,26 @@ l0_%=: \
287287
: __clobber_all);
288288
}
289289

290+
SEC("socket")
291+
__description("MOV64SX, S8, unsigned range_check")
292+
__success __retval(0)
293+
__naked void mov64sx_s8_range_check(void)
294+
{
295+
asm volatile (" \
296+
call %[bpf_get_prandom_u32]; \
297+
r0 &= 0x1; \
298+
r0 += 0xfe; \
299+
r0 = (s8)r0; \
300+
if r0 < 0xfffffffffffffffe goto label_%=; \
301+
r0 = 0; \
302+
exit; \
303+
label_%=: \
304+
exit; \
305+
" :
306+
: __imm(bpf_get_prandom_u32)
307+
: __clobber_all);
308+
}
309+
290310
#else
291311

292312
SEC("socket")

0 commit comments

Comments
 (0)