1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/helper_restricted.c */
5 #include <bpf/bpf_helpers.h>
10 struct bpf_spin_lock l;
14 __uint(type, BPF_MAP_TYPE_ARRAY);
15 __uint(max_entries, 1);
17 __type(value, struct val);
18 } map_spin_lock SEC(".maps");
25 __uint(type, BPF_MAP_TYPE_ARRAY);
26 __uint(max_entries, 1);
28 __type(value, struct timer);
29 } map_timer SEC(".maps");
32 __description("bpf_ktime_get_coarse_ns is forbidden in BPF_PROG_TYPE_KPROBE")
33 __failure __msg("unknown func bpf_ktime_get_coarse_ns")
34 __naked void in_bpf_prog_type_kprobe_1(void)
37 call %[bpf_ktime_get_coarse_ns]; \
41 : __imm(bpf_ktime_get_coarse_ns)
46 __description("bpf_ktime_get_coarse_ns is forbidden in BPF_PROG_TYPE_TRACEPOINT")
47 __failure __msg("unknown func bpf_ktime_get_coarse_ns")
48 __naked void in_bpf_prog_type_tracepoint_1(void)
51 call %[bpf_ktime_get_coarse_ns]; \
55 : __imm(bpf_ktime_get_coarse_ns)
60 __description("bpf_ktime_get_coarse_ns is forbidden in BPF_PROG_TYPE_PERF_EVENT")
61 __failure __msg("unknown func bpf_ktime_get_coarse_ns")
62 __naked void bpf_prog_type_perf_event_1(void)
65 call %[bpf_ktime_get_coarse_ns]; \
69 : __imm(bpf_ktime_get_coarse_ns)
74 __description("bpf_ktime_get_coarse_ns is forbidden in BPF_PROG_TYPE_RAW_TRACEPOINT")
75 __failure __msg("unknown func bpf_ktime_get_coarse_ns")
76 __naked void bpf_prog_type_raw_tracepoint_1(void)
79 call %[bpf_ktime_get_coarse_ns]; \
83 : __imm(bpf_ktime_get_coarse_ns)
88 __description("bpf_timer_init isn restricted in BPF_PROG_TYPE_KPROBE")
89 __failure __msg("tracing progs cannot use bpf_timer yet")
90 __naked void in_bpf_prog_type_kprobe_2(void)
96 *(u64*)(r2 + 0) = r1; \
97 r1 = %[map_timer] ll; \
98 call %[bpf_map_lookup_elem]; \
99 if r0 == 0 goto l0_%=; \
101 r2 = %[map_timer] ll; \
103 l0_%=: call %[bpf_timer_init]; \
106 : __imm(bpf_map_lookup_elem),
107 __imm(bpf_timer_init),
108 __imm_addr(map_timer)
113 __description("bpf_timer_init is forbidden in BPF_PROG_TYPE_PERF_EVENT")
114 __failure __msg("tracing progs cannot use bpf_timer yet")
115 __naked void bpf_prog_type_perf_event_2(void)
121 *(u64*)(r2 + 0) = r1; \
122 r1 = %[map_timer] ll; \
123 call %[bpf_map_lookup_elem]; \
124 if r0 == 0 goto l0_%=; \
126 r2 = %[map_timer] ll; \
128 l0_%=: call %[bpf_timer_init]; \
131 : __imm(bpf_map_lookup_elem),
132 __imm(bpf_timer_init),
133 __imm_addr(map_timer)
138 __description("bpf_timer_init is forbidden in BPF_PROG_TYPE_TRACEPOINT")
139 __failure __msg("tracing progs cannot use bpf_timer yet")
140 __naked void in_bpf_prog_type_tracepoint_2(void)
146 *(u64*)(r2 + 0) = r1; \
147 r1 = %[map_timer] ll; \
148 call %[bpf_map_lookup_elem]; \
149 if r0 == 0 goto l0_%=; \
151 r2 = %[map_timer] ll; \
153 l0_%=: call %[bpf_timer_init]; \
156 : __imm(bpf_map_lookup_elem),
157 __imm(bpf_timer_init),
158 __imm_addr(map_timer)
162 SEC("raw_tracepoint")
163 __description("bpf_timer_init is forbidden in BPF_PROG_TYPE_RAW_TRACEPOINT")
164 __failure __msg("tracing progs cannot use bpf_timer yet")
165 __naked void bpf_prog_type_raw_tracepoint_2(void)
171 *(u64*)(r2 + 0) = r1; \
172 r1 = %[map_timer] ll; \
173 call %[bpf_map_lookup_elem]; \
174 if r0 == 0 goto l0_%=; \
176 r2 = %[map_timer] ll; \
178 l0_%=: call %[bpf_timer_init]; \
181 : __imm(bpf_map_lookup_elem),
182 __imm(bpf_timer_init),
183 __imm_addr(map_timer)
188 __description("bpf_spin_lock is forbidden in BPF_PROG_TYPE_KPROBE")
189 __failure __msg("tracing progs cannot use bpf_spin_lock yet")
190 __naked void in_bpf_prog_type_kprobe_3(void)
196 *(u64*)(r2 + 0) = r1; \
197 r1 = %[map_spin_lock] ll; \
198 call %[bpf_map_lookup_elem]; \
199 if r0 == 0 goto l0_%=; \
201 call %[bpf_spin_lock]; \
204 : __imm(bpf_map_lookup_elem),
205 __imm(bpf_spin_lock),
206 __imm_addr(map_spin_lock)
211 __description("bpf_spin_lock is forbidden in BPF_PROG_TYPE_TRACEPOINT")
212 __failure __msg("tracing progs cannot use bpf_spin_lock yet")
213 __naked void in_bpf_prog_type_tracepoint_3(void)
219 *(u64*)(r2 + 0) = r1; \
220 r1 = %[map_spin_lock] ll; \
221 call %[bpf_map_lookup_elem]; \
222 if r0 == 0 goto l0_%=; \
224 call %[bpf_spin_lock]; \
227 : __imm(bpf_map_lookup_elem),
228 __imm(bpf_spin_lock),
229 __imm_addr(map_spin_lock)
234 __description("bpf_spin_lock is forbidden in BPF_PROG_TYPE_PERF_EVENT")
235 __failure __msg("tracing progs cannot use bpf_spin_lock yet")
236 __naked void bpf_prog_type_perf_event_3(void)
242 *(u64*)(r2 + 0) = r1; \
243 r1 = %[map_spin_lock] ll; \
244 call %[bpf_map_lookup_elem]; \
245 if r0 == 0 goto l0_%=; \
247 call %[bpf_spin_lock]; \
250 : __imm(bpf_map_lookup_elem),
251 __imm(bpf_spin_lock),
252 __imm_addr(map_spin_lock)
256 SEC("raw_tracepoint")
257 __description("bpf_spin_lock is forbidden in BPF_PROG_TYPE_RAW_TRACEPOINT")
258 __failure __msg("tracing progs cannot use bpf_spin_lock yet")
259 __naked void bpf_prog_type_raw_tracepoint_3(void)
265 *(u64*)(r2 + 0) = r1; \
266 r1 = %[map_spin_lock] ll; \
267 call %[bpf_map_lookup_elem]; \
268 if r0 == 0 goto l0_%=; \
270 call %[bpf_spin_lock]; \
273 : __imm(bpf_map_lookup_elem),
274 __imm(bpf_spin_lock),
275 __imm_addr(map_spin_lock)
279 char _license[] SEC("license") = "GPL";