免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3176 | 回复: 8
打印 上一主题 下一主题

insmod后显示Segmentation fault无法rmmod,请前辈指点~在线等 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-03-09 15:59 |只看该作者 |倒序浏览
insmod后显示Segmentation fault无法rmmod
一直提示ERROR: Module test is in use
这是社么原因啊,郁闷~~~
请各位前辈指点~
[root@localhost modules]# insmod test.ko
Segmentation fault
[root@localhost modules]# lsmod
Module                  Size  Used by
test                    5939  1
iptable_filter          6721  0
ip_tables              20929  1 iptable_filter
md5                     8001  1
ipv6                  235105  12
dm_mod                 56773  0
button                 10449  0
battery                12485  0
ac                      8773  0
uhci_hcd               32729  0
ehci_hcd               31941  0
8139too                27329  0
mii                     8641  1 8139too
floppy                 57297  0
ext3                  117961  3
jbd                    59353  1 ext3

论坛徽章:
0
2 [报告]
发表于 2006-03-09 16:04 |只看该作者
module代码有问题。

论坛徽章:
0
3 [报告]
发表于 2006-03-09 16:12 |只看该作者
我第一次写希望各位前辈不要扔鸡蛋~~帮我看看程序中有社么问题
谢谢了!!!
CODE:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/unistd.h>
#include <linux/slab.h>
MODULE_LICENSE("GPL");
unsigned long *sys_call_table=NULL;
#define __NR_used 233
static  int(*anything_saved)(void);
#define CALLOFF 100
struct descriptor_idt
{
        unsigned short offset_low;
        unsigned short sel;
        unsigned short none,flags;
        unsigned short offset_high;
};
static struct
{
        unsigned short limit;
        unsigned long base;
}__attribute__((packed)) idtr;


unsigned long *getscTable(void){
        unsigned sys_call_off;
        unsigned sct;
        char *p;
        struct descriptor_idt *idt;
        unsigned short offset_low,offset_high;
        unsigned char *shell,*sort;
        int i;

        /*get idtr*/
        __asm__ ("sidt %0" : "=m" (idtr));
        printk("idtr base at 0x%X\n",(int)idtr.base);

       
        idt=(struct descriptor_idt*)(idtr.base+8*0x80);
        offset_low = idt->offset_low;
       offset_high = idt->offset_high;
        sys_call_off=(idt->offset_high<<16)|idt->offset_low;
       
        shell=(char *)sys_call_off;
       sort="\xff\x14\x85";
                                                                                                                              
        /* get the address of sys_call_table */
   
        for(i=0;i<CALLOFF;i++)
                if(shell[0]==sort[0]&&shell[i+1]==sort[1]&&shell[i+2]==sort[2])
                        break;                                                                                                

        p=shell;
       p+=3;
       sct=*(unsigned long*)p;
        return (unsigned long*)sct;

}

static int sys_used(void){
        printk("hello word!!");
        return 0;
}
static int __init used_init(void){
        sys_call_table = getscTable();
        anything_saved=(int(*)(void))sys_call_table[__NR_used];
        sys_call_table[__NR_used]=(unsigned long)sys_used;
        return 0;
}

static void __exit used_cleanup(void){
        sys_call_table[__NR_used]=(unsigned long)anything_saved;
}

module_init(used_init);
module_exit(used_cleanup);

论坛徽章:
0
4 [报告]
发表于 2006-03-09 23:20 |只看该作者
程序有问题,自己检查下吧,printk

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
5 [报告]
发表于 2006-03-10 07:20 |只看该作者
在xfocus上看到的.2.6内核导出syscall_table的代码


  1. #ifndef __SYSCALL_INCLUDE__
  2. # define __SYSCALL_INCLUDE__
  3. #endif
  4. #ifdef MODVERSIONS
  5. #include <linux/modversions.h>
  6. #endif
  7. #include <linux/module.h>
  8. #include <linux/kernel.h>
  9. MODULE_LICENSE("GPL");
  10. MODULE_AUTHOR("xinhe <xinhe007@163.com>");
  11. MODULE_DESCRIPTION("export the sys_call_table");
  12. #if !defined(symname)
  13. #error symname not defined
  14. #endif
  15. #define CALLOFF 100
  16. unsigned symname; /* #define */
  17. struct {
  18. unsigned short limit;
  19. unsigned int base;
  20. } __attribute__ ((packed)) idtr;

  21. struct {
  22. unsigned short off1;
  23. unsigned short sel;
  24. unsigned char none,
  25. flags;
  26. unsigned short off2;
  27. } __attribute__ ((packed)) * idt;

  28. void set_symbol_addr(unsigned old_value, unsigned new_value)
  29. {
  30.   struct module *mod;
  31.   struct kernel_symbol *s;
  32.   int i;
  33.   for (mod = THIS_MODULE, s = mod->syms, i = 0; i < mod->num_syms; ++i, ++s)
  34.   if (s->value == old_value)
  35.   {
  36.     s->value = new_value;
  37.     return;
  38.   }
  39.   /*遍历本模块的符号表,把本模块的一个也叫sys_call_table的符号的地址
  40.      设置为系统真正的sys_call_table的实际地址。 */
  41. }

  42. char * findoffset(char *start)
  43. {
  44.   char *p;
  45.   for (p = start; p < start + CALLOFF; p++)
  46.   if (*(p + 0) == '\xff' && *(p + 1) == '\x14' && *(p + 2) == '\x85')
  47.    return p;
  48.   /*查找ini 80处理函数对sys_call_table的引用*/
  49.   return NULL;
  50. }

  51. static int __init init(void)
  52. {
  53.   unsigned sys_call_off;
  54.   unsigned sct;
  55.   char *p;
  56.   asm("sidt %0":"=m"(idtr));
  57.   idt = (void *) (idtr.base + 8 * 0x80);
  58.   sys_call_off = (idt->off2 << 16) | idt->off1;
  59.   /*查找int 80的入口地址*/
  60.   if ((p = findoffset((char *) sys_call_off)))
  61.   {
  62.    sct = *(unsigned *) (p + 3);
  63.    set_symbol_addr((unsigned) &symname, sct);
  64.   }
  65.   EXPORT_SYMBOL(sys_call_table);
  66.   return 0;
  67. }

  68. static void __exit fini(void)
  69. {
  70. }
  71. module_init(init);
  72. module_exit(fini);
复制代码

希望对你有所帮助.

论坛徽章:
0
6 [报告]
发表于 2006-03-10 10:26 |只看该作者
谢谢~~

论坛徽章:
0
7 [报告]
发表于 2006-03-10 11:08 |只看该作者

回复 5楼 mq110 的帖子

你好,我刚用您复制来的那段代码测试了一下
并且在init 和exit的部分加了两个printk,但是 make的时候出现了两个warning,warning如下
/root/pub/test/example.c: In function `set_symbol_addr':
/root/pub/test/example.c:35: warning: assignment discards qualifiers from pointer target type
/root/pub/test/example.c: In function `init':
/root/pub/test/example.c:69: warning: ISO C90 forbids mixed declarations and code
您能告诉我是什么原因导致warning的吗??谢谢

论坛徽章:
0
8 [报告]
发表于 2006-03-10 11:16 |只看该作者
line35:for (mod = THIS_MODULE, s = mod->syms, i = 0; i < mod->num_syms; ++i, ++s)
line69:EXPORT_SYMBOL(sys_call_table);

论坛徽章:
0
9 [报告]
发表于 2006-06-13 14:38 |只看该作者
上面的代码编译出错啊!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP