Skip to content

Commit f6ef558

Browse files
puranjaymohanAlexei Starovoitov
authored andcommitted
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>
1 parent b0388ba commit f6ef558

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,51 @@ __naked void ignore_unique_scalar_ids_old(void)
715715
: __clobber_all);
716716
}
717717

718+
/* Check that two registers with 0 scalar IDs in a verified state can be mapped
719+
* to the same scalar ID in current state.
720+
*/
721+
SEC("socket")
722+
__success __log_level(2)
723+
/* The states should be equivalent on reaching insn 12.
724+
*/
725+
__msg("12: safe")
726+
__msg("processed 17 insns")
727+
__flag(BPF_F_TEST_STATE_FREQ)
728+
__naked void two_nil_old_ids_one_cur_id(void)
729+
{
730+
asm volatile (
731+
/* Give unique scalar IDs to r{6,7} */
732+
"call %[bpf_ktime_get_ns];"
733+
"r0 &= 0xff;"
734+
"r6 = r0;"
735+
"r6 *= 1;"
736+
"call %[bpf_ktime_get_ns];"
737+
"r0 &= 0xff;"
738+
"r7 = r0;"
739+
"r7 *= 1;"
740+
"r0 = 0;"
741+
/* Maybe make r{6,7} IDs identical */
742+
"if r6 > r7 goto l0_%=;"
743+
"goto l1_%=;"
744+
"l0_%=:"
745+
"r6 = r7;"
746+
"l1_%=:"
747+
/* Mark r{6,7} precise.
748+
* Get here in two states:
749+
* - first: r6{.id=0}, r7{.id=0} (cached state)
750+
* - second: r6{.id=A}, r7{.id=A}
751+
* Verifier considers such states equivalent.
752+
* Thus "exit;" would be verified only once.
753+
*/
754+
"r2 = r10;"
755+
"r2 += r6;"
756+
"r2 += r7;"
757+
"exit;"
758+
:
759+
: __imm(bpf_ktime_get_ns)
760+
: __clobber_all);
761+
}
762+
718763
/* Check that two different scalar IDs in a verified state can't be
719764
* mapped to the same scalar ID in current state.
720765
*/

0 commit comments

Comments
 (0)