1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/ringbuf.c */
5 #include <bpf/bpf_helpers.h>
9 __uint(type, BPF_MAP_TYPE_RINGBUF);
10 __uint(max_entries, 4096);
11 } map_ringbuf SEC(".maps");
14 __description("ringbuf: invalid reservation offset 1")
15 __failure __msg("R1 must have zero offset when passed to release func")
17 __naked void ringbuf_invalid_reservation_offset_1(void)
20 /* reserve 8 byte ringbuf memory */ \
22 *(u64*)(r10 - 8) = r1; \
23 r1 = %[map_ringbuf] ll; \
26 call %[bpf_ringbuf_reserve]; \
27 /* store a pointer to the reserved memory in R6 */\
29 /* check whether the reservation was successful */\
30 if r0 == 0 goto l0_%=; \
31 /* spill R6(mem) into the stack */ \
32 *(u64*)(r10 - 8) = r6; \
33 /* fill it back in R7 */ \
34 r7 = *(u64*)(r10 - 8); \
35 /* should be able to access *(R7) = 0 */ \
37 *(u64*)(r7 + 0) = r1; \
38 /* submit the reserved ringbuf memory */ \
40 /* add invalid offset to reserved ringbuf memory */\
43 call %[bpf_ringbuf_submit]; \
47 : __imm(bpf_ringbuf_reserve),
48 __imm(bpf_ringbuf_submit),
49 __imm_addr(map_ringbuf)
54 __description("ringbuf: invalid reservation offset 2")
55 __failure __msg("R7 min value is outside of the allowed memory range")
57 __naked void ringbuf_invalid_reservation_offset_2(void)
60 /* reserve 8 byte ringbuf memory */ \
62 *(u64*)(r10 - 8) = r1; \
63 r1 = %[map_ringbuf] ll; \
66 call %[bpf_ringbuf_reserve]; \
67 /* store a pointer to the reserved memory in R6 */\
69 /* check whether the reservation was successful */\
70 if r0 == 0 goto l0_%=; \
71 /* spill R6(mem) into the stack */ \
72 *(u64*)(r10 - 8) = r6; \
73 /* fill it back in R7 */ \
74 r7 = *(u64*)(r10 - 8); \
75 /* add invalid offset to reserved ringbuf memory */\
77 /* should be able to access *(R7) = 0 */ \
79 *(u64*)(r7 + 0) = r1; \
80 /* submit the reserved ringbuf memory */ \
83 call %[bpf_ringbuf_submit]; \
87 : __imm(bpf_ringbuf_reserve),
88 __imm(bpf_ringbuf_submit),
89 __imm_addr(map_ringbuf)
94 __description("ringbuf: check passing rb mem to helpers")
96 __naked void passing_rb_mem_to_helpers(void)
100 /* reserve 8 byte ringbuf memory */ \
102 *(u64*)(r10 - 8) = r1; \
103 r1 = %[map_ringbuf] ll; \
106 call %[bpf_ringbuf_reserve]; \
108 /* check whether the reservation was successful */\
109 if r0 != 0 goto l0_%=; \
111 l0_%=: /* pass allocated ring buffer memory to fib lookup */\
116 call %[bpf_fib_lookup]; \
117 /* submit the ringbuf memory */ \
120 call %[bpf_ringbuf_submit]; \
124 : __imm(bpf_fib_lookup),
125 __imm(bpf_ringbuf_reserve),
126 __imm(bpf_ringbuf_submit),
127 __imm_addr(map_ringbuf)
131 char _license[] SEC("license") = "GPL";