红联Linux门户
Linux帮助

诡异:内核模块只能正确用两个参数?传第3个参数就空了

发布时间:2013-01-16 12:29:35来源:红联作者:
有一个模块叫GCI.ko,它export出来三个GCIReg、GCIStatNew、GCICtlNew函数
原型分别是
GCIHandle *GCIReg(char *moduleName)
GCICtlHandle *GCICtlNew(GCIHandle *moduleHandle, char *ctlFileName, GCICtlCmd *cmdTable, void *privData)
GCIStatHandle *GCIStatNew(GCIHandle *moduleHandle, char *statFileName, GCIStatDesc *descTable)

现在在Ipdb模块里调用它们
首先声明模块参数
26 static char *mod_name = "IPDB";
27 static char *ctl_file_name = "Control";
28 static char *stat_file_name = "Stat";
29 static void * cm_get_net_entity = CMGetNetEntity;


1598 module_param(mod_name, charp, S_IRUGO);
1599 module_param(ctl_file_name, charp, S_IRUGO);
1600 module_param(stat_file_name, charp, S_IRUGO);
1601 module_param(cm_get_net_entity, charp, S_IRUGO);

module_init(IPDB_init_module) 里的代码片段
106 GuardNotify(mod_name, GUARD_LOG_ERROR, NOPKT,
107 "before GCIReg (0x%x:%s)\n",
108 mod_name, mod_name);
109 GCI_h = GCIReg(mod_name);

116
117 GuardNotify(mod_name, GUARD_LOG_ERROR, NOPKT,
118 "before GCICtlNew (0x%x: %s) %s \n",
119 ctl_file_name, ctl_file_name, mod_name);
120 GCI_Ctl_h = GCICtlNew(GCI_h, ctl_file_name, cmds, NULL);

122 GuardNotify(mod_name, GUARD_LOG_ERROR, NOPKT,
123 "before GCIStatNew (0x%x: %s) %s\n",
124 stat_file_name, stat_file_name, mod_name);
125 GCI_Stat_h = GCIStatNew(GCI_h, stat_file_name, statDesc) ;

insmod时,模块被kill,dmesg打印出来的信息如下:
[ 350.756636] <1>GUARD ERR IPDB PKT ffffffff: before GCIReg (0xf7ffb924:IPDB)
[ 350.756641] <1>GUARD ERR GCI PKT ffffffff: registering GCIReg (0xf7ffb924:IPDB)
[ 350.756651] <1>GUARD ERR IPDB PKT ffffffff: before GCICtlNew (0xf7ffb929: Control) IPDB
[ 350.756654] <1>GUARD DBG GCI PKT ffffffff: creating ctl file (0xf7ffb929: Control) for module IPDB
[ 350.756657] <1>GUARD ERR IPDB PKT ffffffff: before GCIStatNew (0xf7ffb973: Stat) IPDB
[ 350.756660] <1>GUARD DBG GCI PKT ffffffff: creating stat file (0x46: (null)) for module IPDB
[ 350.756670] BUG: unable to handle kernel NULL pointer dereference at 00000046


如果把GCIStatNew挪到GCICtlNew前边调用,insmod时,模块被kill,dmesg打印出来的信息如下:
[ 170.913746] <1>GUARD ERR IPDB PKT ffffffff: before GCIReg (0xf807b924:IPDB)
[ 170.913751] <1>GUARD ERR GCI PKT ffffffff: registering GCIReg (0xf807b924:IPDB)
[ 170.913757] <1>GUARD ERR IPDB PKT ffffffff: before GCIStatNew (0xf807b929: Stat) IPDB
[ 170.913760] <1>GUARD DBG GCI PKT ffffffff: creating stat file (0xf807b929: Stat) for module IPDB
[ 170.913764] <1>GUARD ERR IPDB PKT ffffffff: before GCICtlNew (0xf807b947: Control) IPDB
[ 170.913767] <1>GUARD DBG GCI PKT ffffffff: creating ctl file (0x46: (null)) for module IPDB
[ 170.913776] BUG: unable to handle kernel NULL pointer dereference at 00000046

就是说传入前两个参数都是对的,传入第三个参数时,传入为空,传进去后它地址就变成0x46:
上网查,说是一个模块能传入30个参数,有的人说能传入70个参数,我这个问题是只能传两个参数
同样的我在insmod 时自己填参数也是这个问题
代码中直接传字符串也是这个问题。

请大侠帮忙看看啊,很诡异的问题啊。谢谢谢谢!
文章评论

共有 1 条评论

  1. spworks 于 2013-01-16 16:34:49发表:

    帮顶下