summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/verifier_const_or.c
blob: ba8922b2eebd9aace069edc45a46926f009a1a02 (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
// SPDX-License-Identifier: GPL-2.0
/* Converted from tools/testing/selftests/bpf/verifier/const_or.c */

#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

SEC("tracepoint")
__description("constant register |= constant should keep constant type")
__success
__naked void constant_should_keep_constant_type(void)
{
	asm volatile ("					\
	r1 = r10;					\
	r1 += -48;					\
	r2 = 34;					\
	r2 |= 13;					\
	r3 = 0;						\
	call %[bpf_probe_read_kernel];			\
	exit;						\
"	:
	: __imm(bpf_probe_read_kernel)
	: __clobber_all);
}

SEC("tracepoint")
__description("constant register |= constant should not bypass stack boundary checks")
__failure __msg("invalid indirect access to stack R1 off=-48 size=58")
__naked void not_bypass_stack_boundary_checks_1(void)
{
	asm volatile ("					\
	r1 = r10;					\
	r1 += -48;					\
	r2 = 34;					\
	r2 |= 24;					\
	r3 = 0;						\
	call %[bpf_probe_read_kernel];			\
	exit;						\
"	:
	: __imm(bpf_probe_read_kernel)
	: __clobber_all);
}

SEC("tracepoint")
__description("constant register |= constant register should keep constant type")
__success
__naked void register_should_keep_constant_type(void)
{
	asm volatile ("					\
	r1 = r10;					\
	r1 += -48;					\
	r2 = 34;					\
	r4 = 13;					\
	r2 |= r4;					\
	r3 = 0;						\
	call %[bpf_probe_read_kernel];			\
	exit;						\
"	:
	: __imm(bpf_probe_read_kernel)
	: __clobber_all);
}

SEC("tracepoint")
__description("constant register |= constant register should not bypass stack boundary checks")
__failure __msg("invalid indirect access to stack R1 off=-48 size=58")
__naked void not_bypass_stack_boundary_checks_2(void)
{
	asm volatile ("					\
	r1 = r10;					\
	r1 += -48;					\
	r2 = 34;					\
	r4 = 24;					\
	r2 |= r4;					\
	r3 = 0;						\
	call %[bpf_probe_read_kernel];			\
	exit;						\
"	:
	: __imm(bpf_probe_read_kernel)
	: __clobber_all);
}

char _license[] SEC("license") = "GPL";