1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2024 Google LLC */
3
4 #include <linux/bpf.h>
5 #include <bpf/bpf_helpers.h>
6 #include <bpf_sockopt_helpers.h>
7 #include "bpf_misc.h"
8
9 SEC("cgroup/recvmsg4")
10 __success
recvmsg4_good_return_code(struct bpf_sock_addr * ctx)11 int recvmsg4_good_return_code(struct bpf_sock_addr *ctx)
12 {
13 return 1;
14 }
15
16 SEC("cgroup/recvmsg4")
17 __failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
recvmsg4_bad_return_code(struct bpf_sock_addr * ctx)18 int recvmsg4_bad_return_code(struct bpf_sock_addr *ctx)
19 {
20 return 0;
21 }
22
23 SEC("cgroup/recvmsg6")
24 __success
recvmsg6_good_return_code(struct bpf_sock_addr * ctx)25 int recvmsg6_good_return_code(struct bpf_sock_addr *ctx)
26 {
27 return 1;
28 }
29
30 SEC("cgroup/recvmsg6")
31 __failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
recvmsg6_bad_return_code(struct bpf_sock_addr * ctx)32 int recvmsg6_bad_return_code(struct bpf_sock_addr *ctx)
33 {
34 return 0;
35 }
36
37 SEC("cgroup/recvmsg_unix")
38 __success
recvmsg_unix_good_return_code(struct bpf_sock_addr * ctx)39 int recvmsg_unix_good_return_code(struct bpf_sock_addr *ctx)
40 {
41 return 1;
42 }
43
44 SEC("cgroup/recvmsg_unix")
45 __failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
recvmsg_unix_bad_return_code(struct bpf_sock_addr * ctx)46 int recvmsg_unix_bad_return_code(struct bpf_sock_addr *ctx)
47 {
48 return 0;
49 }
50
51 SEC("cgroup/sendmsg4")
52 __success
sendmsg4_good_return_code_0(struct bpf_sock_addr * ctx)53 int sendmsg4_good_return_code_0(struct bpf_sock_addr *ctx)
54 {
55 return 0;
56 }
57
58 SEC("cgroup/sendmsg4")
59 __success
sendmsg4_good_return_code_1(struct bpf_sock_addr * ctx)60 int sendmsg4_good_return_code_1(struct bpf_sock_addr *ctx)
61 {
62 return 1;
63 }
64
65 SEC("cgroup/sendmsg4")
66 __failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
sendmsg4_bad_return_code(struct bpf_sock_addr * ctx)67 int sendmsg4_bad_return_code(struct bpf_sock_addr *ctx)
68 {
69 return 2;
70 }
71
72 SEC("cgroup/sendmsg6")
73 __success
sendmsg6_good_return_code_0(struct bpf_sock_addr * ctx)74 int sendmsg6_good_return_code_0(struct bpf_sock_addr *ctx)
75 {
76 return 0;
77 }
78
79 SEC("cgroup/sendmsg6")
80 __success
sendmsg6_good_return_code_1(struct bpf_sock_addr * ctx)81 int sendmsg6_good_return_code_1(struct bpf_sock_addr *ctx)
82 {
83 return 1;
84 }
85
86 SEC("cgroup/sendmsg6")
87 __failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
sendmsg6_bad_return_code(struct bpf_sock_addr * ctx)88 int sendmsg6_bad_return_code(struct bpf_sock_addr *ctx)
89 {
90 return 2;
91 }
92
93 SEC("cgroup/sendmsg_unix")
94 __success
sendmsg_unix_good_return_code_0(struct bpf_sock_addr * ctx)95 int sendmsg_unix_good_return_code_0(struct bpf_sock_addr *ctx)
96 {
97 return 0;
98 }
99
100 SEC("cgroup/sendmsg_unix")
101 __success
sendmsg_unix_good_return_code_1(struct bpf_sock_addr * ctx)102 int sendmsg_unix_good_return_code_1(struct bpf_sock_addr *ctx)
103 {
104 return 1;
105 }
106
107 SEC("cgroup/sendmsg_unix")
108 __failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
sendmsg_unix_bad_return_code(struct bpf_sock_addr * ctx)109 int sendmsg_unix_bad_return_code(struct bpf_sock_addr *ctx)
110 {
111 return 2;
112 }
113
114 SEC("cgroup/getpeername4")
115 __success
getpeername4_good_return_code(struct bpf_sock_addr * ctx)116 int getpeername4_good_return_code(struct bpf_sock_addr *ctx)
117 {
118 return 1;
119 }
120
121 SEC("cgroup/getpeername4")
122 __failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
getpeername4_bad_return_code(struct bpf_sock_addr * ctx)123 int getpeername4_bad_return_code(struct bpf_sock_addr *ctx)
124 {
125 return 0;
126 }
127
128 SEC("cgroup/getpeername6")
129 __success
getpeername6_good_return_code(struct bpf_sock_addr * ctx)130 int getpeername6_good_return_code(struct bpf_sock_addr *ctx)
131 {
132 return 1;
133 }
134
135 SEC("cgroup/getpeername6")
136 __failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
getpeername6_bad_return_code(struct bpf_sock_addr * ctx)137 int getpeername6_bad_return_code(struct bpf_sock_addr *ctx)
138 {
139 return 0;
140 }
141
142 SEC("cgroup/getpeername_unix")
143 __success
getpeername_unix_good_return_code(struct bpf_sock_addr * ctx)144 int getpeername_unix_good_return_code(struct bpf_sock_addr *ctx)
145 {
146 return 1;
147 }
148
149 SEC("cgroup/getpeername_unix")
150 __failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
getpeername_unix_bad_return_code(struct bpf_sock_addr * ctx)151 int getpeername_unix_bad_return_code(struct bpf_sock_addr *ctx)
152 {
153 return 0;
154 }
155
156 SEC("cgroup/getsockname4")
157 __success
getsockname4_good_return_code(struct bpf_sock_addr * ctx)158 int getsockname4_good_return_code(struct bpf_sock_addr *ctx)
159 {
160 return 1;
161 }
162
163 SEC("cgroup/getsockname4")
164 __failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
getsockname4_bad_return_code(struct bpf_sock_addr * ctx)165 int getsockname4_bad_return_code(struct bpf_sock_addr *ctx)
166 {
167 return 0;
168 }
169
170 SEC("cgroup/getsockname6")
171 __success
getsockname6_good_return_code(struct bpf_sock_addr * ctx)172 int getsockname6_good_return_code(struct bpf_sock_addr *ctx)
173 {
174 return 1;
175 }
176
177 SEC("cgroup/getsockname6")
178 __failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
getsockname6_bad_return_code(struct bpf_sock_addr * ctx)179 int getsockname6_bad_return_code(struct bpf_sock_addr *ctx)
180 {
181 return 0;
182 }
183
184 SEC("cgroup/getsockname_unix")
185 __success
getsockname_unix_good_return_code(struct bpf_sock_addr * ctx)186 int getsockname_unix_good_return_code(struct bpf_sock_addr *ctx)
187 {
188 return 1;
189 }
190
191 SEC("cgroup/getsockname_unix")
192 __failure __msg("At program exit the register R0 has smin=0 smax=0 should have been in [1, 1]")
getsockname_unix_unix_bad_return_code(struct bpf_sock_addr * ctx)193 int getsockname_unix_unix_bad_return_code(struct bpf_sock_addr *ctx)
194 {
195 return 0;
196 }
197
198 SEC("cgroup/bind4")
199 __success
bind4_good_return_code_0(struct bpf_sock_addr * ctx)200 int bind4_good_return_code_0(struct bpf_sock_addr *ctx)
201 {
202 return 0;
203 }
204
205 SEC("cgroup/bind4")
206 __success
bind4_good_return_code_1(struct bpf_sock_addr * ctx)207 int bind4_good_return_code_1(struct bpf_sock_addr *ctx)
208 {
209 return 1;
210 }
211
212 SEC("cgroup/bind4")
213 __success
bind4_good_return_code_2(struct bpf_sock_addr * ctx)214 int bind4_good_return_code_2(struct bpf_sock_addr *ctx)
215 {
216 return 2;
217 }
218
219 SEC("cgroup/bind4")
220 __success
bind4_good_return_code_3(struct bpf_sock_addr * ctx)221 int bind4_good_return_code_3(struct bpf_sock_addr *ctx)
222 {
223 return 3;
224 }
225
226 SEC("cgroup/bind4")
227 __failure __msg("At program exit the register R0 has smin=4 smax=4 should have been in [0, 3]")
bind4_bad_return_code(struct bpf_sock_addr * ctx)228 int bind4_bad_return_code(struct bpf_sock_addr *ctx)
229 {
230 return 4;
231 }
232
233 SEC("cgroup/bind6")
234 __success
bind6_good_return_code_0(struct bpf_sock_addr * ctx)235 int bind6_good_return_code_0(struct bpf_sock_addr *ctx)
236 {
237 return 0;
238 }
239
240 SEC("cgroup/bind6")
241 __success
bind6_good_return_code_1(struct bpf_sock_addr * ctx)242 int bind6_good_return_code_1(struct bpf_sock_addr *ctx)
243 {
244 return 1;
245 }
246
247 SEC("cgroup/bind6")
248 __success
bind6_good_return_code_2(struct bpf_sock_addr * ctx)249 int bind6_good_return_code_2(struct bpf_sock_addr *ctx)
250 {
251 return 2;
252 }
253
254 SEC("cgroup/bind6")
255 __success
bind6_good_return_code_3(struct bpf_sock_addr * ctx)256 int bind6_good_return_code_3(struct bpf_sock_addr *ctx)
257 {
258 return 3;
259 }
260
261 SEC("cgroup/bind6")
262 __failure __msg("At program exit the register R0 has smin=4 smax=4 should have been in [0, 3]")
bind6_bad_return_code(struct bpf_sock_addr * ctx)263 int bind6_bad_return_code(struct bpf_sock_addr *ctx)
264 {
265 return 4;
266 }
267
268 SEC("cgroup/connect4")
269 __success
connect4_good_return_code_0(struct bpf_sock_addr * ctx)270 int connect4_good_return_code_0(struct bpf_sock_addr *ctx)
271 {
272 return 0;
273 }
274
275 SEC("cgroup/connect4")
276 __success
connect4_good_return_code_1(struct bpf_sock_addr * ctx)277 int connect4_good_return_code_1(struct bpf_sock_addr *ctx)
278 {
279 return 1;
280 }
281
282 SEC("cgroup/connect4")
283 __failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
connect4_bad_return_code(struct bpf_sock_addr * ctx)284 int connect4_bad_return_code(struct bpf_sock_addr *ctx)
285 {
286 return 2;
287 }
288
289 SEC("cgroup/connect6")
290 __success
connect6_good_return_code_0(struct bpf_sock_addr * ctx)291 int connect6_good_return_code_0(struct bpf_sock_addr *ctx)
292 {
293 return 0;
294 }
295
296 SEC("cgroup/connect6")
297 __success
connect6_good_return_code_1(struct bpf_sock_addr * ctx)298 int connect6_good_return_code_1(struct bpf_sock_addr *ctx)
299 {
300 return 1;
301 }
302
303 SEC("cgroup/connect6")
304 __failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
connect6_bad_return_code(struct bpf_sock_addr * ctx)305 int connect6_bad_return_code(struct bpf_sock_addr *ctx)
306 {
307 return 2;
308 }
309
310 SEC("cgroup/connect_unix")
311 __success
connect_unix_good_return_code_0(struct bpf_sock_addr * ctx)312 int connect_unix_good_return_code_0(struct bpf_sock_addr *ctx)
313 {
314 return 0;
315 }
316
317 SEC("cgroup/connect_unix")
318 __success
connect_unix_good_return_code_1(struct bpf_sock_addr * ctx)319 int connect_unix_good_return_code_1(struct bpf_sock_addr *ctx)
320 {
321 return 1;
322 }
323
324 SEC("cgroup/connect_unix")
325 __failure __msg("At program exit the register R0 has smin=2 smax=2 should have been in [0, 1]")
connect_unix_bad_return_code(struct bpf_sock_addr * ctx)326 int connect_unix_bad_return_code(struct bpf_sock_addr *ctx)
327 {
328 return 2;
329 }
330
331 char _license[] SEC("license") = "GPL";
332