1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/value.c */
5 #include <bpf/bpf_helpers.h>
16 __uint(type, BPF_MAP_TYPE_HASH);
17 __uint(max_entries, 1);
18 __type(key, long long);
19 __type(value, struct test_val);
20 } map_hash_48b SEC(".maps");
23 __description("map element value store of cleared call register")
24 __failure __msg("R1 !read_ok")
25 __failure_unpriv __msg_unpriv("R1 !read_ok")
26 __naked void store_of_cleared_call_register(void)
32 *(u64*)(r2 + 0) = r1; \
33 r1 = %[map_hash_48b] ll; \
34 call %[bpf_map_lookup_elem]; \
35 if r0 == 0 goto l0_%=; \
36 *(u64*)(r0 + 0) = r1; \
39 : __imm(bpf_map_lookup_elem),
40 __imm_addr(map_hash_48b)
45 __description("map element value with unaligned store")
46 __success __failure_unpriv __msg_unpriv("R0 leaks addr")
47 __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
48 __naked void element_value_with_unaligned_store(void)
54 *(u64*)(r2 + 0) = r1; \
55 r1 = %[map_hash_48b] ll; \
56 call %[bpf_map_lookup_elem]; \
57 if r0 == 0 goto l0_%=; \
60 *(u64*)(r0 + 0) = r1; \
62 *(u64*)(r0 + 2) = r1; \
64 *(u64*)(r0 - 2) = r1; \
67 *(u64*)(r8 + 0) = r1; \
69 *(u64*)(r8 + 2) = r1; \
71 *(u64*)(r8 - 2) = r1; \
74 *(u64*)(r8 + 0) = r1; \
76 *(u64*)(r8 + 4) = r1; \
78 *(u64*)(r8 - 7) = r1; \
82 *(u64*)(r7 + 0) = r1; \
84 *(u64*)(r7 + 4) = r1; \
86 *(u64*)(r7 - 4) = r1; \
89 : __imm(bpf_map_lookup_elem),
90 __imm_addr(map_hash_48b)
95 __description("map element value with unaligned load")
96 __success __failure_unpriv __msg_unpriv("R0 leaks addr")
97 __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
98 __naked void element_value_with_unaligned_load(void)
104 *(u64*)(r2 + 0) = r1; \
105 r1 = %[map_hash_48b] ll; \
106 call %[bpf_map_lookup_elem]; \
107 if r0 == 0 goto l0_%=; \
108 r1 = *(u32*)(r0 + 0); \
109 if r1 >= %[max_entries] goto l0_%=; \
111 r7 = *(u64*)(r0 + 0); \
112 r7 = *(u64*)(r0 + 2); \
114 r7 = *(u64*)(r8 + 0); \
115 r7 = *(u64*)(r8 + 2); \
117 r7 = *(u64*)(r0 + 0); \
118 r7 = *(u64*)(r0 + 4); \
121 : __imm(bpf_map_lookup_elem),
122 __imm_addr(map_hash_48b),
123 __imm_const(max_entries, MAX_ENTRIES)
128 __description("map element value is preserved across register spilling")
129 __success __failure_unpriv __msg_unpriv("R0 leaks addr")
130 __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
131 __naked void is_preserved_across_register_spilling(void)
137 *(u64*)(r2 + 0) = r1; \
138 r1 = %[map_hash_48b] ll; \
139 call %[bpf_map_lookup_elem]; \
140 if r0 == 0 goto l0_%=; \
141 r0 += %[test_val_foo]; \
143 *(u64*)(r0 + 0) = r1; \
146 *(u64*)(r1 + 0) = r0; \
147 r3 = *(u64*)(r1 + 0); \
149 *(u64*)(r3 + 0) = r1; \
152 : __imm(bpf_map_lookup_elem),
153 __imm_addr(map_hash_48b),
154 __imm_const(test_val_foo, offsetof(struct test_val, foo))
158 char _license[] SEC("license") = "GPL";