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

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

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 
  3 #include "vmlinux.h"
  4 #include "bpf_experimental.h"
  5 #include <bpf/bpf_helpers.h>
  6 #include "bpf_misc.h"
  7 #include "../bpf_testmod/bpf_testmod_kfunc.h"
  8 
  9 char _license[] SEC("license") = "GPL";
 10 
 11 SEC("raw_tp/sys_enter")
 12 __success
 13 int iter_next_trusted(const void *ctx)
 14 {
 15         struct task_struct *cur_task = bpf_get_current_task_btf();
 16         struct bpf_iter_task_vma vma_it;
 17         struct vm_area_struct *vma_ptr;
 18 
 19         bpf_iter_task_vma_new(&vma_it, cur_task, 0);
 20 
 21         vma_ptr = bpf_iter_task_vma_next(&vma_it);
 22         if (vma_ptr == NULL)
 23                 goto out;
 24 
 25         bpf_kfunc_trusted_vma_test(vma_ptr);
 26 out:
 27         bpf_iter_task_vma_destroy(&vma_it);
 28         return 0;
 29 }
 30 
 31 SEC("raw_tp/sys_enter")
 32 __failure __msg("Possibly NULL pointer passed to trusted arg0")
 33 int iter_next_trusted_or_null(const void *ctx)
 34 {
 35         struct task_struct *cur_task = bpf_get_current_task_btf();
 36         struct bpf_iter_task_vma vma_it;
 37         struct vm_area_struct *vma_ptr;
 38 
 39         bpf_iter_task_vma_new(&vma_it, cur_task, 0);
 40 
 41         vma_ptr = bpf_iter_task_vma_next(&vma_it);
 42 
 43         bpf_kfunc_trusted_vma_test(vma_ptr);
 44 
 45         bpf_iter_task_vma_destroy(&vma_it);
 46         return 0;
 47 }
 48 
 49 SEC("raw_tp/sys_enter")
 50 __success
 51 int iter_next_rcu(const void *ctx)
 52 {
 53         struct task_struct *cur_task = bpf_get_current_task_btf();
 54         struct bpf_iter_task task_it;
 55         struct task_struct *task_ptr;
 56 
 57         bpf_iter_task_new(&task_it, cur_task, 0);
 58 
 59         task_ptr = bpf_iter_task_next(&task_it);
 60         if (task_ptr == NULL)
 61                 goto out;
 62 
 63         bpf_kfunc_rcu_task_test(task_ptr);
 64 out:
 65         bpf_iter_task_destroy(&task_it);
 66         return 0;
 67 }
 68 
 69 SEC("raw_tp/sys_enter")
 70 __failure __msg("Possibly NULL pointer passed to trusted arg0")
 71 int iter_next_rcu_or_null(const void *ctx)
 72 {
 73         struct task_struct *cur_task = bpf_get_current_task_btf();
 74         struct bpf_iter_task task_it;
 75         struct task_struct *task_ptr;
 76 
 77         bpf_iter_task_new(&task_it, cur_task, 0);
 78 
 79         task_ptr = bpf_iter_task_next(&task_it);
 80 
 81         bpf_kfunc_rcu_task_test(task_ptr);
 82 
 83         bpf_iter_task_destroy(&task_it);
 84         return 0;
 85 }
 86 
 87 SEC("raw_tp/sys_enter")
 88 __failure __msg("R1 must be referenced or trusted")
 89 int iter_next_rcu_not_trusted(const void *ctx)
 90 {
 91         struct task_struct *cur_task = bpf_get_current_task_btf();
 92         struct bpf_iter_task task_it;
 93         struct task_struct *task_ptr;
 94 
 95         bpf_iter_task_new(&task_it, cur_task, 0);
 96 
 97         task_ptr = bpf_iter_task_next(&task_it);
 98         if (task_ptr == NULL)
 99                 goto out;
100 
101         bpf_kfunc_trusted_task_test(task_ptr);
102 out:
103         bpf_iter_task_destroy(&task_it);
104         return 0;
105 }
106 
107 SEC("raw_tp/sys_enter")
108 __failure __msg("R1 cannot write into rdonly_mem")
109 /* Message should not be 'R1 cannot write into rdonly_trusted_mem' */
110 int iter_next_ptr_mem_not_trusted(const void *ctx)
111 {
112         struct bpf_iter_num num_it;
113         int *num_ptr;
114 
115         bpf_iter_num_new(&num_it, 0, 10);
116 
117         num_ptr = bpf_iter_num_next(&num_it);
118         if (num_ptr == NULL)
119                 goto out;
120 
121         bpf_kfunc_trusted_num_test(num_ptr);
122 out:
123         bpf_iter_num_destroy(&num_it);
124         return 0;
125 }
126 

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