WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / verifier / jset.c
blob8dcd4e0383d5739a17ab217ee96df1cdbd982a3f
2 "jset: functional",
3 .insns = {
4 BPF_DIRECT_PKT_R2,
5 BPF_LDX_MEM(BPF_DW, BPF_REG_7, BPF_REG_2, 0),
7 /* reg, bit 63 or bit 0 set, taken */
8 BPF_LD_IMM64(BPF_REG_8, 0x8000000000000001),
9 BPF_JMP_REG(BPF_JSET, BPF_REG_7, BPF_REG_8, 1),
10 BPF_EXIT_INSN(),
12 /* reg, bit 62, not taken */
13 BPF_LD_IMM64(BPF_REG_8, 0x4000000000000000),
14 BPF_JMP_REG(BPF_JSET, BPF_REG_7, BPF_REG_8, 1),
15 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
16 BPF_EXIT_INSN(),
18 /* imm, any bit set, taken */
19 BPF_JMP_IMM(BPF_JSET, BPF_REG_7, -1, 1),
20 BPF_EXIT_INSN(),
22 /* imm, bit 31 set, taken */
23 BPF_JMP_IMM(BPF_JSET, BPF_REG_7, 0x80000000, 1),
24 BPF_EXIT_INSN(),
26 /* all good - return r0 == 2 */
27 BPF_MOV64_IMM(BPF_REG_0, 2),
28 BPF_EXIT_INSN(),
30 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
31 .result = ACCEPT,
32 .runs = 7,
33 .retvals = {
34 { .retval = 2,
35 .data64 = { (1ULL << 63) | (1U << 31) | (1U << 0), }
37 { .retval = 2,
38 .data64 = { (1ULL << 63) | (1U << 31), }
40 { .retval = 2,
41 .data64 = { (1ULL << 31) | (1U << 0), }
43 { .retval = 2,
44 .data64 = { (__u32)-1, }
46 { .retval = 2,
47 .data64 = { ~0x4000000000000000ULL, }
49 { .retval = 0,
50 .data64 = { 0, }
52 { .retval = 0,
53 .data64 = { ~0ULL, }
56 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
59 "jset: sign-extend",
60 .insns = {
61 BPF_DIRECT_PKT_R2,
62 BPF_LDX_MEM(BPF_DW, BPF_REG_7, BPF_REG_2, 0),
64 BPF_JMP_IMM(BPF_JSET, BPF_REG_7, 0x80000000, 1),
65 BPF_EXIT_INSN(),
67 BPF_MOV64_IMM(BPF_REG_0, 2),
68 BPF_EXIT_INSN(),
70 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
71 .result = ACCEPT,
72 .retval = 2,
73 .data = { 1, 0, 0, 0, 0, 0, 0, 1, },
74 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
77 "jset: known const compare",
78 .insns = {
79 BPF_MOV64_IMM(BPF_REG_0, 1),
80 BPF_JMP_IMM(BPF_JSET, BPF_REG_0, 1, 1),
81 BPF_LDX_MEM(BPF_B, BPF_REG_8, BPF_REG_9, 0),
82 BPF_EXIT_INSN(),
84 .prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
85 .retval_unpriv = 1,
86 .result_unpriv = ACCEPT,
87 .retval = 1,
88 .result = ACCEPT,
91 "jset: known const compare bad",
92 .insns = {
93 BPF_MOV64_IMM(BPF_REG_0, 0),
94 BPF_JMP_IMM(BPF_JSET, BPF_REG_0, 1, 1),
95 BPF_LDX_MEM(BPF_B, BPF_REG_8, BPF_REG_9, 0),
96 BPF_EXIT_INSN(),
98 .prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
99 .errstr_unpriv = "!read_ok",
100 .result_unpriv = REJECT,
101 .errstr = "!read_ok",
102 .result = REJECT,
105 "jset: unknown const compare taken",
106 .insns = {
107 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_get_prandom_u32),
108 BPF_JMP_IMM(BPF_JSET, BPF_REG_0, 1, 1),
109 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
110 BPF_LDX_MEM(BPF_B, BPF_REG_8, BPF_REG_9, 0),
111 BPF_EXIT_INSN(),
113 .prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
114 .errstr_unpriv = "!read_ok",
115 .result_unpriv = REJECT,
116 .errstr = "!read_ok",
117 .result = REJECT,
120 "jset: unknown const compare not taken",
121 .insns = {
122 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_get_prandom_u32),
123 BPF_JMP_IMM(BPF_JSET, BPF_REG_0, 1, 1),
124 BPF_LDX_MEM(BPF_B, BPF_REG_8, BPF_REG_9, 0),
125 BPF_EXIT_INSN(),
127 .prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
128 .errstr_unpriv = "!read_ok",
129 .result_unpriv = REJECT,
130 .errstr = "!read_ok",
131 .result = REJECT,
134 "jset: half-known const compare",
135 .insns = {
136 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_get_prandom_u32),
137 BPF_ALU64_IMM(BPF_OR, BPF_REG_0, 2),
138 BPF_JMP_IMM(BPF_JSET, BPF_REG_0, 3, 1),
139 BPF_LDX_MEM(BPF_B, BPF_REG_8, BPF_REG_9, 0),
140 BPF_MOV64_IMM(BPF_REG_0, 0),
141 BPF_EXIT_INSN(),
143 .prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
144 .result_unpriv = ACCEPT,
145 .result = ACCEPT,
148 "jset: range",
149 .insns = {
150 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_get_prandom_u32),
151 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
152 BPF_MOV64_IMM(BPF_REG_0, 0),
153 BPF_ALU64_IMM(BPF_AND, BPF_REG_1, 0xff),
154 BPF_JMP_IMM(BPF_JSET, BPF_REG_1, 0xf0, 3),
155 BPF_JMP_IMM(BPF_JLT, BPF_REG_1, 0x10, 1),
156 BPF_LDX_MEM(BPF_B, BPF_REG_8, BPF_REG_9, 0),
157 BPF_EXIT_INSN(),
158 BPF_JMP_IMM(BPF_JSET, BPF_REG_1, 0x10, 1),
159 BPF_EXIT_INSN(),
160 BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0x10, 1),
161 BPF_LDX_MEM(BPF_B, BPF_REG_8, BPF_REG_9, 0),
162 BPF_EXIT_INSN(),
164 .prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
165 .result_unpriv = ACCEPT,
166 .result = ACCEPT,