aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2018-06-02 17:06:32 -0400
committerAlexei Starovoitov <ast@kernel.org>2018-06-03 10:42:06 -0400
commitbe08815c5d3b25e53cd9b53a4d768d5f3d93ba25 (patch)
tree1cb8ae911ce9f566839c92bcad468e7a0a75463a
parent06be0864c77ae6861632a678a6378511a4828d6e (diff)
bpf: add also cbpf long jump test cases with heavy expansion
We have one triggering on eBPF but lets also add a cBPF example to make sure we keep tracking them. Also add anther cBPF test running max number of MSH ops. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r--lib/test_bpf.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index 317f231462d4..60aedc879361 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -356,6 +356,52 @@ static int bpf_fill_maxinsns11(struct bpf_test *self)
356 return __bpf_fill_ja(self, BPF_MAXINSNS, 68); 356 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
357} 357}
358 358
359static int bpf_fill_maxinsns12(struct bpf_test *self)
360{
361 unsigned int len = BPF_MAXINSNS;
362 struct sock_filter *insn;
363 int i = 0;
364
365 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
366 if (!insn)
367 return -ENOMEM;
368
369 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
370
371 for (i = 1; i < len - 1; i++)
372 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
373
374 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
375
376 self->u.ptr.insns = insn;
377 self->u.ptr.len = len;
378
379 return 0;
380}
381
382static int bpf_fill_maxinsns13(struct bpf_test *self)
383{
384 unsigned int len = BPF_MAXINSNS;
385 struct sock_filter *insn;
386 int i = 0;
387
388 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
389 if (!insn)
390 return -ENOMEM;
391
392 for (i = 0; i < len - 3; i++)
393 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
394
395 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_IMM, 0xabababab);
396 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0);
397 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
398
399 self->u.ptr.insns = insn;
400 self->u.ptr.len = len;
401
402 return 0;
403}
404
359static int bpf_fill_ja(struct bpf_test *self) 405static int bpf_fill_ja(struct bpf_test *self)
360{ 406{
361 /* Hits exactly 11 passes on x86_64 JIT. */ 407 /* Hits exactly 11 passes on x86_64 JIT. */
@@ -5290,6 +5336,23 @@ static struct bpf_test tests[] = {
5290 .expected_errcode = -ENOTSUPP, 5336 .expected_errcode = -ENOTSUPP,
5291 }, 5337 },
5292 { 5338 {
5339 "BPF_MAXINSNS: jump over MSH",
5340 { },
5341 CLASSIC | FLAG_EXPECTED_FAIL,
5342 { 0xfa, 0xfb, 0xfc, 0xfd, },
5343 { { 4, 0xabababab } },
5344 .fill_helper = bpf_fill_maxinsns12,
5345 .expected_errcode = -EINVAL,
5346 },
5347 {
5348 "BPF_MAXINSNS: exec all MSH",
5349 { },
5350 CLASSIC,
5351 { 0xfa, 0xfb, 0xfc, 0xfd, },
5352 { { 4, 0xababab83 } },
5353 .fill_helper = bpf_fill_maxinsns13,
5354 },
5355 {
5293 "BPF_MAXINSNS: ld_abs+get_processor_id", 5356 "BPF_MAXINSNS: ld_abs+get_processor_id",
5294 { }, 5357 { },
5295 CLASSIC, 5358 CLASSIC,