-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmain.bpf.c
38 lines (30 loc) · 1.09 KB
/
main.bpf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "vmlinux.h"
#include "common.h"
#include <bpf/bpf_core_read.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
/* BPF ringbuf map */
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 16 * 1024 /* 16 KB */);
} events SEC(".maps");
SEC("tracepoint/syscalls/sys_enter_fchmodat")
int tracepoint__syscalls__sys_enter_fchmodat(
struct trace_event_raw_sys_enter *ctx) {
struct event_t *event;
event = bpf_ringbuf_reserve(&events, sizeof(*event), 0);
if (!event) {
return 0;
}
struct task_struct *task = (struct task_struct *)bpf_get_current_task();
event->host_pid = bpf_get_current_pid_tgid() >> 32;
event->host_ppid = BPF_CORE_READ(task, real_parent, tgid);
bpf_get_current_comm(&event->comm, sizeof(event->comm));
char *filename_ptr = (char *)BPF_CORE_READ(ctx, args[1]);
bpf_core_read_user_str(&event->filename, sizeof(event->filename),
filename_ptr);
event->mode = BPF_CORE_READ(ctx, args[2]);
bpf_ringbuf_submit(event, 0);
return 0;
}
char _license[] SEC("license") = "GPL";