我知道过去有一个关于此的问题,但我没有找到解决方案。
我正在编写下一个内核模块来跟踪do_exec
调用。AFAIK 每个新的进程映像(不是创建)都应该像这样加载,所以我想我可以用 this 追踪所有执行jprobe
。
不幸的是,唯一的输出jprobe
是这些:
execve called /usr/lib/systemd/systemd-cgroups-agent by kworker/u8:3
我的模块代码如下:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kprobes.h>
#include <linux/fs.h>
static long jdo_execve(struct filename *filename,
const char __user *const __user __argv,
const char __user *const __user __envp)
{
const char *name = filename->name;
printk("execve called %s by %s\n", name, current->comm);
jprobe_return();
return 0;
}
static struct jprobe execve_jprobe = {
.entry = jdo_execve,
.kp = {
.symbol_name = "do_execve",
},
};
static int __init jprobe_init(void)
{
int ret;
ret = register_jprobe(&execve_jprobe);
if (ret < 0) {
printk(KERN_INFO "register_jprobe failed, returned %d\n", ret);
return -1;
}
return 0;
}
static void __exit jprobe_exit(void)
{
unregister_jprobe(&execve_jprobe);
printk(KERN_INFO "jprobe at %p unregistered\n", write_jprobe.kp.addr);
}
module_init(jprobe_init)
module_exit(jprobe_exit)
MODULE_LICENSE("GPL");
我正在使用 CentOS 7,内核版本 3.10.0-514.el7.x86_64
任何帮助表示赞赏!