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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/verifier_bpf_get_stack.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/bpf_get_stack.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_ARRAY);
 17         __uint(max_entries, 1);
 18         __type(key, int);
 19         __type(value, struct test_val);
 20 } map_array_48b SEC(".maps");
 21 
 22 struct {
 23         __uint(type, BPF_MAP_TYPE_HASH);
 24         __uint(max_entries, 1);
 25         __type(key, long long);
 26         __type(value, struct test_val);
 27 } map_hash_48b SEC(".maps");
 28 
 29 SEC("tracepoint")
 30 __description("bpf_get_stack return R0 within range")
 31 __success
 32 __naked void stack_return_r0_within_range(void)
 33 {
 34         asm volatile ("                                 \
 35         r6 = r1;                                        \
 36         r1 = 0;                                         \
 37         *(u64*)(r10 - 8) = r1;                          \
 38         r2 = r10;                                       \
 39         r2 += -8;                                       \
 40         r1 = %[map_hash_48b] ll;                        \
 41         call %[bpf_map_lookup_elem];                    \
 42         if r0 == 0 goto l0_%=;                          \
 43         r7 = r0;                                        \
 44         r9 = %[__imm_0];                                \
 45         r1 = r6;                                        \
 46         r2 = r7;                                        \
 47         r3 = %[__imm_0];                                \
 48         r4 = 256;                                       \
 49         call %[bpf_get_stack];                          \
 50         r1 = 0;                                         \
 51         r8 = r0;                                        \
 52         r8 <<= 32;                                      \
 53         r8 s>>= 32;                                     \
 54         if r1 s> r8 goto l0_%=;                         \
 55         r9 -= r8;                                       \
 56         r2 = r7;                                        \
 57         r2 += r8;                                       \
 58         r1 = r9;                                        \
 59         r1 <<= 32;                                      \
 60         r1 s>>= 32;                                     \
 61         r3 = r2;                                        \
 62         r3 += r1;                                       \
 63         r1 = r7;                                        \
 64         r5 = %[__imm_0];                                \
 65         r1 += r5;                                       \
 66         if r3 >= r1 goto l0_%=;                         \
 67         r1 = r6;                                        \
 68         r3 = r9;                                        \
 69         r4 = 0;                                         \
 70         call %[bpf_get_stack];                          \
 71 l0_%=:  exit;                                           \
 72 "       :
 73         : __imm(bpf_get_stack),
 74           __imm(bpf_map_lookup_elem),
 75           __imm_addr(map_hash_48b),
 76           __imm_const(__imm_0, sizeof(struct test_val) / 2)
 77         : __clobber_all);
 78 }
 79 
 80 SEC("iter/task")
 81 __description("bpf_get_task_stack return R0 range is refined")
 82 __success
 83 __naked void return_r0_range_is_refined(void)
 84 {
 85         asm volatile ("                                 \
 86         r6 = *(u64*)(r1 + 0);                           \
 87         r6 = *(u64*)(r6 + 0);           /* ctx->meta->seq */\
 88         r7 = *(u64*)(r1 + 8);           /* ctx->task */\
 89         r1 = %[map_array_48b] ll;       /* fixup_map_array_48b */\
 90         r2 = 0;                                         \
 91         *(u64*)(r10 - 8) = r2;                          \
 92         r2 = r10;                                       \
 93         r2 += -8;                                       \
 94         call %[bpf_map_lookup_elem];                    \
 95         if r0 != 0 goto l0_%=;                          \
 96         r0 = 0;                                         \
 97         exit;                                           \
 98 l0_%=:  if r7 != 0 goto l1_%=;                          \
 99         r0 = 0;                                         \
100         exit;                                           \
101 l1_%=:  r1 = r7;                                        \
102         r2 = r0;                                        \
103         r9 = r0;                        /* keep buf for seq_write */\
104         r3 = 48;                                        \
105         r4 = 0;                                         \
106         call %[bpf_get_task_stack];                     \
107         if r0 s> 0 goto l2_%=;                          \
108         r0 = 0;                                         \
109         exit;                                           \
110 l2_%=:  r1 = r6;                                        \
111         r2 = r9;                                        \
112         r3 = r0;                                        \
113         call %[bpf_seq_write];                          \
114         r0 = 0;                                         \
115         exit;                                           \
116 "       :
117         : __imm(bpf_get_task_stack),
118           __imm(bpf_map_lookup_elem),
119           __imm(bpf_seq_write),
120           __imm_addr(map_array_48b)
121         : __clobber_all);
122 }
123 
124 char _license[] SEC("license") = "GPL";
125 

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