1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/and.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("invalid and of negative number")
24 __failure __msg("R0 max value is outside of the allowed memory range")
26 __flag(BPF_F_ANY_ALIGNMENT)
27 __naked void invalid_and_of_negative_number(void)
31 *(u64*)(r10 - 8) = r1; \
34 r1 = %[map_hash_48b] ll; \
35 call %[bpf_map_lookup_elem]; \
36 if r0 == 0 goto l0_%=; \
37 r1 = *(u8*)(r0 + 0); \
41 l0_%=: r1 = %[test_val_foo]; \
42 *(u64*)(r0 + 0) = r1; \
45 : __imm(bpf_map_lookup_elem),
46 __imm_addr(map_hash_48b),
47 __imm_const(test_val_foo, offsetof(struct test_val, foo))
52 __description("invalid range check")
53 __failure __msg("R0 max value is outside of the allowed memory range")
55 __flag(BPF_F_ANY_ALIGNMENT)
56 __naked void invalid_range_check(void)
60 *(u64*)(r10 - 8) = r1; \
63 r1 = %[map_hash_48b] ll; \
64 call %[bpf_map_lookup_elem]; \
65 if r0 == 0 goto l0_%=; \
66 r1 = *(u32*)(r0 + 0); \
77 *(u32*)(r0 + 0) = r3; \
81 : __imm(bpf_map_lookup_elem),
82 __imm_addr(map_hash_48b)
87 __description("check known subreg with unknown reg")
88 __success __failure_unpriv __msg_unpriv("R1 !read_ok")
90 __naked void known_subreg_with_unknown_reg(void)
93 call %[bpf_get_prandom_u32]; \
97 /* Upper bits are unknown but AND above masks out 1 zero'ing lower bits */\
98 if w0 < 1 goto l0_%=; \
99 r1 = *(u32*)(r1 + 512); \
103 : __imm(bpf_get_prandom_u32)
107 char _license[] SEC("license") = "GPL";