Chinaunix

标题: 为什么我的模块插入内核 报 killed? [打印本页]

作者: liuxuejin    时间: 2010-05-15 12:33
标题: 为什么我的模块插入内核 报 killed?
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/init.h>
  4. #include <linux/sched.h>
  5. #include <asm/unistd.h>

  6. MODULE_LICENSE("GPL");
  7. MODULE_AUTHOR("xunil@bmy");
  8. MODULE_DESCRIPTION("Different from others, this module automatically locate the entry ofsys_call_table !");

  9. unsigned long *sys_call_table=NULL;
  10. asmlinkage int (*orig_mkdir)(const char *,int);


  11. struct _idt
  12. {
  13. unsigned short offset_low;
  14. unsigned short segment_sel;
  15. unsigned char reserved;
  16. unsigned char flags;
  17. unsigned short offset_high;
  18. };

  19. unsigned long *getscTable(){
  20.         unsigned char idtr[6],*shell,*sort;
  21.         struct _idt *idt;
  22.         unsigned long system_call,sct;
  23.         unsigned short offset_low,offset_high;
  24.         char *p;
  25.         int i;


  26.         /* get the interrupt descriptor table */


  27.         __asm__("sidt %0" : "=m" (idtr));


  28.         /* get the address of system_call */
  29.         idt=(struct _idt*)(*(unsigned long*)&idtr[2]+8*0x80);
  30.         offset_low = idt->offset_low;
  31.         offset_high = idt->offset_high;
  32.         system_call=(offset_high<<16)|offset_low;


  33.         shell=(char *)system_call;
  34.         sort="\xff\x14\x85";


  35.         /* get the address of sys_call_table */

  36.         for(i=0;i<(100-2);i++)
  37.                 if(shell[i]==sort[0]&&shell[i+1]==sort[1]&&shell[i+2]==sort[2])
  38.                         break;

  39.         p=&shell[i];
  40.         p+=3;
  41.         sct=*(unsigned long*)p;

  42.         return (unsigned long*)(sct);
  43. }

  44. asmlinkage int hacked_mkdir(const char * pathname, int mode){
  45.         printk("PID %d called sys_mkdir !\n",current->pid);
  46.         return orig_mkdir(pathname,mode);
  47. }

  48. static int  find_init(void){
  49.         sys_call_table = getscTable();
  50.         orig_mkdir=(int(*)(const char*,int))sys_call_table[__NR_mkdir];
  51.         sys_call_table[__NR_mkdir]=(unsigned long)hacked_mkdir;
  52.         printk("<1>start--------------------------------------");
  53.         return 0;
  54. }

  55. static void find_cleanup(void){
  56.         sys_call_table[__NR_mkdir]=(unsigned long)orig_mkdir;
  57. }

  58. module_init(find_init);
  59. module_exit(find_cleanup);
复制代码
编译没有问题,就是insmod 的时候  报 killed!
作者: Godbach    时间: 2010-05-15 14:18
又在劫持系统调用啊。详细的报错信息是什么。
作者: liuxuejin    时间: 2010-05-15 19:38
回复 2# Godbach


    如果报错了还好,就是编译什么都没有报,就说KIlled了!
作者: liuxuejin    时间: 2010-05-15 23:07
回复 3# liuxuejin
搞定了,你的代码也可以在新的内核里用! 2。6。30 那里
作者: Godbach    时间: 2010-05-17 10:24
是什么原因,和大家分享一下啊。
作者: lulusunnydays    时间: 2015-06-10 10:47
怎么搞定的分享一下啊
作者: firocu    时间: 2015-06-12 17:03
楼主这个很有趣, 我在kernel 4.1上直接hang住了.
应该是 __asm__("sidt %0" : "=m" (idtr));这句汇编的搞的什么鬼...




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2