summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/verifier/basic_stack.c
blob: f995777dddb3f85080dbaf508ac2ed59cc1ead57 (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
{
	"stack out of bounds",
	.insns = {
	BPF_ST_MEM(BPF_DW, BPF_REG_10, 8, 0),
	BPF_EXIT_INSN(),
	},
	.errstr = "invalid write to stack",
	.result = REJECT,
},
{
	"uninitialized stack1",
	.insns = {
	BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
	BPF_LD_MAP_FD(BPF_REG_1, 0),
	BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
	BPF_EXIT_INSN(),
	},
	.fixup_map_hash_8b = { 2 },
	.errstr = "invalid indirect read from stack",
	.result = REJECT,
},
{
	"uninitialized stack2",
	.insns = {
	BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
	BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_2, -8),
	BPF_EXIT_INSN(),
	},
	.errstr = "invalid read from stack",
	.result = REJECT,
},
{
	"invalid fp arithmetic",
	/* If this gets ever changed, make sure JITs can deal with it. */
	.insns = {
	BPF_MOV64_IMM(BPF_REG_0, 0),
	BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
	BPF_ALU64_IMM(BPF_SUB, BPF_REG_1, 8),
	BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, 0),
	BPF_EXIT_INSN(),
	},
	.errstr = "R1 subtraction from stack pointer",
	.result = REJECT,
},
{
	"non-invalid fp arithmetic",
	.insns = {
	BPF_MOV64_IMM(BPF_REG_0, 0),
	BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
	BPF_EXIT_INSN(),
	},
	.result = ACCEPT,
},
{
	"misaligned read from stack",
	.insns = {
	BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
	BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_2, -4),
	BPF_EXIT_INSN(),
	},
	.errstr = "misaligned stack access",
	.result = REJECT,
},