xref: /openbmc/linux/tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c (revision c79fe9b436690209954f908a41b19e0bf575877a)
1 {
2 	"valid 1,2,4,8-byte reads from bpf_sk_lookup",
3 	.insns = {
4 		/* 1-byte read from family field */
5 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
6 			    offsetof(struct bpf_sk_lookup, family)),
7 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
8 			    offsetof(struct bpf_sk_lookup, family) + 1),
9 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
10 			    offsetof(struct bpf_sk_lookup, family) + 2),
11 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
12 			    offsetof(struct bpf_sk_lookup, family) + 3),
13 		/* 2-byte read from family field */
14 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
15 			    offsetof(struct bpf_sk_lookup, family)),
16 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
17 			    offsetof(struct bpf_sk_lookup, family) + 2),
18 		/* 4-byte read from family field */
19 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
20 			    offsetof(struct bpf_sk_lookup, family)),
21 
22 		/* 1-byte read from protocol field */
23 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
24 			    offsetof(struct bpf_sk_lookup, protocol)),
25 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
26 			    offsetof(struct bpf_sk_lookup, protocol) + 1),
27 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
28 			    offsetof(struct bpf_sk_lookup, protocol) + 2),
29 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
30 			    offsetof(struct bpf_sk_lookup, protocol) + 3),
31 		/* 2-byte read from protocol field */
32 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
33 			    offsetof(struct bpf_sk_lookup, protocol)),
34 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
35 			    offsetof(struct bpf_sk_lookup, protocol) + 2),
36 		/* 4-byte read from protocol field */
37 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
38 			    offsetof(struct bpf_sk_lookup, protocol)),
39 
40 		/* 1-byte read from remote_ip4 field */
41 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
42 			    offsetof(struct bpf_sk_lookup, remote_ip4)),
43 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
44 			    offsetof(struct bpf_sk_lookup, remote_ip4) + 1),
45 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
46 			    offsetof(struct bpf_sk_lookup, remote_ip4) + 2),
47 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
48 			    offsetof(struct bpf_sk_lookup, remote_ip4) + 3),
49 		/* 2-byte read from remote_ip4 field */
50 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
51 			    offsetof(struct bpf_sk_lookup, remote_ip4)),
52 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
53 			    offsetof(struct bpf_sk_lookup, remote_ip4) + 2),
54 		/* 4-byte read from remote_ip4 field */
55 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
56 			    offsetof(struct bpf_sk_lookup, remote_ip4)),
57 
58 		/* 1-byte read from remote_ip6 field */
59 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
60 			    offsetof(struct bpf_sk_lookup, remote_ip6)),
61 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
62 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 1),
63 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
64 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 2),
65 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
66 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 3),
67 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
68 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 4),
69 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
70 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 5),
71 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
72 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 6),
73 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
74 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 7),
75 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
76 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 8),
77 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
78 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 9),
79 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
80 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 10),
81 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
82 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 11),
83 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
84 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 12),
85 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
86 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 13),
87 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
88 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 14),
89 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
90 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 15),
91 		/* 2-byte read from remote_ip6 field */
92 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
93 			    offsetof(struct bpf_sk_lookup, remote_ip6)),
94 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
95 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 2),
96 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
97 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 4),
98 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
99 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 6),
100 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
101 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 8),
102 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
103 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 10),
104 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
105 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 12),
106 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
107 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 14),
108 		/* 4-byte read from remote_ip6 field */
109 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
110 			    offsetof(struct bpf_sk_lookup, remote_ip6)),
111 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
112 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 4),
113 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
114 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 8),
115 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
116 			    offsetof(struct bpf_sk_lookup, remote_ip6) + 12),
117 
118 		/* 1-byte read from remote_port field */
119 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
120 			    offsetof(struct bpf_sk_lookup, remote_port)),
121 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
122 			    offsetof(struct bpf_sk_lookup, remote_port) + 1),
123 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
124 			    offsetof(struct bpf_sk_lookup, remote_port) + 2),
125 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
126 			    offsetof(struct bpf_sk_lookup, remote_port) + 3),
127 		/* 2-byte read from remote_port field */
128 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
129 			    offsetof(struct bpf_sk_lookup, remote_port)),
130 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
131 			    offsetof(struct bpf_sk_lookup, remote_port) + 2),
132 		/* 4-byte read from remote_port field */
133 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
134 			    offsetof(struct bpf_sk_lookup, remote_port)),
135 
136 		/* 1-byte read from local_ip4 field */
137 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
138 			    offsetof(struct bpf_sk_lookup, local_ip4)),
139 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
140 			    offsetof(struct bpf_sk_lookup, local_ip4) + 1),
141 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
142 			    offsetof(struct bpf_sk_lookup, local_ip4) + 2),
143 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
144 			    offsetof(struct bpf_sk_lookup, local_ip4) + 3),
145 		/* 2-byte read from local_ip4 field */
146 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
147 			    offsetof(struct bpf_sk_lookup, local_ip4)),
148 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
149 			    offsetof(struct bpf_sk_lookup, local_ip4) + 2),
150 		/* 4-byte read from local_ip4 field */
151 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
152 			    offsetof(struct bpf_sk_lookup, local_ip4)),
153 
154 		/* 1-byte read from local_ip6 field */
155 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
156 			    offsetof(struct bpf_sk_lookup, local_ip6)),
157 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
158 			    offsetof(struct bpf_sk_lookup, local_ip6) + 1),
159 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
160 			    offsetof(struct bpf_sk_lookup, local_ip6) + 2),
161 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
162 			    offsetof(struct bpf_sk_lookup, local_ip6) + 3),
163 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
164 			    offsetof(struct bpf_sk_lookup, local_ip6) + 4),
165 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
166 			    offsetof(struct bpf_sk_lookup, local_ip6) + 5),
167 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
168 			    offsetof(struct bpf_sk_lookup, local_ip6) + 6),
169 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
170 			    offsetof(struct bpf_sk_lookup, local_ip6) + 7),
171 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
172 			    offsetof(struct bpf_sk_lookup, local_ip6) + 8),
173 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
174 			    offsetof(struct bpf_sk_lookup, local_ip6) + 9),
175 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
176 			    offsetof(struct bpf_sk_lookup, local_ip6) + 10),
177 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
178 			    offsetof(struct bpf_sk_lookup, local_ip6) + 11),
179 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
180 			    offsetof(struct bpf_sk_lookup, local_ip6) + 12),
181 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
182 			    offsetof(struct bpf_sk_lookup, local_ip6) + 13),
183 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
184 			    offsetof(struct bpf_sk_lookup, local_ip6) + 14),
185 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
186 			    offsetof(struct bpf_sk_lookup, local_ip6) + 15),
187 		/* 2-byte read from local_ip6 field */
188 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
189 			    offsetof(struct bpf_sk_lookup, local_ip6)),
190 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
191 			    offsetof(struct bpf_sk_lookup, local_ip6) + 2),
192 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
193 			    offsetof(struct bpf_sk_lookup, local_ip6) + 4),
194 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
195 			    offsetof(struct bpf_sk_lookup, local_ip6) + 6),
196 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
197 			    offsetof(struct bpf_sk_lookup, local_ip6) + 8),
198 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
199 			    offsetof(struct bpf_sk_lookup, local_ip6) + 10),
200 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
201 			    offsetof(struct bpf_sk_lookup, local_ip6) + 12),
202 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
203 			    offsetof(struct bpf_sk_lookup, local_ip6) + 14),
204 		/* 4-byte read from local_ip6 field */
205 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
206 			    offsetof(struct bpf_sk_lookup, local_ip6)),
207 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
208 			    offsetof(struct bpf_sk_lookup, local_ip6) + 4),
209 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
210 			    offsetof(struct bpf_sk_lookup, local_ip6) + 8),
211 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
212 			    offsetof(struct bpf_sk_lookup, local_ip6) + 12),
213 
214 		/* 1-byte read from local_port field */
215 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
216 			    offsetof(struct bpf_sk_lookup, local_port)),
217 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
218 			    offsetof(struct bpf_sk_lookup, local_port) + 1),
219 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
220 			    offsetof(struct bpf_sk_lookup, local_port) + 2),
221 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
222 			    offsetof(struct bpf_sk_lookup, local_port) + 3),
223 		/* 2-byte read from local_port field */
224 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
225 			    offsetof(struct bpf_sk_lookup, local_port)),
226 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
227 			    offsetof(struct bpf_sk_lookup, local_port) + 2),
228 		/* 4-byte read from local_port field */
229 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
230 			    offsetof(struct bpf_sk_lookup, local_port)),
231 
232 		/* 8-byte read from sk field */
233 		BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
234 			    offsetof(struct bpf_sk_lookup, sk)),
235 
236 		BPF_MOV32_IMM(BPF_REG_0, 0),
237 		BPF_EXIT_INSN(),
238 	},
239 	.result = ACCEPT,
240 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
241 	.expected_attach_type = BPF_SK_LOOKUP,
242 },
243 /* invalid 8-byte reads from a 4-byte fields in bpf_sk_lookup */
244 {
245 	"invalid 8-byte read from bpf_sk_lookup family field",
246 	.insns = {
247 		BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
248 			    offsetof(struct bpf_sk_lookup, family)),
249 		BPF_MOV32_IMM(BPF_REG_0, 0),
250 		BPF_EXIT_INSN(),
251 	},
252 	.errstr = "invalid bpf_context access",
253 	.result = REJECT,
254 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
255 	.expected_attach_type = BPF_SK_LOOKUP,
256 },
257 {
258 	"invalid 8-byte read from bpf_sk_lookup protocol field",
259 	.insns = {
260 		BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
261 			    offsetof(struct bpf_sk_lookup, protocol)),
262 		BPF_MOV32_IMM(BPF_REG_0, 0),
263 		BPF_EXIT_INSN(),
264 	},
265 	.errstr = "invalid bpf_context access",
266 	.result = REJECT,
267 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
268 	.expected_attach_type = BPF_SK_LOOKUP,
269 	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
270 },
271 {
272 	"invalid 8-byte read from bpf_sk_lookup remote_ip4 field",
273 	.insns = {
274 		BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
275 			    offsetof(struct bpf_sk_lookup, remote_ip4)),
276 		BPF_MOV32_IMM(BPF_REG_0, 0),
277 		BPF_EXIT_INSN(),
278 	},
279 	.errstr = "invalid bpf_context access",
280 	.result = REJECT,
281 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
282 	.expected_attach_type = BPF_SK_LOOKUP,
283 },
284 {
285 	"invalid 8-byte read from bpf_sk_lookup remote_ip6 field",
286 	.insns = {
287 		BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
288 			    offsetof(struct bpf_sk_lookup, remote_ip6)),
289 		BPF_MOV32_IMM(BPF_REG_0, 0),
290 		BPF_EXIT_INSN(),
291 	},
292 	.errstr = "invalid bpf_context access",
293 	.result = REJECT,
294 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
295 	.expected_attach_type = BPF_SK_LOOKUP,
296 	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
297 },
298 {
299 	"invalid 8-byte read from bpf_sk_lookup remote_port field",
300 	.insns = {
301 		BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
302 			    offsetof(struct bpf_sk_lookup, remote_port)),
303 		BPF_MOV32_IMM(BPF_REG_0, 0),
304 		BPF_EXIT_INSN(),
305 	},
306 	.errstr = "invalid bpf_context access",
307 	.result = REJECT,
308 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
309 	.expected_attach_type = BPF_SK_LOOKUP,
310 	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
311 },
312 {
313 	"invalid 8-byte read from bpf_sk_lookup local_ip4 field",
314 	.insns = {
315 		BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
316 			    offsetof(struct bpf_sk_lookup, local_ip4)),
317 		BPF_MOV32_IMM(BPF_REG_0, 0),
318 		BPF_EXIT_INSN(),
319 	},
320 	.errstr = "invalid bpf_context access",
321 	.result = REJECT,
322 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
323 	.expected_attach_type = BPF_SK_LOOKUP,
324 },
325 {
326 	"invalid 8-byte read from bpf_sk_lookup local_ip6 field",
327 	.insns = {
328 		BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
329 			    offsetof(struct bpf_sk_lookup, local_ip6)),
330 		BPF_MOV32_IMM(BPF_REG_0, 0),
331 		BPF_EXIT_INSN(),
332 	},
333 	.errstr = "invalid bpf_context access",
334 	.result = REJECT,
335 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
336 	.expected_attach_type = BPF_SK_LOOKUP,
337 	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
338 },
339 {
340 	"invalid 8-byte read from bpf_sk_lookup local_port field",
341 	.insns = {
342 		BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1,
343 			    offsetof(struct bpf_sk_lookup, local_port)),
344 		BPF_MOV32_IMM(BPF_REG_0, 0),
345 		BPF_EXIT_INSN(),
346 	},
347 	.errstr = "invalid bpf_context access",
348 	.result = REJECT,
349 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
350 	.expected_attach_type = BPF_SK_LOOKUP,
351 	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
352 },
353 /* invalid 1,2,4-byte reads from 8-byte fields in bpf_sk_lookup */
354 {
355 	"invalid 4-byte read from bpf_sk_lookup sk field",
356 	.insns = {
357 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
358 			    offsetof(struct bpf_sk_lookup, sk)),
359 		BPF_MOV32_IMM(BPF_REG_0, 0),
360 		BPF_EXIT_INSN(),
361 	},
362 	.errstr = "invalid bpf_context access",
363 	.result = REJECT,
364 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
365 	.expected_attach_type = BPF_SK_LOOKUP,
366 },
367 {
368 	"invalid 2-byte read from bpf_sk_lookup sk field",
369 	.insns = {
370 		BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1,
371 			    offsetof(struct bpf_sk_lookup, sk)),
372 		BPF_MOV32_IMM(BPF_REG_0, 0),
373 		BPF_EXIT_INSN(),
374 	},
375 	.errstr = "invalid bpf_context access",
376 	.result = REJECT,
377 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
378 	.expected_attach_type = BPF_SK_LOOKUP,
379 },
380 {
381 	"invalid 1-byte read from bpf_sk_lookup sk field",
382 	.insns = {
383 		BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
384 			    offsetof(struct bpf_sk_lookup, sk)),
385 		BPF_MOV32_IMM(BPF_REG_0, 0),
386 		BPF_EXIT_INSN(),
387 	},
388 	.errstr = "invalid bpf_context access",
389 	.result = REJECT,
390 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
391 	.expected_attach_type = BPF_SK_LOOKUP,
392 },
393 /* out of bounds and unaligned reads from bpf_sk_lookup */
394 {
395 	"invalid 4-byte read past end of bpf_sk_lookup",
396 	.insns = {
397 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
398 			    sizeof(struct bpf_sk_lookup)),
399 		BPF_MOV32_IMM(BPF_REG_0, 0),
400 		BPF_EXIT_INSN(),
401 	},
402 	.errstr = "invalid bpf_context access",
403 	.result = REJECT,
404 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
405 	.expected_attach_type = BPF_SK_LOOKUP,
406 },
407 {
408 	"invalid 4-byte unaligned read from bpf_sk_lookup at odd offset",
409 	.insns = {
410 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 1),
411 		BPF_MOV32_IMM(BPF_REG_0, 0),
412 		BPF_EXIT_INSN(),
413 	},
414 	.errstr = "invalid bpf_context access",
415 	.result = REJECT,
416 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
417 	.expected_attach_type = BPF_SK_LOOKUP,
418 	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
419 },
420 {
421 	"invalid 4-byte unaligned read from bpf_sk_lookup at even offset",
422 	.insns = {
423 		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 2),
424 		BPF_MOV32_IMM(BPF_REG_0, 0),
425 		BPF_EXIT_INSN(),
426 	},
427 	.errstr = "invalid bpf_context access",
428 	.result = REJECT,
429 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
430 	.expected_attach_type = BPF_SK_LOOKUP,
431 	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
432 },
433 /* in-bound and out-of-bound writes to bpf_sk_lookup */
434 {
435 	"invalid 8-byte write to bpf_sk_lookup",
436 	.insns = {
437 		BPF_MOV64_IMM(BPF_REG_0, 0xcafe4a11U),
438 		BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, 0),
439 		BPF_MOV32_IMM(BPF_REG_0, 0),
440 		BPF_EXIT_INSN(),
441 	},
442 	.errstr = "invalid bpf_context access",
443 	.result = REJECT,
444 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
445 	.expected_attach_type = BPF_SK_LOOKUP,
446 },
447 {
448 	"invalid 4-byte write to bpf_sk_lookup",
449 	.insns = {
450 		BPF_MOV64_IMM(BPF_REG_0, 0xcafe4a11U),
451 		BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, 0),
452 		BPF_MOV32_IMM(BPF_REG_0, 0),
453 		BPF_EXIT_INSN(),
454 	},
455 	.errstr = "invalid bpf_context access",
456 	.result = REJECT,
457 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
458 	.expected_attach_type = BPF_SK_LOOKUP,
459 },
460 {
461 	"invalid 2-byte write to bpf_sk_lookup",
462 	.insns = {
463 		BPF_MOV64_IMM(BPF_REG_0, 0xcafe4a11U),
464 		BPF_STX_MEM(BPF_H, BPF_REG_1, BPF_REG_0, 0),
465 		BPF_MOV32_IMM(BPF_REG_0, 0),
466 		BPF_EXIT_INSN(),
467 	},
468 	.errstr = "invalid bpf_context access",
469 	.result = REJECT,
470 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
471 	.expected_attach_type = BPF_SK_LOOKUP,
472 },
473 {
474 	"invalid 1-byte write to bpf_sk_lookup",
475 	.insns = {
476 		BPF_MOV64_IMM(BPF_REG_0, 0xcafe4a11U),
477 		BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, 0),
478 		BPF_MOV32_IMM(BPF_REG_0, 0),
479 		BPF_EXIT_INSN(),
480 	},
481 	.errstr = "invalid bpf_context access",
482 	.result = REJECT,
483 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
484 	.expected_attach_type = BPF_SK_LOOKUP,
485 },
486 {
487 	"invalid 4-byte write past end of bpf_sk_lookup",
488 	.insns = {
489 		BPF_MOV64_IMM(BPF_REG_0, 0xcafe4a11U),
490 		BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0,
491 			    sizeof(struct bpf_sk_lookup)),
492 		BPF_MOV32_IMM(BPF_REG_0, 0),
493 		BPF_EXIT_INSN(),
494 	},
495 	.errstr = "invalid bpf_context access",
496 	.result = REJECT,
497 	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
498 	.expected_attach_type = BPF_SK_LOOKUP,
499 },
500