I would like to generate user stack trace in kernel module. Actually I made a kernel module for intercepting the close system call by hooking the system call table. And I want to know who calls this system call for the specific fd in the user mode. In my kernel module, comparing the tracking fd and given param, if match, want to make a user space call stack. I tried to make the backtrace by dump_stack() or WARN macro, but it generated the kerenl stack trace. Is is possible to get the user stack trace in kerenl module ?
How to generate user stack trace in kernel module
2.5k views Asked by 정민철 At
2
There are 2 answers
0
On
You can use the save_stack_trace_user()
function from your kernel module to achieve that:
void save_stack_trace_user(struct stack_trace *trace);
You can have a look at how ftrace does it in the kernel: ftrace_trace_userstack
If you don't mind the user program getting terminated, you could abort it e. g. with
force_sig(SIGABRT, current)
and analyze the core dump with a debugger.