1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/int_ptr.c */
5 #include <bpf/bpf_helpers.h>
9 __description("ARG_PTR_TO_LONG uninitialized")
11 __failure_unpriv __msg_unpriv("invalid indirect read from stack R4 off -16+0 size 8")
12 __naked void arg_ptr_to_long_uninitialized(void)
15 /* bpf_strtoul arg1 (buf) */ \
19 *(u64*)(r7 + 0) = r0; \
21 /* bpf_strtoul arg2 (buf_len) */ \
23 /* bpf_strtoul arg3 (flags) */ \
25 /* bpf_strtoul arg4 (res) */ \
29 call %[bpf_strtoul]; \
38 __description("ARG_PTR_TO_LONG half-uninitialized")
39 /* in privileged mode reads from uninitialized stack locations are permitted */
40 __success __failure_unpriv
41 __msg_unpriv("invalid indirect read from stack R4 off -16+4 size 8")
43 __naked void ptr_to_long_half_uninitialized(void)
46 /* bpf_strtoul arg1 (buf) */ \
50 *(u64*)(r7 + 0) = r0; \
52 /* bpf_strtoul arg2 (buf_len) */ \
54 /* bpf_strtoul arg3 (flags) */ \
56 /* bpf_strtoul arg4 (res) */ \
58 *(u32*)(r7 + 0) = r0; \
61 call %[bpf_strtoul]; \
70 __description("ARG_PTR_TO_LONG misaligned")
71 __failure __msg("misaligned stack access off (0x0; 0x0)+-20+0 size 8")
72 __naked void arg_ptr_to_long_misaligned(void)
75 /* bpf_strtoul arg1 (buf) */ \
79 *(u64*)(r7 + 0) = r0; \
81 /* bpf_strtoul arg2 (buf_len) */ \
83 /* bpf_strtoul arg3 (flags) */ \
85 /* bpf_strtoul arg4 (res) */ \
88 *(u32*)(r7 + 0) = r0; \
89 *(u64*)(r7 + 4) = r0; \
92 call %[bpf_strtoul]; \
101 __description("ARG_PTR_TO_LONG size < sizeof(long)")
102 __failure __msg("invalid indirect access to stack R4 off=-4 size=8")
103 __naked void to_long_size_sizeof_long(void)
106 /* bpf_strtoul arg1 (buf) */ \
110 *(u64*)(r7 + 0) = r0; \
112 /* bpf_strtoul arg2 (buf_len) */ \
114 /* bpf_strtoul arg3 (flags) */ \
116 /* bpf_strtoul arg4 (res) */ \
118 *(u32*)(r7 + 0) = r0; \
120 /* bpf_strtoul() */ \
121 call %[bpf_strtoul]; \
130 __description("ARG_PTR_TO_LONG initialized")
132 __naked void arg_ptr_to_long_initialized(void)
135 /* bpf_strtoul arg1 (buf) */ \
139 *(u64*)(r7 + 0) = r0; \
141 /* bpf_strtoul arg2 (buf_len) */ \
143 /* bpf_strtoul arg3 (flags) */ \
145 /* bpf_strtoul arg4 (res) */ \
147 *(u64*)(r7 + 0) = r0; \
149 /* bpf_strtoul() */ \
150 call %[bpf_strtoul]; \
158 char _license[] SEC("license") = "GPL";