I know there has been a question about this in the past, but I didn't find a solution.
I'm writing the next kernel module to trace do_exec
calls. AFAIK every new process image (not creation) should be loaded like this, so I figure I can trace down all executions with this jprobe
.
Unfortunately, the only outputs from this jprobe
are these:
execve called /usr/lib/systemd/systemd-cgroups-agent by kworker/u8:3
My module code is as follow:
#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");
I'm using CentOS 7, kernel version 3.10.0-514.el7.x86_64
Any help is appreciated!