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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.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 /* Copyright (c) 2022, Oracle and/or its affiliates. */
  3 
  4 #include "vmlinux.h"
  5 
  6 #include <bpf/bpf_core_read.h>
  7 #include <bpf/bpf_helpers.h>
  8 #include <bpf/bpf_tracing.h>
  9 #include "bpf_misc.h"
 10 
 11 int uprobe_byname_parm1 = 0;
 12 int uprobe_byname_ran = 0;
 13 int uretprobe_byname_rc = 0;
 14 int uretprobe_byname_ret = 0;
 15 int uretprobe_byname_ran = 0;
 16 u64 uprobe_byname2_parm1 = 0;
 17 int uprobe_byname2_ran = 0;
 18 u64 uretprobe_byname2_rc = 0;
 19 int uretprobe_byname2_ran = 0;
 20 
 21 int test_pid;
 22 
 23 int a[8];
 24 
 25 /* This program cannot auto-attach, but that should not stop other
 26  * programs from attaching.
 27  */
 28 SEC("uprobe")
 29 int handle_uprobe_noautoattach(struct pt_regs *ctx)
 30 {
 31         return 0;
 32 }
 33 
 34 SEC("uprobe//proc/self/exe:autoattach_trigger_func")
 35 int BPF_UPROBE(handle_uprobe_byname
 36                , int arg1
 37                , int arg2
 38                , int arg3
 39 #if FUNC_REG_ARG_CNT > 3
 40                , int arg4
 41 #endif
 42 #if FUNC_REG_ARG_CNT > 4
 43                , int arg5
 44 #endif
 45 #if FUNC_REG_ARG_CNT > 5
 46                , int arg6
 47 #endif
 48 #if FUNC_REG_ARG_CNT > 6
 49                , int arg7
 50 #endif
 51 #if FUNC_REG_ARG_CNT > 7
 52                , int arg8
 53 #endif
 54 )
 55 {
 56         uprobe_byname_parm1 = PT_REGS_PARM1_CORE(ctx);
 57         uprobe_byname_ran = 1;
 58 
 59         a[0] = arg1;
 60         a[1] = arg2;
 61         a[2] = arg3;
 62 #if FUNC_REG_ARG_CNT > 3
 63         a[3] = arg4;
 64 #endif
 65 #if FUNC_REG_ARG_CNT > 4
 66         a[4] = arg5;
 67 #endif
 68 #if FUNC_REG_ARG_CNT > 5
 69         a[5] = arg6;
 70 #endif
 71 #if FUNC_REG_ARG_CNT > 6
 72         a[6] = arg7;
 73 #endif
 74 #if FUNC_REG_ARG_CNT > 7
 75         a[7] = arg8;
 76 #endif
 77         return 0;
 78 }
 79 
 80 SEC("uretprobe//proc/self/exe:autoattach_trigger_func")
 81 int BPF_URETPROBE(handle_uretprobe_byname, int ret)
 82 {
 83         uretprobe_byname_rc = PT_REGS_RC_CORE(ctx);
 84         uretprobe_byname_ret = ret;
 85         uretprobe_byname_ran = 2;
 86 
 87         return 0;
 88 }
 89 
 90 
 91 SEC("uprobe/libc.so.6:fopen")
 92 int BPF_UPROBE(handle_uprobe_byname2, const char *pathname, const char *mode)
 93 {
 94         int pid = bpf_get_current_pid_tgid() >> 32;
 95 
 96         /* ignore irrelevant invocations */
 97         if (test_pid != pid)
 98                 return 0;
 99         uprobe_byname2_parm1 = (u64)(long)pathname;
100         uprobe_byname2_ran = 3;
101         return 0;
102 }
103 
104 SEC("uretprobe/libc.so.6:fopen")
105 int BPF_URETPROBE(handle_uretprobe_byname2, void *ret)
106 {
107         int pid = bpf_get_current_pid_tgid() >> 32;
108 
109         /* ignore irrelevant invocations */
110         if (test_pid != pid)
111                 return 0;
112         uretprobe_byname2_rc = (u64)(long)ret;
113         uretprobe_byname2_ran = 4;
114         return 0;
115 }
116 
117 char _license[] SEC("license") = "GPL";
118 

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