I accessing the current process's structure in order to get the process ID and the command name for the current process within a Linux module in kernel-space, but when I build my module with make
and then insert it into the kernel, insmod
returns Killed
and then I cannot even remove my module from the kernel.
Is there something wrong here?
As you can see, I also tried to use task_struct
as global, but I get the same results.
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
// #include <linux/moduleparam.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("whoami");
MODULE_DESCRIPTION("Simple LKM");
// char *to_say = "Nothing";
// struct task_struct *current_process;
// module_param(to_say, charp, S_IRUGO);
static int __init initialization_function(void)
{
struct task_struct *current_process;
printk(KERN_INFO "Module: pid - %d, command name - %s\n", current_process->pid, current_process->comm);
return 0;
}
static void __exit cleanup_funcion(void)
{
printk(KERN_INFO "Module: Bye, World.");
}
module_init(initialization_function);
module_exit(cleanup_funcion);
$ make all
$ sudo insmod my_module.ko
Killed
$ tail -f /var/log/syslog | grep "Module:"
$ sudo rmmod my_module
cannot remove...
I fixed the error, I just initallized current_process
with current
.
struct task_struct *current_process = current;
printk(KERN_INFO "Module: pid - %d, command name - %s\n", current_process->pid, current_process->comm);