1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/basic_stack.c */
5 #include <bpf/bpf_helpers.h>
9 __uint(type, BPF_MAP_TYPE_HASH);
10 __uint(max_entries, 1);
11 __type(key, long long);
12 __type(value, long long);
13 } map_hash_8b SEC(".maps");
16 __description("stack out of bounds")
17 __failure __msg("invalid write to stack")
19 __naked void stack_out_of_bounds(void)
23 *(u64*)(r10 + 8) = r1; \
29 __description("uninitialized stack1")
30 __failure __msg("invalid indirect read from stack")
32 __naked void uninitialized_stack1(void)
37 r1 = %[map_hash_8b] ll; \
38 call %[bpf_map_lookup_elem]; \
41 : __imm(bpf_map_lookup_elem),
42 __imm_addr(map_hash_8b)
47 __description("uninitialized stack2")
48 __failure __msg("invalid read from stack")
50 __naked void uninitialized_stack2(void)
54 r0 = *(u64*)(r2 - 8); \
60 __description("invalid fp arithmetic")
61 __failure __msg("R1 subtraction from stack pointer")
63 __naked void invalid_fp_arithmetic(void)
65 /* If this gets ever changed, make sure JITs can deal with it. */
70 *(u64*)(r1 + 0) = r0; \
76 __description("non-invalid fp arithmetic")
77 __success __success_unpriv __retval(0)
78 __naked void non_invalid_fp_arithmetic(void)
82 *(u64*)(r10 - 8) = r0; \
88 __description("misaligned read from stack")
89 __failure __msg("misaligned stack access")
91 __naked void misaligned_read_from_stack(void)
95 r0 = *(u64*)(r2 - 4); \
100 char _license[] SEC("license") = "GPL";