diff options
| author | Edward Cree <ecree@solarflare.com> | 2017-07-20 18:00:24 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2017-07-20 18:20:27 -0400 |
| commit | b712296a41ce0a114895fdff68fc22aada165b07 (patch) | |
| tree | 388161638f63429c33566ff41b6ef3b5d9f3179a /tools | |
| parent | a1502132866fd2d2705eef4041dd6d7d849f48a2 (diff) | |
bpf: add test for mixed signed and unsigned bounds checks
These failed due to a bug in verifier bounds handling.
Signed-off-by: Edward Cree <ecree@solarflare.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/testing/selftests/bpf/test_verifier.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index 64b39d37d91d..48b7997c0ae7 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c | |||
| @@ -5510,6 +5510,58 @@ static struct bpf_test tests[] = { | |||
| 5510 | .errstr = "invalid bpf_context access", | 5510 | .errstr = "invalid bpf_context access", |
| 5511 | .prog_type = BPF_PROG_TYPE_LWT_IN, | 5511 | .prog_type = BPF_PROG_TYPE_LWT_IN, |
| 5512 | }, | 5512 | }, |
| 5513 | { | ||
| 5514 | "bounds checks mixing signed and unsigned, positive bounds", | ||
| 5515 | .insns = { | ||
| 5516 | BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0), | ||
| 5517 | BPF_MOV64_REG(BPF_REG_2, BPF_REG_10), | ||
| 5518 | BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8), | ||
| 5519 | BPF_LD_MAP_FD(BPF_REG_1, 0), | ||
| 5520 | BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, | ||
| 5521 | BPF_FUNC_map_lookup_elem), | ||
| 5522 | BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7), | ||
| 5523 | BPF_ST_MEM(BPF_DW, BPF_REG_10, -16, -8), | ||
| 5524 | BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_10, -16), | ||
| 5525 | BPF_MOV64_IMM(BPF_REG_2, 2), | ||
| 5526 | BPF_JMP_REG(BPF_JGE, BPF_REG_2, BPF_REG_1, 3), | ||
| 5527 | BPF_JMP_IMM(BPF_JSGT, BPF_REG_1, 4, 2), | ||
| 5528 | BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1), | ||
| 5529 | BPF_ST_MEM(BPF_B, BPF_REG_0, 0, 0), | ||
| 5530 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
| 5531 | BPF_EXIT_INSN(), | ||
| 5532 | }, | ||
| 5533 | .fixup_map1 = { 3 }, | ||
| 5534 | .errstr_unpriv = "R0 pointer arithmetic prohibited", | ||
| 5535 | .errstr = "R0 min value is negative", | ||
| 5536 | .result = REJECT, | ||
| 5537 | .result_unpriv = REJECT, | ||
| 5538 | }, | ||
| 5539 | { | ||
| 5540 | "bounds checks mixing signed and unsigned", | ||
| 5541 | .insns = { | ||
| 5542 | BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0), | ||
| 5543 | BPF_MOV64_REG(BPF_REG_2, BPF_REG_10), | ||
| 5544 | BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8), | ||
| 5545 | BPF_LD_MAP_FD(BPF_REG_1, 0), | ||
| 5546 | BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, | ||
| 5547 | BPF_FUNC_map_lookup_elem), | ||
| 5548 | BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7), | ||
| 5549 | BPF_ST_MEM(BPF_DW, BPF_REG_10, -16, -8), | ||
| 5550 | BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_10, -16), | ||
| 5551 | BPF_MOV64_IMM(BPF_REG_2, -1), | ||
| 5552 | BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_2, 3), | ||
| 5553 | BPF_JMP_IMM(BPF_JSGT, BPF_REG_1, 1, 2), | ||
| 5554 | BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1), | ||
| 5555 | BPF_ST_MEM(BPF_B, BPF_REG_0, 0, 0), | ||
| 5556 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
| 5557 | BPF_EXIT_INSN(), | ||
| 5558 | }, | ||
| 5559 | .fixup_map1 = { 3 }, | ||
| 5560 | .errstr_unpriv = "R0 pointer arithmetic prohibited", | ||
| 5561 | .errstr = "R0 min value is negative", | ||
| 5562 | .result = REJECT, | ||
| 5563 | .result_unpriv = REJECT, | ||
| 5564 | }, | ||
| 5513 | }; | 5565 | }; |
| 5514 | 5566 | ||
| 5515 | static int probe_filter_length(const struct bpf_insn *fp) | 5567 | static int probe_filter_length(const struct bpf_insn *fp) |
