xref: /openbmc/linux/tools/testing/selftests/bpf/verifier/precise.c (revision 411cdb4569013cc1089c00b2cd279033d6278f61)
1e8c13c4dSAlexei Starovoitov {
2e8c13c4dSAlexei Starovoitov 	"precise: test 1",
3e8c13c4dSAlexei Starovoitov 	.insns = {
4e8c13c4dSAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_0, 1),
5e8c13c4dSAlexei Starovoitov 	BPF_LD_MAP_FD(BPF_REG_6, 0),
6e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
7e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_FP),
8e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
9e8c13c4dSAlexei Starovoitov 	BPF_ST_MEM(BPF_DW, BPF_REG_FP, -8, 0),
10e8c13c4dSAlexei Starovoitov 	BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
11e8c13c4dSAlexei Starovoitov 	BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
12e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
13e8c13c4dSAlexei Starovoitov 
14e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_9, BPF_REG_0),
15e8c13c4dSAlexei Starovoitov 
16e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
17e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_FP),
18e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
19e8c13c4dSAlexei Starovoitov 	BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
20e8c13c4dSAlexei Starovoitov 	BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
21e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
22e8c13c4dSAlexei Starovoitov 
23e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_8, BPF_REG_0),
24e8c13c4dSAlexei Starovoitov 
25e8c13c4dSAlexei Starovoitov 	BPF_ALU64_REG(BPF_SUB, BPF_REG_9, BPF_REG_8), /* map_value_ptr -= map_value_ptr */
26e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_9),
27e8c13c4dSAlexei Starovoitov 	BPF_JMP_IMM(BPF_JLT, BPF_REG_2, 8, 1),
28e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
29e8c13c4dSAlexei Starovoitov 
30e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1), /* R2=inv(umin=1, umax=8) */
31e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_FP),
32e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8),
33e8c13c4dSAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_3, 0),
34e8c13c4dSAlexei Starovoitov 	BPF_EMIT_CALL(BPF_FUNC_probe_read),
35e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
36e8c13c4dSAlexei Starovoitov 	},
37e8c13c4dSAlexei Starovoitov 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
38e8c13c4dSAlexei Starovoitov 	.fixup_map_array_48b = { 1 },
39e8c13c4dSAlexei Starovoitov 	.result = VERBOSE_ACCEPT,
40e8c13c4dSAlexei Starovoitov 	.errstr =
41e8c13c4dSAlexei Starovoitov 	"26: (85) call bpf_probe_read#4\
42e8c13c4dSAlexei Starovoitov 	last_idx 26 first_idx 20\
43e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 25\
44e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 24\
45e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 23\
46e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 22\
47e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 20\
48e8c13c4dSAlexei Starovoitov 	parent didn't have regs=4 stack=0 marks\
49e8c13c4dSAlexei Starovoitov 	last_idx 19 first_idx 10\
50e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 19\
51e8c13c4dSAlexei Starovoitov 	regs=200 stack=0 before 18\
52e8c13c4dSAlexei Starovoitov 	regs=300 stack=0 before 17\
53e8c13c4dSAlexei Starovoitov 	regs=201 stack=0 before 15\
54e8c13c4dSAlexei Starovoitov 	regs=201 stack=0 before 14\
55e8c13c4dSAlexei Starovoitov 	regs=200 stack=0 before 13\
56e8c13c4dSAlexei Starovoitov 	regs=200 stack=0 before 12\
57e8c13c4dSAlexei Starovoitov 	regs=200 stack=0 before 11\
58e8c13c4dSAlexei Starovoitov 	regs=200 stack=0 before 10\
59e8c13c4dSAlexei Starovoitov 	parent already had regs=0 stack=0 marks",
60e8c13c4dSAlexei Starovoitov },
61e8c13c4dSAlexei Starovoitov {
62e8c13c4dSAlexei Starovoitov 	"precise: test 2",
63e8c13c4dSAlexei Starovoitov 	.insns = {
64e8c13c4dSAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_0, 1),
65e8c13c4dSAlexei Starovoitov 	BPF_LD_MAP_FD(BPF_REG_6, 0),
66e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
67e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_FP),
68e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
69e8c13c4dSAlexei Starovoitov 	BPF_ST_MEM(BPF_DW, BPF_REG_FP, -8, 0),
70e8c13c4dSAlexei Starovoitov 	BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
71e8c13c4dSAlexei Starovoitov 	BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
72e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
73e8c13c4dSAlexei Starovoitov 
74e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_9, BPF_REG_0),
75e8c13c4dSAlexei Starovoitov 
76e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
77e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_FP),
78e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
79e8c13c4dSAlexei Starovoitov 	BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
80e8c13c4dSAlexei Starovoitov 	BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
81e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
82e8c13c4dSAlexei Starovoitov 
83e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_8, BPF_REG_0),
84e8c13c4dSAlexei Starovoitov 
85e8c13c4dSAlexei Starovoitov 	BPF_ALU64_REG(BPF_SUB, BPF_REG_9, BPF_REG_8), /* map_value_ptr -= map_value_ptr */
86e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_9),
87e8c13c4dSAlexei Starovoitov 	BPF_JMP_IMM(BPF_JLT, BPF_REG_2, 8, 1),
88e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
89e8c13c4dSAlexei Starovoitov 
90e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1), /* R2=inv(umin=1, umax=8) */
91e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_FP),
92e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8),
93e8c13c4dSAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_3, 0),
94e8c13c4dSAlexei Starovoitov 	BPF_EMIT_CALL(BPF_FUNC_probe_read),
95e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
96e8c13c4dSAlexei Starovoitov 	},
97e8c13c4dSAlexei Starovoitov 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
98e8c13c4dSAlexei Starovoitov 	.fixup_map_array_48b = { 1 },
99e8c13c4dSAlexei Starovoitov 	.result = VERBOSE_ACCEPT,
100e8c13c4dSAlexei Starovoitov 	.flags = BPF_F_TEST_STATE_FREQ,
101e8c13c4dSAlexei Starovoitov 	.errstr =
102e8c13c4dSAlexei Starovoitov 	"26: (85) call bpf_probe_read#4\
103e8c13c4dSAlexei Starovoitov 	last_idx 26 first_idx 22\
104e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 25\
105e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 24\
106e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 23\
107e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 22\
108e8c13c4dSAlexei Starovoitov 	parent didn't have regs=4 stack=0 marks\
109e8c13c4dSAlexei Starovoitov 	last_idx 20 first_idx 20\
110e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 20\
111e8c13c4dSAlexei Starovoitov 	parent didn't have regs=4 stack=0 marks\
112e8c13c4dSAlexei Starovoitov 	last_idx 19 first_idx 17\
113e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 19\
114e8c13c4dSAlexei Starovoitov 	regs=200 stack=0 before 18\
115e8c13c4dSAlexei Starovoitov 	regs=300 stack=0 before 17\
116e8c13c4dSAlexei Starovoitov 	parent already had regs=0 stack=0 marks",
117e8c13c4dSAlexei Starovoitov },
118*411cdb45SAlexei Starovoitov {
119*411cdb45SAlexei Starovoitov 	"precise: cross frame pruning",
120*411cdb45SAlexei Starovoitov 	.insns = {
121*411cdb45SAlexei Starovoitov 	BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_get_prandom_u32),
122*411cdb45SAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_8, 0),
123*411cdb45SAlexei Starovoitov 	BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
124*411cdb45SAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_8, 1),
125*411cdb45SAlexei Starovoitov 	BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_get_prandom_u32),
126*411cdb45SAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_9, 0),
127*411cdb45SAlexei Starovoitov 	BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
128*411cdb45SAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_9, 1),
129*411cdb45SAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
130*411cdb45SAlexei Starovoitov 	BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 4),
131*411cdb45SAlexei Starovoitov 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_8, 1, 1),
132*411cdb45SAlexei Starovoitov 	BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_2, 0),
133*411cdb45SAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_0, 0),
134*411cdb45SAlexei Starovoitov 	BPF_EXIT_INSN(),
135*411cdb45SAlexei Starovoitov 	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 0),
136*411cdb45SAlexei Starovoitov 	BPF_EXIT_INSN(),
137*411cdb45SAlexei Starovoitov 	},
138*411cdb45SAlexei Starovoitov 	.prog_type = BPF_PROG_TYPE_XDP,
139*411cdb45SAlexei Starovoitov 	.flags = BPF_F_TEST_STATE_FREQ,
140*411cdb45SAlexei Starovoitov 	.errstr = "!read_ok",
141*411cdb45SAlexei Starovoitov 	.result = REJECT,
142*411cdb45SAlexei Starovoitov },
143