我正在尝试编写一些简单的测试代码作为挂钩系统调用表的演示.
"sys_call_table"不再在2.6中导出,所以我只是从System.map文件中获取地址,我可以看到它是正确的(通过我发现的地址查看内存,我可以看到指向系统调用).
但是,当我尝试修改此表时,内核给出"Oops","无法在虚拟地址c061e4f4处理内核分页请求"并且机器重新启动.
这是运行2.6.18-164.10.1.el5的CentOS 5.4.是否有某种保护或我只是有一个错误?我知道它带有SELinux,我已经尝试将它放入许可模式,但它并没有什么区别
这是我的代码:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/unistd.h>
void **sys_call_table;
asmlinkage int (*original_call) (const char*, int, int);
asmlinkage int our_sys_open(const char* file, int flags, int mode)
{
printk("A file was opened\n");
return original_call(file, flags, mode);
}
int init_module()
{
// sys_call_table address in System.map
sys_call_table = (void*)0xc061e4e0;
original_call = sys_call_table[__NR_open];
// Hook: Crashes here
sys_call_table[__NR_open] = our_sys_open;
}
void cleanup_module()
{
// Restore the original call
sys_call_table[__NR_open] = original_call;
}
Run Code Online (Sandbox Code Playgroud)