mirror of
https://github.com/torvalds/linux.git
synced 2024-12-27 21:33:00 +00:00
bpf: add tests to verifier testsuite
add 4 extra tests to cover jump verification better Signed-off-by: Alexei Starovoitov <ast@plumgrid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
f1bca824da
commit
fd10c2ef3e
@ -461,6 +461,136 @@ static struct bpf_test tests[] = {
|
||||
.errstr = "R0 invalid mem access",
|
||||
.result = REJECT,
|
||||
},
|
||||
{
|
||||
"jump test 1",
|
||||
.insns = {
|
||||
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
||||
BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -8),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 1),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -8, 0),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 1, 1),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -16, 1),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 2, 1),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -8, 2),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 3, 1),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -16, 3),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 4, 1),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -8, 4),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 5, 1),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -32, 5),
|
||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
||||
BPF_EXIT_INSN(),
|
||||
},
|
||||
.result = ACCEPT,
|
||||
},
|
||||
{
|
||||
"jump test 2",
|
||||
.insns = {
|
||||
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 2),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -8, 0),
|
||||
BPF_JMP_IMM(BPF_JA, 0, 0, 14),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 1, 2),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -16, 0),
|
||||
BPF_JMP_IMM(BPF_JA, 0, 0, 11),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 2, 2),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -32, 0),
|
||||
BPF_JMP_IMM(BPF_JA, 0, 0, 8),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 3, 2),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -40, 0),
|
||||
BPF_JMP_IMM(BPF_JA, 0, 0, 5),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 4, 2),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -48, 0),
|
||||
BPF_JMP_IMM(BPF_JA, 0, 0, 2),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 5, 1),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -56, 0),
|
||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
||||
BPF_EXIT_INSN(),
|
||||
},
|
||||
.result = ACCEPT,
|
||||
},
|
||||
{
|
||||
"jump test 3",
|
||||
.insns = {
|
||||
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 3),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -8, 0),
|
||||
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
||||
BPF_JMP_IMM(BPF_JA, 0, 0, 19),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 1, 3),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -16, 0),
|
||||
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -16),
|
||||
BPF_JMP_IMM(BPF_JA, 0, 0, 15),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 2, 3),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -32, 0),
|
||||
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -32),
|
||||
BPF_JMP_IMM(BPF_JA, 0, 0, 11),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 3, 3),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -40, 0),
|
||||
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -40),
|
||||
BPF_JMP_IMM(BPF_JA, 0, 0, 7),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 4, 3),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -48, 0),
|
||||
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -48),
|
||||
BPF_JMP_IMM(BPF_JA, 0, 0, 3),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 5, 0),
|
||||
BPF_ST_MEM(BPF_DW, BPF_REG_2, -56, 0),
|
||||
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -56),
|
||||
BPF_LD_MAP_FD(BPF_REG_1, 0),
|
||||
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_unspec),
|
||||
BPF_EXIT_INSN(),
|
||||
},
|
||||
.fixup = {24},
|
||||
.result = ACCEPT,
|
||||
},
|
||||
{
|
||||
"jump test 4",
|
||||
.insns = {
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 1),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 2),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 3),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 4),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 0),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 0),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 0),
|
||||
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, BPF_REG_10, 0),
|
||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
||||
BPF_EXIT_INSN(),
|
||||
},
|
||||
.result = ACCEPT,
|
||||
},
|
||||
};
|
||||
|
||||
static int probe_filter_length(struct bpf_insn *fp)
|
||||
|
Loading…
Reference in New Issue
Block a user