为什么我的模块插入内核 报 killed?
#include <linux/kernel.h>#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <asm/unistd.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("xunil@bmy");
MODULE_DESCRIPTION("Different from others, this module automatically locate the entry ofsys_call_table !");
unsigned long *sys_call_table=NULL;
asmlinkage int (*orig_mkdir)(const char *,int);
struct _idt
{
unsigned short offset_low;
unsigned short segment_sel;
unsigned char reserved;
unsigned char flags;
unsigned short offset_high;
};
unsigned long *getscTable(){
unsigned char idtr,*shell,*sort;
struct _idt *idt;
unsigned long system_call,sct;
unsigned short offset_low,offset_high;
char *p;
int i;
/* get the interrupt descriptor table */
__asm__("sidt %0" : "=m" (idtr));
/* get the address of system_call */
idt=(struct _idt*)(*(unsigned long*)&idtr+8*0x80);
offset_low = idt->offset_low;
offset_high = idt->offset_high;
system_call=(offset_high<<16)|offset_low;
shell=(char *)system_call;
sort="\xff\x14\x85";
/* get the address of sys_call_table */
for(i=0;i<(100-2);i++)
if(shell==sort&&shell==sort&&shell==sort)
break;
p=&shell;
p+=3;
sct=*(unsigned long*)p;
return (unsigned long*)(sct);
}
asmlinkage int hacked_mkdir(const char * pathname, int mode){
printk("PID %d called sys_mkdir !\n",current->pid);
return orig_mkdir(pathname,mode);
}
static intfind_init(void){
sys_call_table = getscTable();
orig_mkdir=(int(*)(const char*,int))sys_call_table;
sys_call_table=(unsigned long)hacked_mkdir;
printk("<1>start--------------------------------------");
return 0;
}
static void find_cleanup(void){
sys_call_table=(unsigned long)orig_mkdir;
}
module_init(find_init);
module_exit(find_cleanup);
编译没有问题,就是insmod 的时候报 killed! 又在劫持系统调用啊。详细的报错信息是什么。 回复 2# Godbach
如果报错了还好,就是编译什么都没有报,就说KIlled了! 回复 3# liuxuejin
搞定了,你的代码也可以在新的内核里用! 2。6。30 那里 是什么原因,和大家分享一下啊。 怎么搞定的分享一下啊 楼主这个很有趣, 我在kernel 4.1上直接hang住了.
应该是 __asm__("sidt %0" : "=m" (idtr));这句汇编的搞的什么鬼...
页:
[1]