tracepoint内核调试sys_enter_openat系统调用
前言:tracepoint内核调试sys_enter_openat系统调用
参考文章:https://linux.die.net/man/2/openat
参考文章:https://eunomia.dev/zh/tutorials/4-opensnoop/
sys_enter_openat系统调用

tracepoint调试sys_enter_openat
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
/// @description "Process ID to trace"
const volatile int pid_target = 0;
SEC("tracepoint/syscalls/sys_enter_openat")
int tracepoint__syscalls__sys_enter_openat(struct trace_event_raw_sys_enter* ctx)
{
u64 id = bpf_get_current_pid_tgid();
u32 pid = id >> 32;
if (pid_target && pid_target != pid)
return false;
// Use bpf_printk to print the process information
bpf_printk("Process ID: %d enter sys openat\n", pid);
return 0;
}
/// "Trace open family syscalls."
char LICENSE[] SEC("license") = "GPL";
进行编译运行操作,同时可以看到在阿里云上的话相关的安骑士产品应用在持续的监控文件打开情况,如下图所示
ecc opensnoop.bpf.c
ecli run package.json
cat /sys/kernel/debug/tracing/trace_pipe

参数接受
在上面的代码中定义了如下两行代码,可实现命令行解析接受指定pid来进行过滤
/// @description "Process ID to trace"
const volatile int pid_target = 0;
运行如下命令,可以看到调试输出信息只有pid为1929的进程信息


浙公网安备 33010602011771号