0001
0002
0003 #include "vmlinux.h"
0004 #include <bpf/bpf_helpers.h>
0005 #include <bpf/bpf_tracing.h>
0006
0007 char _license[] SEC("license") = "GPL";
0008
0009 struct callback_ctx {
0010 int dummy;
0011 };
0012
0013 #define VM_EXEC 0x00000004
0014 #define DNAME_INLINE_LEN 32
0015
0016 pid_t target_pid = 0;
0017 char d_iname[DNAME_INLINE_LEN] = {0};
0018 __u32 found_vm_exec = 0;
0019 __u64 addr = 0;
0020 int find_zero_ret = -1;
0021 int find_addr_ret = -1;
0022
0023 static long check_vma(struct task_struct *task, struct vm_area_struct *vma,
0024 struct callback_ctx *data)
0025 {
0026 if (vma->vm_file)
0027 bpf_probe_read_kernel_str(d_iname, DNAME_INLINE_LEN - 1,
0028 vma->vm_file->f_path.dentry->d_iname);
0029
0030
0031 if (vma->vm_flags & VM_EXEC)
0032 found_vm_exec = 1;
0033
0034 return 0;
0035 }
0036
0037 SEC("raw_tp/sys_enter")
0038 int handle_getpid(void)
0039 {
0040 struct task_struct *task = bpf_get_current_task_btf();
0041 struct callback_ctx data = {};
0042
0043 if (task->pid != target_pid)
0044 return 0;
0045
0046 find_addr_ret = bpf_find_vma(task, addr, check_vma, &data, 0);
0047
0048
0049 find_zero_ret = bpf_find_vma(task, 0, check_vma, &data, 0);
0050 return 0;
0051 }
0052
0053 SEC("perf_event")
0054 int handle_pe(void)
0055 {
0056 struct task_struct *task = bpf_get_current_task_btf();
0057 struct callback_ctx data = {};
0058
0059 if (task->pid != target_pid)
0060 return 0;
0061
0062 find_addr_ret = bpf_find_vma(task, addr, check_vma, &data, 0);
0063
0064
0065
0066
0067 find_zero_ret = bpf_find_vma(task, 0, check_vma, &data, 0);
0068 return 0;
0069 }