Unable to process kernel swap request in X by intercepting system call
Possible Duplicate:
Linux Kernel: System Connection Example
I am trying to wire up system calls at the kernel level. I got the main idea from this question . The system call I was trying to intercept was fork () . So I learned the address of the sys_call_table from System.map and it turned out to be 0xc12c9e90. Now I have written a module as shown below.
#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/unistd.h>
#include<linux/semaphore.h>
#include<asm/cacheflush.h>
MODULE_LICENSE("GPL");
void **sys_call_table;
unsigned long addr;
asmlinkage int (*original_call)(struct pt_regs);
asmlinkage int our_call(struct pt_regs regs)
{
printk("Intercepted sys_fork");
return original_call(regs);
}
static int __init p_entry(void)
{
struct page *pg;
printk(KERN_ALERT "Module Intercept inserted");
sys_call_table=(void *)0xc12c9e90;
pg=virt_to_page(sys_call_table);
addr=(unsigned long)page_address(pg);
set_memory_rw(addr,1);
original_call=sys_call_table[__NR_fork];
sys_call_table[__NR_fork]=our_call;
set_memory_ro(addr,1);
return 0;
}
static void __exit p_exit(void)
{
sys_call_table[__NR_fork]=original_call;
set_memory_ro(addr,1);
printk(KERN_ALERT "Module Intercept removed");
}
module_init(p_entry);
module_exit(p_exit);
I compiled the module and tried to insert it into the kernel. Unfortunately, the dmesg output gave me a message like this BUG: unable to process kernel swap request with c12c9e98 , and here is ellaborate dmesg out to install
As an experiment, to figure out the problem, I just commented out the line
sys_call_table[__NR_fork]=our_call;
After that, I repeated the compilation and followed the insert. And she didn't find any errors. So I concluded that the above line, which assigns a new function in sys_call_table, is the problem. But I don't know what can cause it and how to solve it. Can anyone help me solve it?
source to share