1// SPDX-License-Identifier: GPL-2.0
2/* Converted from tools/testing/selftests/bpf/verifier/cgroup_inv_retcode.c */
3
4#include <linux/bpf.h>
5#include <bpf/bpf_helpers.h>
6#include "bpf_misc.h"
7
8SEC("cgroup/sock")
9__description("bpf_exit with invalid return code. test1")
10__failure __msg("smin=0 smax=4294967295 should have been in [0, 1]")
11__naked void with_invalid_return_code_test1(void)
12{
13 asm volatile (" \
14 r0 = *(u32*)(r1 + 0); \
15 exit; \
16" ::: __clobber_all);
17}
18
19SEC("cgroup/sock")
20__description("bpf_exit with invalid return code. test2")
21__success
22__naked void with_invalid_return_code_test2(void)
23{
24 asm volatile (" \
25 r0 = *(u32*)(r1 + 0); \
26 r0 &= 1; \
27 exit; \
28" ::: __clobber_all);
29}
30
31SEC("cgroup/sock")
32__description("bpf_exit with invalid return code. test3")
33__failure __msg("smin=0 smax=3 should have been in [0, 1]")
34__naked void with_invalid_return_code_test3(void)
35{
36 asm volatile (" \
37 r0 = *(u32*)(r1 + 0); \
38 r0 &= 3; \
39 exit; \
40" ::: __clobber_all);
41}
42
43SEC("cgroup/sock")
44__description("bpf_exit with invalid return code. test4")
45__success
46__naked void with_invalid_return_code_test4(void)
47{
48 asm volatile (" \
49 r0 = 1; \
50 exit; \
51" ::: __clobber_all);
52}
53
54SEC("cgroup/sock")
55__description("bpf_exit with invalid return code. test5")
56__failure __msg("smin=2 smax=2 should have been in [0, 1]")
57__naked void with_invalid_return_code_test5(void)
58{
59 asm volatile (" \
60 r0 = 2; \
61 exit; \
62" ::: __clobber_all);
63}
64
65SEC("cgroup/sock")
66__description("bpf_exit with invalid return code. test6")
67__failure __msg("R0 is not a known value (ctx)")
68__naked void with_invalid_return_code_test6(void)
69{
70 asm volatile (" \
71 r0 = r1; \
72 exit; \
73" ::: __clobber_all);
74}
75
76SEC("cgroup/sock")
77__description("bpf_exit with invalid return code. test7")
78__failure __msg("R0 has unknown scalar value should have been in [0, 1]")
79__naked void with_invalid_return_code_test7(void)
80{
81 asm volatile (" \
82 r0 = *(u32*)(r1 + 0); \
83 r2 = *(u32*)(r1 + 4); \
84 r0 *= r2; \
85 exit; \
86" ::: __clobber_all);
87}
88
89char _license[] SEC("license") = "GPL";
90

source code of linux/tools/testing/selftests/bpf/progs/verifier_cgroup_inv_retcode.c