1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2021 Facebook */
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
7 char _license[] SEC("license") = "GPL";
13 #define VM_EXEC 0x00000004
14 #define DNAME_INLINE_LEN 32
17 char d_iname[DNAME_INLINE_LEN] = {0};
18 __u32 found_vm_exec = 0;
20 int find_zero_ret = -1;
21 int find_addr_ret = -1;
23 static long check_vma(struct task_struct *task, struct vm_area_struct *vma,
24 struct callback_ctx *data)
27 bpf_probe_read_kernel_str(d_iname, DNAME_INLINE_LEN - 1,
28 vma->vm_file->f_path.dentry->d_iname);
30 /* check for VM_EXEC */
31 if (vma->vm_flags & VM_EXEC)
37 SEC("raw_tp/sys_enter")
38 int handle_getpid(void)
40 struct task_struct *task = bpf_get_current_task_btf();
41 struct callback_ctx data = {};
43 if (task->pid != target_pid)
46 find_addr_ret = bpf_find_vma(task, addr, check_vma, &data, 0);
48 /* this should return -ENOENT */
49 find_zero_ret = bpf_find_vma(task, 0, check_vma, &data, 0);
56 struct task_struct *task = bpf_get_current_task_btf();
57 struct callback_ctx data = {};
59 if (task->pid != target_pid)
62 find_addr_ret = bpf_find_vma(task, addr, check_vma, &data, 0);
64 /* In NMI, this should return -EBUSY, as the previous call is using
67 find_zero_ret = bpf_find_vma(task, 0, check_vma, &data, 0);