Commit 105c0361 authored by Alexei Starovoitov's avatar Alexei Starovoitov Committed by David S. Miller

bpf: fix stack_depth usage by test_bpf.ko

test_bpf.ko doesn't call verifier before selecting interpreter or JITing,
hence the tests need to manually specify the amount of stack they consume.
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 50bbfed9
...@@ -84,6 +84,7 @@ struct bpf_test { ...@@ -84,6 +84,7 @@ struct bpf_test {
} test[MAX_SUBTESTS]; } test[MAX_SUBTESTS];
int (*fill_helper)(struct bpf_test *self); int (*fill_helper)(struct bpf_test *self);
__u8 frag_data[MAX_DATA]; __u8 frag_data[MAX_DATA];
int stack_depth; /* for eBPF only, since tests don't call verifier */
}; };
/* Large test cases need separate allocation and fill handler. */ /* Large test cases need separate allocation and fill handler. */
...@@ -455,6 +456,7 @@ static int __bpf_fill_stxdw(struct bpf_test *self, int size) ...@@ -455,6 +456,7 @@ static int __bpf_fill_stxdw(struct bpf_test *self, int size)
self->u.ptr.insns = insn; self->u.ptr.insns = insn;
self->u.ptr.len = len; self->u.ptr.len = len;
self->stack_depth = 40;
return 0; return 0;
} }
...@@ -2317,7 +2319,8 @@ static struct bpf_test tests[] = { ...@@ -2317,7 +2319,8 @@ static struct bpf_test tests[] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6}, 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
{ { 38, 256 } } { { 38, 256 } },
.stack_depth = 64,
}, },
/* BPF_ALU | BPF_MOV | BPF_X */ /* BPF_ALU | BPF_MOV | BPF_X */
{ {
...@@ -4169,6 +4172,7 @@ static struct bpf_test tests[] = { ...@@ -4169,6 +4172,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0xff } }, { { 0, 0xff } },
.stack_depth = 40,
}, },
{ {
"ST_MEM_B: Store/Load byte: max positive", "ST_MEM_B: Store/Load byte: max positive",
...@@ -4181,6 +4185,7 @@ static struct bpf_test tests[] = { ...@@ -4181,6 +4185,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0x7f } }, { { 0, 0x7f } },
.stack_depth = 40,
}, },
{ {
"STX_MEM_B: Store/Load byte: max negative", "STX_MEM_B: Store/Load byte: max negative",
...@@ -4194,6 +4199,7 @@ static struct bpf_test tests[] = { ...@@ -4194,6 +4199,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0xff } }, { { 0, 0xff } },
.stack_depth = 40,
}, },
{ {
"ST_MEM_H: Store/Load half word: max negative", "ST_MEM_H: Store/Load half word: max negative",
...@@ -4206,6 +4212,7 @@ static struct bpf_test tests[] = { ...@@ -4206,6 +4212,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0xffff } }, { { 0, 0xffff } },
.stack_depth = 40,
}, },
{ {
"ST_MEM_H: Store/Load half word: max positive", "ST_MEM_H: Store/Load half word: max positive",
...@@ -4218,6 +4225,7 @@ static struct bpf_test tests[] = { ...@@ -4218,6 +4225,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0x7fff } }, { { 0, 0x7fff } },
.stack_depth = 40,
}, },
{ {
"STX_MEM_H: Store/Load half word: max negative", "STX_MEM_H: Store/Load half word: max negative",
...@@ -4231,6 +4239,7 @@ static struct bpf_test tests[] = { ...@@ -4231,6 +4239,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0xffff } }, { { 0, 0xffff } },
.stack_depth = 40,
}, },
{ {
"ST_MEM_W: Store/Load word: max negative", "ST_MEM_W: Store/Load word: max negative",
...@@ -4243,6 +4252,7 @@ static struct bpf_test tests[] = { ...@@ -4243,6 +4252,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0xffffffff } }, { { 0, 0xffffffff } },
.stack_depth = 40,
}, },
{ {
"ST_MEM_W: Store/Load word: max positive", "ST_MEM_W: Store/Load word: max positive",
...@@ -4255,6 +4265,7 @@ static struct bpf_test tests[] = { ...@@ -4255,6 +4265,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0x7fffffff } }, { { 0, 0x7fffffff } },
.stack_depth = 40,
}, },
{ {
"STX_MEM_W: Store/Load word: max negative", "STX_MEM_W: Store/Load word: max negative",
...@@ -4268,6 +4279,7 @@ static struct bpf_test tests[] = { ...@@ -4268,6 +4279,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0xffffffff } }, { { 0, 0xffffffff } },
.stack_depth = 40,
}, },
{ {
"ST_MEM_DW: Store/Load double word: max negative", "ST_MEM_DW: Store/Load double word: max negative",
...@@ -4280,6 +4292,7 @@ static struct bpf_test tests[] = { ...@@ -4280,6 +4292,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0xffffffff } }, { { 0, 0xffffffff } },
.stack_depth = 40,
}, },
{ {
"ST_MEM_DW: Store/Load double word: max negative 2", "ST_MEM_DW: Store/Load double word: max negative 2",
...@@ -4297,6 +4310,7 @@ static struct bpf_test tests[] = { ...@@ -4297,6 +4310,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0x1 } }, { { 0, 0x1 } },
.stack_depth = 40,
}, },
{ {
"ST_MEM_DW: Store/Load double word: max positive", "ST_MEM_DW: Store/Load double word: max positive",
...@@ -4309,6 +4323,7 @@ static struct bpf_test tests[] = { ...@@ -4309,6 +4323,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0x7fffffff } }, { { 0, 0x7fffffff } },
.stack_depth = 40,
}, },
{ {
"STX_MEM_DW: Store/Load double word: max negative", "STX_MEM_DW: Store/Load double word: max negative",
...@@ -4322,6 +4337,7 @@ static struct bpf_test tests[] = { ...@@ -4322,6 +4337,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0xffffffff } }, { { 0, 0xffffffff } },
.stack_depth = 40,
}, },
/* BPF_STX | BPF_XADD | BPF_W/DW */ /* BPF_STX | BPF_XADD | BPF_W/DW */
{ {
...@@ -4336,6 +4352,7 @@ static struct bpf_test tests[] = { ...@@ -4336,6 +4352,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0x22 } }, { { 0, 0x22 } },
.stack_depth = 40,
}, },
{ {
"STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22", "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
...@@ -4351,6 +4368,7 @@ static struct bpf_test tests[] = { ...@@ -4351,6 +4368,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0 } }, { { 0, 0 } },
.stack_depth = 40,
}, },
{ {
"STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22", "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
...@@ -4363,6 +4381,7 @@ static struct bpf_test tests[] = { ...@@ -4363,6 +4381,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0x12 } }, { { 0, 0x12 } },
.stack_depth = 40,
}, },
{ {
"STX_XADD_W: X + 1 + 1 + 1 + ...", "STX_XADD_W: X + 1 + 1 + 1 + ...",
...@@ -4384,6 +4403,7 @@ static struct bpf_test tests[] = { ...@@ -4384,6 +4403,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0x22 } }, { { 0, 0x22 } },
.stack_depth = 40,
}, },
{ {
"STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22", "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
...@@ -4399,6 +4419,7 @@ static struct bpf_test tests[] = { ...@@ -4399,6 +4419,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0 } }, { { 0, 0 } },
.stack_depth = 40,
}, },
{ {
"STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22", "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
...@@ -4411,6 +4432,7 @@ static struct bpf_test tests[] = { ...@@ -4411,6 +4432,7 @@ static struct bpf_test tests[] = {
INTERNAL, INTERNAL,
{ }, { },
{ { 0, 0x12 } }, { { 0, 0x12 } },
.stack_depth = 40,
}, },
{ {
"STX_XADD_DW: X + 1 + 1 + 1 + ...", "STX_XADD_DW: X + 1 + 1 + 1 + ...",
...@@ -5809,6 +5831,7 @@ static struct bpf_prog *generate_filter(int which, int *err) ...@@ -5809,6 +5831,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
/* Type doesn't really matter here as long as it's not unspec. */ /* Type doesn't really matter here as long as it's not unspec. */
fp->type = BPF_PROG_TYPE_SOCKET_FILTER; fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn)); memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
fp->aux->stack_depth = tests[which].stack_depth;
/* We cannot error here as we don't need type compatibility /* We cannot error here as we don't need type compatibility
* checks. * checks.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment