summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/verifier/runtime_jit.c
blob: a9a8f620e71cd8b84d74e9142fe9cb959f02d0a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{
	"runtime/jit: tail_call within bounds, prog once",
	.insns = {
	BPF_MOV64_IMM(BPF_REG_3, 0),
	BPF_LD_MAP_FD(BPF_REG_2, 0),
	BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_tail_call),
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_EXIT_INSN(),
	},
	.fixup_prog1 = { 1 },
	.result = ACCEPT,
	.retval = 42,
},
{
	"runtime/jit: tail_call within bounds, prog loop",
	.insns = {
	BPF_MOV64_IMM(BPF_REG_3, 1),
	BPF_LD_MAP_FD(BPF_REG_2, 0),
	BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_tail_call),
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_EXIT_INSN(),
	},
	.fixup_prog1 = { 1 },
	.result = ACCEPT,
	.retval = 41,
},
{
	"runtime/jit: tail_call within bounds, no prog",
	.insns = {
	BPF_MOV64_IMM(BPF_REG_3, 2),
	BPF_LD_MAP_FD(BPF_REG_2, 0),
	BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_tail_call),
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_EXIT_INSN(),
	},
	.fixup_prog1 = { 1 },
	.result = ACCEPT,
	.retval = 1,
},
{
	"runtime/jit: tail_call out of bounds",
	.insns = {
	BPF_MOV64_IMM(BPF_REG_3, 256),
	BPF_LD_MAP_FD(BPF_REG_2, 0),
	BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_tail_call),
	BPF_MOV64_IMM(BPF_REG_0, 2),
	BPF_EXIT_INSN(),
	},
	.fixup_prog1 = { 1 },
	.result = ACCEPT,
	.retval = 2,
},
{
	"runtime/jit: pass negative index to tail_call",
	.insns = {
	BPF_MOV64_IMM(BPF_REG_3, -1),
	BPF_LD_MAP_FD(BPF_REG_2, 0),
	BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_tail_call),
	BPF_MOV64_IMM(BPF_REG_0, 2),
	BPF_EXIT_INSN(),
	},
	.fixup_prog1 = { 1 },
	.result = ACCEPT,
	.retval = 2,
},
{
	"runtime/jit: pass > 32bit index to tail_call",
	.insns = {
	BPF_LD_IMM64(BPF_REG_3, 0x100000000ULL),
	BPF_LD_MAP_FD(BPF_REG_2, 0),
	BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_tail_call),
	BPF_MOV64_IMM(BPF_REG_0, 2),
	BPF_EXIT_INSN(),
	},
	.fixup_prog1 = { 2 },
	.result = ACCEPT,
	.retval = 42,
	/* Verifier rewrite for unpriv skips tail call here. */
	.retval_unpriv = 2,
},