summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/verifier/ld_imm64.c
blob: 78f19c255f20b466d4f022029217da87260a4800 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{
	"test1 ld_imm64",
	.insns = {
	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 1),
	BPF_LD_IMM64(BPF_REG_0, 0),
	BPF_LD_IMM64(BPF_REG_0, 0),
	BPF_LD_IMM64(BPF_REG_0, 1),
	BPF_LD_IMM64(BPF_REG_0, 1),
	BPF_MOV64_IMM(BPF_REG_0, 2),
	BPF_EXIT_INSN(),
	},
	.errstr = "jump into the middle of ldimm64 insn 1",
	.errstr_unpriv = "jump into the middle of ldimm64 insn 1",
	.result = REJECT,
},
{
	"test2 ld_imm64",
	.insns = {
	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 1),
	BPF_LD_IMM64(BPF_REG_0, 0),
	BPF_LD_IMM64(BPF_REG_0, 0),
	BPF_LD_IMM64(BPF_REG_0, 1),
	BPF_LD_IMM64(BPF_REG_0, 1),
	BPF_EXIT_INSN(),
	},
	.errstr = "jump into the middle of ldimm64 insn 1",
	.errstr_unpriv = "jump into the middle of ldimm64 insn 1",
	.result = REJECT,
},
{
	"test3 ld_imm64",
	.insns = {
	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 1),
	BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, 0, 0, 0),
	BPF_LD_IMM64(BPF_REG_0, 0),
	BPF_LD_IMM64(BPF_REG_0, 0),
	BPF_LD_IMM64(BPF_REG_0, 1),
	BPF_LD_IMM64(BPF_REG_0, 1),
	BPF_EXIT_INSN(),
	},
	.errstr = "invalid bpf_ld_imm64 insn",
	.result = REJECT,
},
{
	"test4 ld_imm64",
	.insns = {
	BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, 0, 0, 0),
	BPF_EXIT_INSN(),
	},
	.errstr = "invalid bpf_ld_imm64 insn",
	.result = REJECT,
},
{
	"test6 ld_imm64",
	.insns = {
	BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, 0, 0, 0),
	BPF_RAW_INSN(0, 0, 0, 0, 0),
	BPF_EXIT_INSN(),
	},
	.result = ACCEPT,
},
{
	"test7 ld_imm64",
	.insns = {
	BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, 0, 0, 1),
	BPF_RAW_INSN(0, 0, 0, 0, 1),
	BPF_EXIT_INSN(),
	},
	.result = ACCEPT,
	.retval = 1,
},
{
	"test8 ld_imm64",
	.insns = {
	BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, 0, 1, 1),
	BPF_RAW_INSN(0, 0, 0, 0, 1),
	BPF_EXIT_INSN(),
	},
	.errstr = "uses reserved fields",
	.result = REJECT,
},
{
	"test9 ld_imm64",
	.insns = {
	BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, 0, 0, 1),
	BPF_RAW_INSN(0, 0, 0, 1, 1),
	BPF_EXIT_INSN(),
	},
	.errstr = "invalid bpf_ld_imm64 insn",
	.result = REJECT,
},
{
	"test10 ld_imm64",
	.insns = {
	BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, 0, 0, 1),
	BPF_RAW_INSN(0, BPF_REG_1, 0, 0, 1),
	BPF_EXIT_INSN(),
	},
	.errstr = "invalid bpf_ld_imm64 insn",
	.result = REJECT,
},
{
	"test11 ld_imm64",
	.insns = {
	BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, 0, 0, 1),
	BPF_RAW_INSN(0, 0, BPF_REG_1, 0, 1),
	BPF_EXIT_INSN(),
	},
	.errstr = "invalid bpf_ld_imm64 insn",
	.result = REJECT,
},
{
	"test12 ld_imm64",
	.insns = {
	BPF_MOV64_IMM(BPF_REG_1, 0),
	BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, BPF_REG_1, 0, 1),
	BPF_RAW_INSN(0, 0, 0, 0, 0),
	BPF_EXIT_INSN(),
	},
	.errstr = "not pointing to valid bpf_map",
	.result = REJECT,
},
{
	"test13 ld_imm64",
	.insns = {
	BPF_MOV64_IMM(BPF_REG_1, 0),
	BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, 0, BPF_REG_1, 0, 1),
	BPF_RAW_INSN(0, 0, BPF_REG_1, 0, 1),
	BPF_EXIT_INSN(),
	},
	.errstr = "invalid bpf_ld_imm64 insn",
	.result = REJECT,
},
{
	"test14 ld_imm64: reject 2nd imm != 0",
	.insns = {
	BPF_MOV64_IMM(BPF_REG_0, 0),
	BPF_RAW_INSN(BPF_LD | BPF_IMM | BPF_DW, BPF_REG_1,
		     BPF_PSEUDO_MAP_FD, 0, 0),
	BPF_RAW_INSN(0, 0, 0, 0, 0xfefefe),
	BPF_EXIT_INSN(),
	},
	.fixup_map_hash_48b = { 1 },
	.errstr = "unrecognized bpf_ld_imm64 insn",
	.result = REJECT,
},