Skip to content

Commit be08815

Browse files
borkmannAlexei Starovoitov
authored andcommitted
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>
1 parent 06be086 commit be08815

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

lib/test_bpf.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,52 @@ static int bpf_fill_maxinsns11(struct bpf_test *self)
356356
return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
357357
}
358358

359+
static 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+
382+
static 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+
359405
static int bpf_fill_ja(struct bpf_test *self)
360406
{
361407
/* Hits exactly 11 passes on x86_64 JIT. */
@@ -5289,6 +5335,23 @@ static struct bpf_test tests[] = {
52895335
.fill_helper = bpf_fill_maxinsns11,
52905336
.expected_errcode = -ENOTSUPP,
52915337
},
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+
},
52925355
{
52935356
"BPF_MAXINSNS: ld_abs+get_processor_id",
52945357
{ },

0 commit comments

Comments
 (0)