1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/lwt.c */
5 #include <bpf/bpf_helpers.h>
9 __description("invalid direct packet write for LWT_IN")
10 __failure __msg("cannot write into packet")
11 __naked void packet_write_for_lwt_in(void)
14 r2 = *(u32*)(r1 + %[__sk_buff_data]); \
15 r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
18 if r0 > r3 goto l0_%=; \
19 *(u8*)(r2 + 0) = r2; \
23 : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
24 __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end))
29 __description("invalid direct packet write for LWT_OUT")
30 __failure __msg("cannot write into packet")
31 __naked void packet_write_for_lwt_out(void)
34 r2 = *(u32*)(r1 + %[__sk_buff_data]); \
35 r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
38 if r0 > r3 goto l0_%=; \
39 *(u8*)(r2 + 0) = r2; \
43 : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
44 __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end))
49 __description("direct packet write for LWT_XMIT")
51 __naked void packet_write_for_lwt_xmit(void)
54 r2 = *(u32*)(r1 + %[__sk_buff_data]); \
55 r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
58 if r0 > r3 goto l0_%=; \
59 *(u8*)(r2 + 0) = r2; \
63 : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
64 __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end))
69 __description("direct packet read for LWT_IN")
71 __naked void packet_read_for_lwt_in(void)
74 r2 = *(u32*)(r1 + %[__sk_buff_data]); \
75 r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
78 if r0 > r3 goto l0_%=; \
79 r0 = *(u8*)(r2 + 0); \
83 : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
84 __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end))
89 __description("direct packet read for LWT_OUT")
91 __naked void packet_read_for_lwt_out(void)
94 r2 = *(u32*)(r1 + %[__sk_buff_data]); \
95 r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
98 if r0 > r3 goto l0_%=; \
99 r0 = *(u8*)(r2 + 0); \
103 : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
104 __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end))
109 __description("direct packet read for LWT_XMIT")
110 __success __retval(0)
111 __naked void packet_read_for_lwt_xmit(void)
114 r2 = *(u32*)(r1 + %[__sk_buff_data]); \
115 r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
118 if r0 > r3 goto l0_%=; \
119 r0 = *(u8*)(r2 + 0); \
123 : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
124 __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end))
129 __description("overlapping checks for direct packet access")
130 __success __retval(0)
131 __naked void checks_for_direct_packet_access(void)
134 r2 = *(u32*)(r1 + %[__sk_buff_data]); \
135 r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
138 if r0 > r3 goto l0_%=; \
141 if r1 > r3 goto l0_%=; \
142 r0 = *(u16*)(r2 + 6); \
146 : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
147 __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end))
152 __description("make headroom for LWT_XMIT")
153 __success __retval(0)
154 __naked void make_headroom_for_lwt_xmit(void)
160 call %[bpf_skb_change_head]; \
161 /* split for s390 to succeed */ \
165 call %[bpf_skb_change_head]; \
169 : __imm(bpf_skb_change_head)
174 __description("invalid access of tc_classid for LWT_IN")
175 __failure __msg("invalid bpf_context access")
177 __naked void tc_classid_for_lwt_in(void)
180 r0 = *(u32*)(r1 + %[__sk_buff_tc_classid]); \
183 : __imm_const(__sk_buff_tc_classid, offsetof(struct __sk_buff, tc_classid))
188 __description("invalid access of tc_classid for LWT_OUT")
189 __failure __msg("invalid bpf_context access")
191 __naked void tc_classid_for_lwt_out(void)
194 r0 = *(u32*)(r1 + %[__sk_buff_tc_classid]); \
197 : __imm_const(__sk_buff_tc_classid, offsetof(struct __sk_buff, tc_classid))
202 __description("invalid access of tc_classid for LWT_XMIT")
203 __failure __msg("invalid bpf_context access")
205 __naked void tc_classid_for_lwt_xmit(void)
208 r0 = *(u32*)(r1 + %[__sk_buff_tc_classid]); \
211 : __imm_const(__sk_buff_tc_classid, offsetof(struct __sk_buff, tc_classid))
216 __description("check skb->tc_classid half load not permitted for lwt prog")
217 __failure __msg("invalid bpf_context access")
218 __naked void not_permitted_for_lwt_prog(void)
222 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
223 "r0 = *(u16*)(r1 + %[__sk_buff_tc_classid]);"
225 "r0 = *(u16*)(r1 + %[__imm_0]);"
229 : __imm_const(__imm_0, offsetof(struct __sk_buff, tc_classid) + 2),
230 __imm_const(__sk_buff_tc_classid, offsetof(struct __sk_buff, tc_classid))
234 char _license[] SEC("license") = "GPL";