1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/ld_ind.c */
3 
4 #include <linux/bpf.h>
5 #include <bpf/bpf_helpers.h>
6 #include "../../../include/linux/filter.h"
7 #include "bpf_misc.h"
8 
9 SEC("socket")
10 __description("ld_ind: check calling conv, r1")
11 __failure __msg("R1 !read_ok")
12 __failure_unpriv
ind_check_calling_conv_r1(void)13 __naked void ind_check_calling_conv_r1(void)
14 {
15 	asm volatile ("					\
16 	r6 = r1;					\
17 	r1 = 1;						\
18 	.8byte %[ld_ind];				\
19 	r0 = r1;					\
20 	exit;						\
21 "	:
22 	: __imm_insn(ld_ind, BPF_LD_IND(BPF_W, BPF_REG_1, -0x200000))
23 	: __clobber_all);
24 }
25 
26 SEC("socket")
27 __description("ld_ind: check calling conv, r2")
28 __failure __msg("R2 !read_ok")
29 __failure_unpriv
ind_check_calling_conv_r2(void)30 __naked void ind_check_calling_conv_r2(void)
31 {
32 	asm volatile ("					\
33 	r6 = r1;					\
34 	r2 = 1;						\
35 	.8byte %[ld_ind];				\
36 	r0 = r2;					\
37 	exit;						\
38 "	:
39 	: __imm_insn(ld_ind, BPF_LD_IND(BPF_W, BPF_REG_2, -0x200000))
40 	: __clobber_all);
41 }
42 
43 SEC("socket")
44 __description("ld_ind: check calling conv, r3")
45 __failure __msg("R3 !read_ok")
46 __failure_unpriv
ind_check_calling_conv_r3(void)47 __naked void ind_check_calling_conv_r3(void)
48 {
49 	asm volatile ("					\
50 	r6 = r1;					\
51 	r3 = 1;						\
52 	.8byte %[ld_ind];				\
53 	r0 = r3;					\
54 	exit;						\
55 "	:
56 	: __imm_insn(ld_ind, BPF_LD_IND(BPF_W, BPF_REG_3, -0x200000))
57 	: __clobber_all);
58 }
59 
60 SEC("socket")
61 __description("ld_ind: check calling conv, r4")
62 __failure __msg("R4 !read_ok")
63 __failure_unpriv
ind_check_calling_conv_r4(void)64 __naked void ind_check_calling_conv_r4(void)
65 {
66 	asm volatile ("					\
67 	r6 = r1;					\
68 	r4 = 1;						\
69 	.8byte %[ld_ind];				\
70 	r0 = r4;					\
71 	exit;						\
72 "	:
73 	: __imm_insn(ld_ind, BPF_LD_IND(BPF_W, BPF_REG_4, -0x200000))
74 	: __clobber_all);
75 }
76 
77 SEC("socket")
78 __description("ld_ind: check calling conv, r5")
79 __failure __msg("R5 !read_ok")
80 __failure_unpriv
ind_check_calling_conv_r5(void)81 __naked void ind_check_calling_conv_r5(void)
82 {
83 	asm volatile ("					\
84 	r6 = r1;					\
85 	r5 = 1;						\
86 	.8byte %[ld_ind];				\
87 	r0 = r5;					\
88 	exit;						\
89 "	:
90 	: __imm_insn(ld_ind, BPF_LD_IND(BPF_W, BPF_REG_5, -0x200000))
91 	: __clobber_all);
92 }
93 
94 SEC("socket")
95 __description("ld_ind: check calling conv, r7")
96 __success __success_unpriv __retval(1)
ind_check_calling_conv_r7(void)97 __naked void ind_check_calling_conv_r7(void)
98 {
99 	asm volatile ("					\
100 	r6 = r1;					\
101 	r7 = 1;						\
102 	.8byte %[ld_ind];				\
103 	r0 = r7;					\
104 	exit;						\
105 "	:
106 	: __imm_insn(ld_ind, BPF_LD_IND(BPF_W, BPF_REG_7, -0x200000))
107 	: __clobber_all);
108 }
109 
110 char _license[] SEC("license") = "GPL";
111