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

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

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ 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/map_in_map.c */
  3 
  4 #include <linux/bpf.h>
  5 #include <bpf/bpf_helpers.h>
  6 #include "bpf_misc.h"
  7 
  8 struct {
  9         __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
 10         __uint(max_entries, 1);
 11         __type(key, int);
 12         __type(value, int);
 13         __array(values, struct {
 14                 __uint(type, BPF_MAP_TYPE_ARRAY);
 15                 __uint(max_entries, 1);
 16                 __type(key, int);
 17                 __type(value, int);
 18         });
 19 } map_in_map SEC(".maps");
 20 
 21 SEC("socket")
 22 __description("map in map access")
 23 __success __success_unpriv __retval(0)
 24 __naked void map_in_map_access(void)
 25 {
 26         asm volatile ("                                 \
 27         r1 = 0;                                         \
 28         *(u32*)(r10 - 4) = r1;                          \
 29         r2 = r10;                                       \
 30         r2 += -4;                                       \
 31         r1 = %[map_in_map] ll;                          \
 32         call %[bpf_map_lookup_elem];                    \
 33         if r0 == 0 goto l0_%=;                          \
 34         r1 = 0;                                         \
 35         *(u32*)(r10 - 4) = r1;                          \
 36         r2 = r10;                                       \
 37         r2 += -4;                                       \
 38         r1 = r0;                                        \
 39         call %[bpf_map_lookup_elem];                    \
 40 l0_%=:  r0 = 0;                                         \
 41         exit;                                           \
 42 "       :
 43         : __imm(bpf_map_lookup_elem),
 44           __imm_addr(map_in_map)
 45         : __clobber_all);
 46 }
 47 
 48 SEC("xdp")
 49 __description("map in map state pruning")
 50 __success __msg("processed 26 insns")
 51 __log_level(2) __retval(0) __flag(BPF_F_TEST_STATE_FREQ)
 52 __naked void map_in_map_state_pruning(void)
 53 {
 54         asm volatile ("                                 \
 55         r1 = 0;                                         \
 56         *(u32*)(r10 - 4) = r1;                          \
 57         r6 = r10;                                       \
 58         r6 += -4;                                       \
 59         r2 = r6;                                        \
 60         r1 = %[map_in_map] ll;                          \
 61         call %[bpf_map_lookup_elem];                    \
 62         if r0 != 0 goto l0_%=;                          \
 63         exit;                                           \
 64 l0_%=:  r2 = r6;                                        \
 65         r1 = r0;                                        \
 66         call %[bpf_map_lookup_elem];                    \
 67         if r0 != 0 goto l1_%=;                          \
 68         r2 = r6;                                        \
 69         r1 = %[map_in_map] ll;                          \
 70         call %[bpf_map_lookup_elem];                    \
 71         if r0 != 0 goto l2_%=;                          \
 72         exit;                                           \
 73 l2_%=:  r2 = r6;                                        \
 74         r1 = r0;                                        \
 75         call %[bpf_map_lookup_elem];                    \
 76         if r0 != 0 goto l1_%=;                          \
 77         exit;                                           \
 78 l1_%=:  r0 = *(u32*)(r0 + 0);                           \
 79         exit;                                           \
 80 "       :
 81         : __imm(bpf_map_lookup_elem),
 82           __imm_addr(map_in_map)
 83         : __clobber_all);
 84 }
 85 
 86 SEC("socket")
 87 __description("invalid inner map pointer")
 88 __failure __msg("R1 pointer arithmetic on map_ptr prohibited")
 89 __failure_unpriv
 90 __naked void invalid_inner_map_pointer(void)
 91 {
 92         asm volatile ("                                 \
 93         r1 = 0;                                         \
 94         *(u32*)(r10 - 4) = r1;                          \
 95         r2 = r10;                                       \
 96         r2 += -4;                                       \
 97         r1 = %[map_in_map] ll;                          \
 98         call %[bpf_map_lookup_elem];                    \
 99         if r0 == 0 goto l0_%=;                          \
100         r1 = 0;                                         \
101         *(u32*)(r10 - 4) = r1;                          \
102         r2 = r10;                                       \
103         r2 += -4;                                       \
104         r1 = r0;                                        \
105         r1 += 8;                                        \
106         call %[bpf_map_lookup_elem];                    \
107 l0_%=:  r0 = 0;                                         \
108         exit;                                           \
109 "       :
110         : __imm(bpf_map_lookup_elem),
111           __imm_addr(map_in_map)
112         : __clobber_all);
113 }
114 
115 SEC("socket")
116 __description("forgot null checking on the inner map pointer")
117 __failure __msg("R1 type=map_value_or_null expected=map_ptr")
118 __failure_unpriv
119 __naked void on_the_inner_map_pointer(void)
120 {
121         asm volatile ("                                 \
122         r1 = 0;                                         \
123         *(u32*)(r10 - 4) = r1;                          \
124         r2 = r10;                                       \
125         r2 += -4;                                       \
126         r1 = %[map_in_map] ll;                          \
127         call %[bpf_map_lookup_elem];                    \
128         r1 = 0;                                         \
129         *(u32*)(r10 - 4) = r1;                          \
130         r2 = r10;                                       \
131         r2 += -4;                                       \
132         r1 = r0;                                        \
133         call %[bpf_map_lookup_elem];                    \
134         r0 = 0;                                         \
135         exit;                                           \
136 "       :
137         : __imm(bpf_map_lookup_elem),
138           __imm_addr(map_in_map)
139         : __clobber_all);
140 }
141 
142 char _license[] SEC("license") = "GPL";
143 

~ [ 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