mirror of
https://github.com/torvalds/linux.git
synced 2026-05-26 16:12:59 +02:00
selftests/bpf: Add a test for ids=0 to verifier_scalar_ids test
Test that two registers with their id=0 (unlinked) in the cached state can be mapped to a single id (linked) in the current state. Signed-off-by: Puranjay Mohan <puranjay@kernel.org> Link: https://lore.kernel.org/r/20260203165102.2302462-6-puranjay@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
b0388bafa4
commit
f6ef5584cc
|
|
@ -715,6 +715,51 @@ __naked void ignore_unique_scalar_ids_old(void)
|
|||
: __clobber_all);
|
||||
}
|
||||
|
||||
/* Check that two registers with 0 scalar IDs in a verified state can be mapped
|
||||
* to the same scalar ID in current state.
|
||||
*/
|
||||
SEC("socket")
|
||||
__success __log_level(2)
|
||||
/* The states should be equivalent on reaching insn 12.
|
||||
*/
|
||||
__msg("12: safe")
|
||||
__msg("processed 17 insns")
|
||||
__flag(BPF_F_TEST_STATE_FREQ)
|
||||
__naked void two_nil_old_ids_one_cur_id(void)
|
||||
{
|
||||
asm volatile (
|
||||
/* Give unique scalar IDs to r{6,7} */
|
||||
"call %[bpf_ktime_get_ns];"
|
||||
"r0 &= 0xff;"
|
||||
"r6 = r0;"
|
||||
"r6 *= 1;"
|
||||
"call %[bpf_ktime_get_ns];"
|
||||
"r0 &= 0xff;"
|
||||
"r7 = r0;"
|
||||
"r7 *= 1;"
|
||||
"r0 = 0;"
|
||||
/* Maybe make r{6,7} IDs identical */
|
||||
"if r6 > r7 goto l0_%=;"
|
||||
"goto l1_%=;"
|
||||
"l0_%=:"
|
||||
"r6 = r7;"
|
||||
"l1_%=:"
|
||||
/* Mark r{6,7} precise.
|
||||
* Get here in two states:
|
||||
* - first: r6{.id=0}, r7{.id=0} (cached state)
|
||||
* - second: r6{.id=A}, r7{.id=A}
|
||||
* Verifier considers such states equivalent.
|
||||
* Thus "exit;" would be verified only once.
|
||||
*/
|
||||
"r2 = r10;"
|
||||
"r2 += r6;"
|
||||
"r2 += r7;"
|
||||
"exit;"
|
||||
:
|
||||
: __imm(bpf_ktime_get_ns)
|
||||
: __clobber_all);
|
||||
}
|
||||
|
||||
/* Check that two different scalar IDs in a verified state can't be
|
||||
* mapped to the same scalar ID in current state.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user