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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/test_attach_probe.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 // Copyright (c) 2017 Facebook
  3 
  4 #include "vmlinux.h"
  5 #include <bpf/bpf_helpers.h>
  6 #include <bpf/bpf_tracing.h>
  7 #include <bpf/bpf_core_read.h>
  8 #include "bpf_misc.h"
  9 
 10 int kprobe2_res = 0;
 11 int kretprobe2_res = 0;
 12 int uprobe_byname_res = 0;
 13 int uretprobe_byname_res = 0;
 14 int uprobe_byname2_res = 0;
 15 int uretprobe_byname2_res = 0;
 16 int uprobe_byname3_sleepable_res = 0;
 17 int uprobe_byname3_res = 0;
 18 int uretprobe_byname3_sleepable_res = 0;
 19 int uretprobe_byname3_res = 0;
 20 void *user_ptr = 0;
 21 
 22 SEC("ksyscall/nanosleep")
 23 int BPF_KSYSCALL(handle_kprobe_auto, struct __kernel_timespec *req, struct __kernel_timespec *rem)
 24 {
 25         kprobe2_res = 11;
 26         return 0;
 27 }
 28 
 29 SEC("kretsyscall/nanosleep")
 30 int BPF_KRETPROBE(handle_kretprobe_auto, int ret)
 31 {
 32         kretprobe2_res = 22;
 33         return ret;
 34 }
 35 
 36 SEC("uprobe")
 37 int handle_uprobe_ref_ctr(struct pt_regs *ctx)
 38 {
 39         return 0;
 40 }
 41 
 42 SEC("uretprobe")
 43 int handle_uretprobe_ref_ctr(struct pt_regs *ctx)
 44 {
 45         return 0;
 46 }
 47 
 48 SEC("uprobe")
 49 int handle_uprobe_byname(struct pt_regs *ctx)
 50 {
 51         uprobe_byname_res = 5;
 52         return 0;
 53 }
 54 
 55 /* use auto-attach format for section definition. */
 56 SEC("uretprobe//proc/self/exe:trigger_func2")
 57 int handle_uretprobe_byname(struct pt_regs *ctx)
 58 {
 59         uretprobe_byname_res = 6;
 60         return 0;
 61 }
 62 
 63 SEC("uprobe")
 64 int BPF_UPROBE(handle_uprobe_byname2, const char *pathname, const char *mode)
 65 {
 66         char mode_buf[2] = {};
 67 
 68         /* verify fopen mode */
 69         bpf_probe_read_user(mode_buf, sizeof(mode_buf), mode);
 70         if (mode_buf[0] == 'r' && mode_buf[1] == 0)
 71                 uprobe_byname2_res = 7;
 72         return 0;
 73 }
 74 
 75 SEC("uretprobe")
 76 int BPF_URETPROBE(handle_uretprobe_byname2, void *ret)
 77 {
 78         uretprobe_byname2_res = 8;
 79         return 0;
 80 }
 81 
 82 static __always_inline bool verify_sleepable_user_copy(void)
 83 {
 84         char data[9];
 85 
 86         bpf_copy_from_user(data, sizeof(data), user_ptr);
 87         return bpf_strncmp(data, sizeof(data), "test_data") == 0;
 88 }
 89 
 90 SEC("uprobe.s//proc/self/exe:trigger_func3")
 91 int handle_uprobe_byname3_sleepable(struct pt_regs *ctx)
 92 {
 93         if (verify_sleepable_user_copy())
 94                 uprobe_byname3_sleepable_res = 9;
 95         return 0;
 96 }
 97 
 98 /**
 99  * same target as the uprobe.s above to force sleepable and non-sleepable
100  * programs in the same bpf_prog_array
101  */
102 SEC("uprobe//proc/self/exe:trigger_func3")
103 int handle_uprobe_byname3(struct pt_regs *ctx)
104 {
105         uprobe_byname3_res = 10;
106         return 0;
107 }
108 
109 SEC("uretprobe.s//proc/self/exe:trigger_func3")
110 int handle_uretprobe_byname3_sleepable(struct pt_regs *ctx)
111 {
112         if (verify_sleepable_user_copy())
113                 uretprobe_byname3_sleepable_res = 11;
114         return 0;
115 }
116 
117 SEC("uretprobe//proc/self/exe:trigger_func3")
118 int handle_uretprobe_byname3(struct pt_regs *ctx)
119 {
120         uretprobe_byname3_res = 12;
121         return 0;
122 }
123 
124 
125 char _license[] SEC("license") = "GPL";
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