aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2018-01-19 19:24:32 -0500
committerAlexei Starovoitov <ast@kernel.org>2018-01-19 21:37:00 -0500
commit87c1793b1b7f34915e9e64cdb503efb281c769a7 (patch)
treec9abdd574414dbb1e54c712a3d95340058ea6998 /tools
parentfcd1c9177195489c40198d2769649439dd88505b (diff)
bpf: add couple of test cases for div/mod by zero
Add couple of missing test cases for eBPF div/mod by zero to the new test_verifier prog runtime feature. Also one for an empty prog and only exit. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/bpf/test_verifier.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 6c22edb1f006..efca10de64e9 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -102,6 +102,93 @@ static struct bpf_test tests[] = {
102 .retval = -3, 102 .retval = -3,
103 }, 103 },
104 { 104 {
105 "DIV32 by 0, zero check 1",
106 .insns = {
107 BPF_MOV32_IMM(BPF_REG_0, 42),
108 BPF_MOV32_IMM(BPF_REG_1, 0),
109 BPF_MOV32_IMM(BPF_REG_2, 1),
110 BPF_ALU32_REG(BPF_DIV, BPF_REG_2, BPF_REG_1),
111 BPF_EXIT_INSN(),
112 },
113 .result = ACCEPT,
114 .retval = 0,
115 },
116 {
117 "DIV32 by 0, zero check 2",
118 .insns = {
119 BPF_MOV32_IMM(BPF_REG_0, 42),
120 BPF_LD_IMM64(BPF_REG_1, 0xffffffff00000000LL),
121 BPF_MOV32_IMM(BPF_REG_2, 1),
122 BPF_ALU32_REG(BPF_DIV, BPF_REG_2, BPF_REG_1),
123 BPF_EXIT_INSN(),
124 },
125 .result = ACCEPT,
126 .retval = 0,
127 },
128 {
129 "DIV64 by 0, zero check",
130 .insns = {
131 BPF_MOV32_IMM(BPF_REG_0, 42),
132 BPF_MOV32_IMM(BPF_REG_1, 0),
133 BPF_MOV32_IMM(BPF_REG_2, 1),
134 BPF_ALU64_REG(BPF_DIV, BPF_REG_2, BPF_REG_1),
135 BPF_EXIT_INSN(),
136 },
137 .result = ACCEPT,
138 .retval = 0,
139 },
140 {
141 "MOD32 by 0, zero check 1",
142 .insns = {
143 BPF_MOV32_IMM(BPF_REG_0, 42),
144 BPF_MOV32_IMM(BPF_REG_1, 0),
145 BPF_MOV32_IMM(BPF_REG_2, 1),
146 BPF_ALU32_REG(BPF_MOD, BPF_REG_2, BPF_REG_1),
147 BPF_EXIT_INSN(),
148 },
149 .result = ACCEPT,
150 .retval = 0,
151 },
152 {
153 "MOD32 by 0, zero check 2",
154 .insns = {
155 BPF_MOV32_IMM(BPF_REG_0, 42),
156 BPF_LD_IMM64(BPF_REG_1, 0xffffffff00000000LL),
157 BPF_MOV32_IMM(BPF_REG_2, 1),
158 BPF_ALU32_REG(BPF_MOD, BPF_REG_2, BPF_REG_1),
159 BPF_EXIT_INSN(),
160 },
161 .result = ACCEPT,
162 .retval = 0,
163 },
164 {
165 "MOD64 by 0, zero check",
166 .insns = {
167 BPF_MOV32_IMM(BPF_REG_0, 42),
168 BPF_MOV32_IMM(BPF_REG_1, 0),
169 BPF_MOV32_IMM(BPF_REG_2, 1),
170 BPF_ALU64_REG(BPF_MOD, BPF_REG_2, BPF_REG_1),
171 BPF_EXIT_INSN(),
172 },
173 .result = ACCEPT,
174 .retval = 0,
175 },
176 {
177 "empty prog",
178 .insns = {
179 },
180 .errstr = "last insn is not an exit or jmp",
181 .result = REJECT,
182 },
183 {
184 "only exit insn",
185 .insns = {
186 BPF_EXIT_INSN(),
187 },
188 .errstr = "R0 !read_ok",
189 .result = REJECT,
190 },
191 {
105 "unreachable", 192 "unreachable",
106 .insns = { 193 .insns = {
107 BPF_EXIT_INSN(), 194 BPF_EXIT_INSN(),