Skip to content

Commit 105c036

Browse files
4astdavem330
authored andcommitted
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: Alexei Starovoitov <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 50bbfed commit 105c036

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

lib/test_bpf.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct bpf_test {
8484
} test[MAX_SUBTESTS];
8585
int (*fill_helper)(struct bpf_test *self);
8686
__u8 frag_data[MAX_DATA];
87+
int stack_depth; /* for eBPF only, since tests don't call verifier */
8788
};
8889

8990
/* Large test cases need separate allocation and fill handler. */
@@ -455,6 +456,7 @@ static int __bpf_fill_stxdw(struct bpf_test *self, int size)
455456

456457
self->u.ptr.insns = insn;
457458
self->u.ptr.len = len;
459+
self->stack_depth = 40;
458460

459461
return 0;
460462
}
@@ -2317,7 +2319,8 @@ static struct bpf_test tests[] = {
23172319
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
23182320
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23192321
0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
2320-
{ { 38, 256 } }
2322+
{ { 38, 256 } },
2323+
.stack_depth = 64,
23212324
},
23222325
/* BPF_ALU | BPF_MOV | BPF_X */
23232326
{
@@ -4169,6 +4172,7 @@ static struct bpf_test tests[] = {
41694172
INTERNAL,
41704173
{ },
41714174
{ { 0, 0xff } },
4175+
.stack_depth = 40,
41724176
},
41734177
{
41744178
"ST_MEM_B: Store/Load byte: max positive",
@@ -4181,6 +4185,7 @@ static struct bpf_test tests[] = {
41814185
INTERNAL,
41824186
{ },
41834187
{ { 0, 0x7f } },
4188+
.stack_depth = 40,
41844189
},
41854190
{
41864191
"STX_MEM_B: Store/Load byte: max negative",
@@ -4194,6 +4199,7 @@ static struct bpf_test tests[] = {
41944199
INTERNAL,
41954200
{ },
41964201
{ { 0, 0xff } },
4202+
.stack_depth = 40,
41974203
},
41984204
{
41994205
"ST_MEM_H: Store/Load half word: max negative",
@@ -4206,6 +4212,7 @@ static struct bpf_test tests[] = {
42064212
INTERNAL,
42074213
{ },
42084214
{ { 0, 0xffff } },
4215+
.stack_depth = 40,
42094216
},
42104217
{
42114218
"ST_MEM_H: Store/Load half word: max positive",
@@ -4218,6 +4225,7 @@ static struct bpf_test tests[] = {
42184225
INTERNAL,
42194226
{ },
42204227
{ { 0, 0x7fff } },
4228+
.stack_depth = 40,
42214229
},
42224230
{
42234231
"STX_MEM_H: Store/Load half word: max negative",
@@ -4231,6 +4239,7 @@ static struct bpf_test tests[] = {
42314239
INTERNAL,
42324240
{ },
42334241
{ { 0, 0xffff } },
4242+
.stack_depth = 40,
42344243
},
42354244
{
42364245
"ST_MEM_W: Store/Load word: max negative",
@@ -4243,6 +4252,7 @@ static struct bpf_test tests[] = {
42434252
INTERNAL,
42444253
{ },
42454254
{ { 0, 0xffffffff } },
4255+
.stack_depth = 40,
42464256
},
42474257
{
42484258
"ST_MEM_W: Store/Load word: max positive",
@@ -4255,6 +4265,7 @@ static struct bpf_test tests[] = {
42554265
INTERNAL,
42564266
{ },
42574267
{ { 0, 0x7fffffff } },
4268+
.stack_depth = 40,
42584269
},
42594270
{
42604271
"STX_MEM_W: Store/Load word: max negative",
@@ -4268,6 +4279,7 @@ static struct bpf_test tests[] = {
42684279
INTERNAL,
42694280
{ },
42704281
{ { 0, 0xffffffff } },
4282+
.stack_depth = 40,
42714283
},
42724284
{
42734285
"ST_MEM_DW: Store/Load double word: max negative",
@@ -4280,6 +4292,7 @@ static struct bpf_test tests[] = {
42804292
INTERNAL,
42814293
{ },
42824294
{ { 0, 0xffffffff } },
4295+
.stack_depth = 40,
42834296
},
42844297
{
42854298
"ST_MEM_DW: Store/Load double word: max negative 2",
@@ -4297,6 +4310,7 @@ static struct bpf_test tests[] = {
42974310
INTERNAL,
42984311
{ },
42994312
{ { 0, 0x1 } },
4313+
.stack_depth = 40,
43004314
},
43014315
{
43024316
"ST_MEM_DW: Store/Load double word: max positive",
@@ -4309,6 +4323,7 @@ static struct bpf_test tests[] = {
43094323
INTERNAL,
43104324
{ },
43114325
{ { 0, 0x7fffffff } },
4326+
.stack_depth = 40,
43124327
},
43134328
{
43144329
"STX_MEM_DW: Store/Load double word: max negative",
@@ -4322,6 +4337,7 @@ static struct bpf_test tests[] = {
43224337
INTERNAL,
43234338
{ },
43244339
{ { 0, 0xffffffff } },
4340+
.stack_depth = 40,
43254341
},
43264342
/* BPF_STX | BPF_XADD | BPF_W/DW */
43274343
{
@@ -4336,6 +4352,7 @@ static struct bpf_test tests[] = {
43364352
INTERNAL,
43374353
{ },
43384354
{ { 0, 0x22 } },
4355+
.stack_depth = 40,
43394356
},
43404357
{
43414358
"STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
@@ -4351,6 +4368,7 @@ static struct bpf_test tests[] = {
43514368
INTERNAL,
43524369
{ },
43534370
{ { 0, 0 } },
4371+
.stack_depth = 40,
43544372
},
43554373
{
43564374
"STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
@@ -4363,6 +4381,7 @@ static struct bpf_test tests[] = {
43634381
INTERNAL,
43644382
{ },
43654383
{ { 0, 0x12 } },
4384+
.stack_depth = 40,
43664385
},
43674386
{
43684387
"STX_XADD_W: X + 1 + 1 + 1 + ...",
@@ -4384,6 +4403,7 @@ static struct bpf_test tests[] = {
43844403
INTERNAL,
43854404
{ },
43864405
{ { 0, 0x22 } },
4406+
.stack_depth = 40,
43874407
},
43884408
{
43894409
"STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
@@ -4399,6 +4419,7 @@ static struct bpf_test tests[] = {
43994419
INTERNAL,
44004420
{ },
44014421
{ { 0, 0 } },
4422+
.stack_depth = 40,
44024423
},
44034424
{
44044425
"STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
@@ -4411,6 +4432,7 @@ static struct bpf_test tests[] = {
44114432
INTERNAL,
44124433
{ },
44134434
{ { 0, 0x12 } },
4435+
.stack_depth = 40,
44144436
},
44154437
{
44164438
"STX_XADD_DW: X + 1 + 1 + 1 + ...",
@@ -5809,6 +5831,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
58095831
/* Type doesn't really matter here as long as it's not unspec. */
58105832
fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
58115833
memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
5834+
fp->aux->stack_depth = tests[which].stack_depth;
58125835

58135836
/* We cannot error here as we don't need type compatibility
58145837
* checks.

0 commit comments

Comments
 (0)