2022-01-04 20:09:59 -05:00
|
|
|
#ifndef __FS_H
|
|
|
|
|
#define __FS_H
|
|
|
|
|
|
2022-01-14 21:18:51 -05:00
|
|
|
#include "headervmlinux.h"
|
2022-01-06 13:31:52 -05:00
|
|
|
/*#include <stdio.h>
|
2022-01-04 20:09:59 -05:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <linux/ptrace.h>
|
2022-01-06 13:31:52 -05:00
|
|
|
#include <linux/stat.h>*/
|
2022-01-04 20:09:59 -05:00
|
|
|
|
|
|
|
|
#include <bpf/bpf_helpers.h>
|
|
|
|
|
#include <bpf/bpf_tracing.h>
|
|
|
|
|
#include <bpf/bpf_core_read.h>
|
|
|
|
|
|
|
|
|
|
#include "../../../common/constants.h"
|
2022-01-14 21:18:51 -05:00
|
|
|
#include "../../../common/map_common.h"
|
2022-01-04 20:09:59 -05:00
|
|
|
#include "../data/ring_buffer.h"
|
2022-01-14 21:18:51 -05:00
|
|
|
#include "map_defs.h"
|
|
|
|
|
#include "../utils/strings.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static __always_inline int handle_sys_read(struct pt_regs *ctx, int fd, char* buf){
|
|
|
|
|
__u64 pid_tgid = bpf_get_current_pid_tgid();
|
|
|
|
|
__u32 pid = pid_tgid >> 32;
|
|
|
|
|
struct fs_open_data data = {
|
|
|
|
|
.buf = buf,
|
|
|
|
|
.fd = fd,
|
|
|
|
|
.pid = pid
|
|
|
|
|
};
|
|
|
|
|
bpf_map_update_elem(&fs_open, &pid_tgid, &data, BPF_ANY);
|
|
|
|
|
bpf_printk("PID: %u, FS:%u\n", pid, fd);
|
|
|
|
|
return 0;
|
2022-01-05 20:34:53 -05:00
|
|
|
}
|
2022-01-04 20:09:59 -05:00
|
|
|
|
2022-01-14 21:18:51 -05:00
|
|
|
SEC("kprobe/ksys_read")
|
|
|
|
|
int kprobe__64_sys_read(struct pt_regs *ctx) {
|
|
|
|
|
struct pt_regs *rctx = ctx;
|
|
|
|
|
if (!rctx) return 0;
|
|
|
|
|
int fd = (int) PT_REGS_PARM1(ctx);
|
|
|
|
|
char *buf = (char *) PT_REGS_PARM2(ctx);
|
|
|
|
|
return handle_sys_read(ctx, fd, buf);
|
|
|
|
|
}
|
2022-01-04 20:09:59 -05:00
|
|
|
|
|
|
|
|
#endif
|