~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/verifier_value.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /* Converted from tools/testing/selftests/bpf/verifier/value.c */
  3 
  4 #include <linux/bpf.h>
  5 #include <bpf/bpf_helpers.h>
  6 #include "bpf_misc.h"
  7 
  8 #define MAX_ENTRIES 11
  9 
 10 struct test_val {
 11         unsigned int index;
 12         int foo[MAX_ENTRIES];
 13 };
 14 
 15 struct {
 16         __uint(type, BPF_MAP_TYPE_HASH);
 17         __uint(max_entries, 1);
 18         __type(key, long long);
 19         __type(value, struct test_val);
 20 } map_hash_48b SEC(".maps");
 21 
 22 SEC("socket")
 23 __description("map element value store of cleared call register")
 24 __failure __msg("R1 !read_ok")
 25 __failure_unpriv __msg_unpriv("R1 !read_ok")
 26 __naked void store_of_cleared_call_register(void)
 27 {
 28         asm volatile ("                                 \
 29         r2 = r10;                                       \
 30         r2 += -8;                                       \
 31         r1 = 0;                                         \
 32         *(u64*)(r2 + 0) = r1;                           \
 33         r1 = %[map_hash_48b] ll;                        \
 34         call %[bpf_map_lookup_elem];                    \
 35         if r0 == 0 goto l0_%=;                          \
 36         *(u64*)(r0 + 0) = r1;                           \
 37 l0_%=:  exit;                                           \
 38 "       :
 39         : __imm(bpf_map_lookup_elem),
 40           __imm_addr(map_hash_48b)
 41         : __clobber_all);
 42 }
 43 
 44 SEC("socket")
 45 __description("map element value with unaligned store")
 46 __success __failure_unpriv __msg_unpriv("R0 leaks addr")
 47 __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
 48 __naked void element_value_with_unaligned_store(void)
 49 {
 50         asm volatile ("                                 \
 51         r2 = r10;                                       \
 52         r2 += -8;                                       \
 53         r1 = 0;                                         \
 54         *(u64*)(r2 + 0) = r1;                           \
 55         r1 = %[map_hash_48b] ll;                        \
 56         call %[bpf_map_lookup_elem];                    \
 57         if r0 == 0 goto l0_%=;                          \
 58         r0 += 3;                                        \
 59         r1 = 42;                                        \
 60         *(u64*)(r0 + 0) = r1;                           \
 61         r1 = 43;                                        \
 62         *(u64*)(r0 + 2) = r1;                           \
 63         r1 = 44;                                        \
 64         *(u64*)(r0 - 2) = r1;                           \
 65         r8 = r0;                                        \
 66         r1 = 32;                                        \
 67         *(u64*)(r8 + 0) = r1;                           \
 68         r1 = 33;                                        \
 69         *(u64*)(r8 + 2) = r1;                           \
 70         r1 = 34;                                        \
 71         *(u64*)(r8 - 2) = r1;                           \
 72         r8 += 5;                                        \
 73         r1 = 22;                                        \
 74         *(u64*)(r8 + 0) = r1;                           \
 75         r1 = 23;                                        \
 76         *(u64*)(r8 + 4) = r1;                           \
 77         r1 = 24;                                        \
 78         *(u64*)(r8 - 7) = r1;                           \
 79         r7 = r8;                                        \
 80         r7 += 3;                                        \
 81         r1 = 22;                                        \
 82         *(u64*)(r7 + 0) = r1;                           \
 83         r1 = 23;                                        \
 84         *(u64*)(r7 + 4) = r1;                           \
 85         r1 = 24;                                        \
 86         *(u64*)(r7 - 4) = r1;                           \
 87 l0_%=:  exit;                                           \
 88 "       :
 89         : __imm(bpf_map_lookup_elem),
 90           __imm_addr(map_hash_48b)
 91         : __clobber_all);
 92 }
 93 
 94 SEC("socket")
 95 __description("map element value with unaligned load")
 96 __success __failure_unpriv __msg_unpriv("R0 leaks addr")
 97 __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
 98 __naked void element_value_with_unaligned_load(void)
 99 {
100         asm volatile ("                                 \
101         r2 = r10;                                       \
102         r2 += -8;                                       \
103         r1 = 0;                                         \
104         *(u64*)(r2 + 0) = r1;                           \
105         r1 = %[map_hash_48b] ll;                        \
106         call %[bpf_map_lookup_elem];                    \
107         if r0 == 0 goto l0_%=;                          \
108         r1 = *(u32*)(r0 + 0);                           \
109         if r1 >= %[max_entries] goto l0_%=;             \
110         r0 += 3;                                        \
111         r7 = *(u64*)(r0 + 0);                           \
112         r7 = *(u64*)(r0 + 2);                           \
113         r8 = r0;                                        \
114         r7 = *(u64*)(r8 + 0);                           \
115         r7 = *(u64*)(r8 + 2);                           \
116         r0 += 5;                                        \
117         r7 = *(u64*)(r0 + 0);                           \
118         r7 = *(u64*)(r0 + 4);                           \
119 l0_%=:  exit;                                           \
120 "       :
121         : __imm(bpf_map_lookup_elem),
122           __imm_addr(map_hash_48b),
123           __imm_const(max_entries, MAX_ENTRIES)
124         : __clobber_all);
125 }
126 
127 SEC("socket")
128 __description("map element value is preserved across register spilling")
129 __success __failure_unpriv __msg_unpriv("R0 leaks addr")
130 __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
131 __naked void is_preserved_across_register_spilling(void)
132 {
133         asm volatile ("                                 \
134         r2 = r10;                                       \
135         r2 += -8;                                       \
136         r1 = 0;                                         \
137         *(u64*)(r2 + 0) = r1;                           \
138         r1 = %[map_hash_48b] ll;                        \
139         call %[bpf_map_lookup_elem];                    \
140         if r0 == 0 goto l0_%=;                          \
141         r0 += %[test_val_foo];                          \
142         r1 = 42;                                        \
143         *(u64*)(r0 + 0) = r1;                           \
144         r1 = r10;                                       \
145         r1 += -184;                                     \
146         *(u64*)(r1 + 0) = r0;                           \
147         r3 = *(u64*)(r1 + 0);                           \
148         r1 = 42;                                        \
149         *(u64*)(r3 + 0) = r1;                           \
150 l0_%=:  exit;                                           \
151 "       :
152         : __imm(bpf_map_lookup_elem),
153           __imm_addr(map_hash_48b),
154           __imm_const(test_val_foo, offsetof(struct test_val, foo))
155         : __clobber_all);
156 }
157 
158 char _license[] SEC("license") = "GPL";
159 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php