I wrote a simple kernel module that processes all processes and retrieves their registers stored when they were scheduled (especially EIP).
If I am not mistaken, what I need is saved on the kernel stack indicated by sp0 in the thread_struct of each process. This is what I do:
#include <linux/kernel.h> #include <linux/module.h> #include <linux/sched.h> int init_module(void){ struct task_struct *t; struct pt_regs regs; for_each_process(t){ memcpy(®s, (unsigned long*)(t->thread.sp0-sizeof(struct pt_regs)), sizeof(struct pt_regs)); printk(KERN_INFO "%s eip: %lx\n", t->comm, regs.ip); } return 0; } void cleanup_module(void){ } MODULE_LICENSE("GPL");
Now, the conclusion about user-level processes seems legitimate:
[ 3558.322088] bash eip: b770b430
BUT everything that I get from kernel threads is always 0.
[ 3558.322095] kworker/0:0 eip: 0
I do not understand. Does the kernel save registers somewhere else when it comes to kernel threads?
Is this accidentally related to the kernel advantage?
I'm on the core 3.14-1-486.
Thanks in advance.
source share