Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6334

Linux kernel module programming - hooking to sys_wait4 system call

$
0
0

I try to do hooking to system call sys_wait4 and every time I try to do rmmod to module the kernel crashes.

This is my code.

void **sys_call_table;//pointer for the system call's tabletypedef asmlinkage long (*sys)( struct pt_regs * );sys wait_dos;//save the original system call sys_wait4//Function initasmlinkage long hooked_wait(struct pt_regs *param){  printk("hello world\n");  return wait_dos(param);}//Functiom exitstatic int lkm_example_init(void){  write_cr0(read_cr0()&(~ 0x10000));  sys_call_table = (void*)kallsyms_lookup_name("sys_call_table");  wait_dos = sys_call_table[__NR_wait4];  sys_call_table[__NR_wait4] = hooked_wait;  write_cr0(read_cr0() | 0X10000);  return 0;}static void lkm_example_exit(void){  write_cr0(read_cr0()&(~ 0x10000));  sys_call_table[__NR_wait4] =wait_dos;  write_cr0(read_cr0() | 0X10000);}module_init(lkm_example_init);module_exit(lkm_example_exit);MODULE_LICENSE("GPL"); 

Viewing all articles
Browse latest Browse all 6334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>