1// SPDX-License-Identifier: GPL-2.0
2/* Converted from tools/testing/selftests/bpf/verifier/const_or.c */
3
4#include <linux/bpf.h>
5#include <bpf/bpf_helpers.h>
6#include "bpf_misc.h"
7
8SEC("tracepoint")
9__description("constant register |= constant should keep constant type")
10__success
11__naked void constant_should_keep_constant_type(void)
12{
13 asm volatile (" \
14 r1 = r10; \
15 r1 += -48; \
16 r2 = 34; \
17 r2 |= 13; \
18 r3 = 0; \
19 call %[bpf_probe_read_kernel]; \
20 exit; \
21" :
22 : __imm(bpf_probe_read_kernel)
23 : __clobber_all);
24}
25
26SEC("tracepoint")
27__description("constant register |= constant should not bypass stack boundary checks")
28__failure __msg("invalid indirect access to stack R1 off=-48 size=58")
29__naked void not_bypass_stack_boundary_checks_1(void)
30{
31 asm volatile (" \
32 r1 = r10; \
33 r1 += -48; \
34 r2 = 34; \
35 r2 |= 24; \
36 r3 = 0; \
37 call %[bpf_probe_read_kernel]; \
38 exit; \
39" :
40 : __imm(bpf_probe_read_kernel)
41 : __clobber_all);
42}
43
44SEC("tracepoint")
45__description("constant register |= constant register should keep constant type")
46__success
47__naked void register_should_keep_constant_type(void)
48{
49 asm volatile (" \
50 r1 = r10; \
51 r1 += -48; \
52 r2 = 34; \
53 r4 = 13; \
54 r2 |= r4; \
55 r3 = 0; \
56 call %[bpf_probe_read_kernel]; \
57 exit; \
58" :
59 : __imm(bpf_probe_read_kernel)
60 : __clobber_all);
61}
62
63SEC("tracepoint")
64__description("constant register |= constant register should not bypass stack boundary checks")
65__failure __msg("invalid indirect access to stack R1 off=-48 size=58")
66__naked void not_bypass_stack_boundary_checks_2(void)
67{
68 asm volatile (" \
69 r1 = r10; \
70 r1 += -48; \
71 r2 = 34; \
72 r4 = 24; \
73 r2 |= r4; \
74 r3 = 0; \
75 call %[bpf_probe_read_kernel]; \
76 exit; \
77" :
78 : __imm(bpf_probe_read_kernel)
79 : __clobber_all);
80}
81
82char _license[] SEC("license") = "GPL";
83

source code of linux/tools/testing/selftests/bpf/progs/verifier_const_or.c