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
9SEC("socket")
10__description("ld_ind: check calling conv, r1")
11__failure __msg("R1 !read_ok")
12__failure_unpriv
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
26SEC("socket")
27__description("ld_ind: check calling conv, r2")
28__failure __msg("R2 !read_ok")
29__failure_unpriv
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
43SEC("socket")
44__description("ld_ind: check calling conv, r3")
45__failure __msg("R3 !read_ok")
46__failure_unpriv
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
60SEC("socket")
61__description("ld_ind: check calling conv, r4")
62__failure __msg("R4 !read_ok")
63__failure_unpriv
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
77SEC("socket")
78__description("ld_ind: check calling conv, r5")
79__failure __msg("R5 !read_ok")
80__failure_unpriv
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
94SEC("socket")
95__description("ld_ind: check calling conv, r7")
96__success __success_unpriv __retval(1)
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
110char _license[] SEC("license") = "GPL";
111