xref: /linux/tools/testing/selftests/bpf/verifier/jump.c (revision 2b64b2ed277ff23e785fbdb65098ee7e1252d64f)
1 {
2 	"jump test 1",
3 	.insns = {
4 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
5 	BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -8),
6 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 1),
7 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -8, 0),
8 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 1, 1),
9 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -16, 1),
10 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 2, 1),
11 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -8, 2),
12 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 3, 1),
13 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -16, 3),
14 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 4, 1),
15 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -8, 4),
16 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 5, 1),
17 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -32, 5),
18 	BPF_MOV64_IMM(BPF_REG_0, 0),
19 	BPF_EXIT_INSN(),
20 	},
21 	.errstr_unpriv = "R1 pointer comparison",
22 	.result_unpriv = REJECT,
23 	.result = ACCEPT,
24 },
25 {
26 	"jump test 2",
27 	.insns = {
28 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
29 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 2),
30 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -8, 0),
31 	BPF_JMP_IMM(BPF_JA, 0, 0, 14),
32 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 1, 2),
33 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -16, 0),
34 	BPF_JMP_IMM(BPF_JA, 0, 0, 11),
35 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 2, 2),
36 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -32, 0),
37 	BPF_JMP_IMM(BPF_JA, 0, 0, 8),
38 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 3, 2),
39 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -40, 0),
40 	BPF_JMP_IMM(BPF_JA, 0, 0, 5),
41 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 4, 2),
42 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -48, 0),
43 	BPF_JMP_IMM(BPF_JA, 0, 0, 2),
44 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 5, 1),
45 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -56, 0),
46 	BPF_MOV64_IMM(BPF_REG_0, 0),
47 	BPF_EXIT_INSN(),
48 	},
49 	.errstr_unpriv = "R1 pointer comparison",
50 	.result_unpriv = REJECT,
51 	.result = ACCEPT,
52 },
53 {
54 	"jump test 3",
55 	.insns = {
56 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
57 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 3),
58 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -8, 0),
59 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
60 	BPF_JMP_IMM(BPF_JA, 0, 0, 19),
61 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 1, 3),
62 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -16, 0),
63 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -16),
64 	BPF_JMP_IMM(BPF_JA, 0, 0, 15),
65 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 2, 3),
66 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -32, 0),
67 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -32),
68 	BPF_JMP_IMM(BPF_JA, 0, 0, 11),
69 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 3, 3),
70 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -40, 0),
71 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -40),
72 	BPF_JMP_IMM(BPF_JA, 0, 0, 7),
73 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 4, 3),
74 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -48, 0),
75 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -48),
76 	BPF_JMP_IMM(BPF_JA, 0, 0, 3),
77 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 5, 0),
78 	BPF_ST_MEM(BPF_DW, BPF_REG_2, -56, 0),
79 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -56),
80 	BPF_LD_MAP_FD(BPF_REG_1, 0),
81 	BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_delete_elem),
82 	BPF_EXIT_INSN(),
83 	},
84 	.fixup_map_hash_8b = { 24 },
85 	.errstr_unpriv = "R1 pointer comparison",
86 	.result_unpriv = REJECT,
87 	.result = ACCEPT,
88 	.retval = -ENOENT,
89 },
90 {
91 	"jump test 4",
92 	.insns = {
93 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
94 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
95 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
96 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
97 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
98 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
99 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
100 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
101 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
102 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
103 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
104 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
105 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
106 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
107 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
108 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
109 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
110 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
111 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
112 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
113 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
114 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
115 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
116 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
117 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
118 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
119 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
120 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
121 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
122 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
123 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
124 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
125 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
126 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
127 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
128 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
129 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 0),
130 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 0),
131 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 0),
132 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 0),
133 	BPF_MOV64_IMM(BPF_REG_0, 0),
134 	BPF_EXIT_INSN(),
135 	},
136 	.errstr_unpriv = "R1 pointer comparison",
137 	.result_unpriv = REJECT,
138 	.result = ACCEPT,
139 },
140 {
141 	"jump test 5",
142 	.insns = {
143 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
144 	BPF_MOV64_REG(BPF_REG_3, BPF_REG_2),
145 	BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0, 2),
146 	BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_3, -8),
147 	BPF_JMP_IMM(BPF_JA, 0, 0, 2),
148 	BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_2, -8),
149 	BPF_JMP_IMM(BPF_JA, 0, 0, 0),
150 	BPF_MOV64_IMM(BPF_REG_0, 0),
151 	BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0, 2),
152 	BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_3, -8),
153 	BPF_JMP_IMM(BPF_JA, 0, 0, 2),
154 	BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_2, -8),
155 	BPF_JMP_IMM(BPF_JA, 0, 0, 0),
156 	BPF_MOV64_IMM(BPF_REG_0, 0),
157 	BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0, 2),
158 	BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_3, -8),
159 	BPF_JMP_IMM(BPF_JA, 0, 0, 2),
160 	BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_2, -8),
161 	BPF_JMP_IMM(BPF_JA, 0, 0, 0),
162 	BPF_MOV64_IMM(BPF_REG_0, 0),
163 	BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0, 2),
164 	BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_3, -8),
165 	BPF_JMP_IMM(BPF_JA, 0, 0, 2),
166 	BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_2, -8),
167 	BPF_JMP_IMM(BPF_JA, 0, 0, 0),
168 	BPF_MOV64_IMM(BPF_REG_0, 0),
169 	BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0, 2),
170 	BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_3, -8),
171 	BPF_JMP_IMM(BPF_JA, 0, 0, 2),
172 	BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_2, -8),
173 	BPF_JMP_IMM(BPF_JA, 0, 0, 0),
174 	BPF_MOV64_IMM(BPF_REG_0, 0),
175 	BPF_EXIT_INSN(),
176 	},
177 	.errstr_unpriv = "R1 pointer comparison",
178 	.result_unpriv = REJECT,
179 	.result = ACCEPT,
180 },
181