当前位置: 技术问答>linux和unix
关于系统函数重载
来源: 互联网 发布时间:2017-01-06
本文导语: 比如我重载 chdir asmlinkage int (* orig_chdir)(const char *path); 只要我返回错误代码 -1 -2 这种 就会出这样的问题 [36113.544621] BUG: unable to handle kernel NULL pointer dereference at (null) [36113.544625] IP: [] get_fullname+0xd7/0x...
比如我重载 chdir
只要我返回错误代码 -1 -2 这种 就会出这样的问题
get_fullname是这么写的。。。
不知道 怎么改 能正常
asmlinkage int (* orig_chdir)(const char *path);
只要我返回错误代码 -1 -2 这种 就会出这样的问题
[36113.544621] BUG: unable to handle kernel NULL pointer dereference at (null)
[36113.544625] IP: [] get_fullname+0xd7/0x1f0 [GetModule]
[36113.544632] *pde = 1fb4f067 *pte = 00000000
[36113.544635] Oops: 0002 [#16] SMP
[36113.544638] last sysfs file: /sys/devices/pci0000:00/0000:00:11.0/0000:02:03.0/local_cpus
[36113.544641] Modules linked in: GetModule(P) binfmt_misc acpiphp snd_ens1371 gameport snd_ac97_codec ac97_bus snd_pcm_oss snd_mixer_oss snd_pcm snd_seq_dummy snd_seq_oss snd_seq_midi snd_rawmidi snd_seq_midi_event fbcon tileblit font bitblit softcursor snd_seq psmouse serio_raw ppdev snd_timer snd_seq_device parport_pc snd vga16fb vgastate soundcore snd_page_alloc lp shpchp intel_agp i2c_piix4 agpgart parport floppy pcnet32 mii mptspi mptscsih mptbase scsi_transport_spi [last unloaded: GetModule]
[36113.544672]
[36113.544675] Pid: 25993, comm: bash Tainted: P D (2.6.32-34-generic #77-Ubuntu) VMware Virtual Platform
[36113.544681] EIP: 0060:[] EFLAGS: 00210206 CPU: 1
[36113.544683] EIP is at get_fullname+0xd7/0x1f0 [GetModule]
[36113.544685] EAX: dfb11b6e EBX: 00000000 ECX: 0000001e EDX: dfb11b50
[36113.544687] ESI: df597d1c EDI: dfb11c50 EBP: dfb11d60 ESP: dfb11b44
[36113.544688] DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068
[36113.544691] Process bash (pid: 25993, ti=dfb10000 task=d65fcc80 task.ti=dfb10000)
[36113.544692] Stack:
[36113.544693] dfb11e74 093184a8 00000000 6d6f682f 6d652f65 6e61687a 72702f67 63656a6f
[36113.544698] 65742f74 616c706d 00006574 00000000 00000000 00000000 00000000 00000000
[36113.544704] 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[36113.544709] Call Trace:
[36113.544714] [] ? hacked_chdir+0x90/0x100 [GetModule]
[36113.544815] [] ? tty_ldisc_deref+0xd/0x10
[36113.544818] [] ? change_termios+0x195/0x2c0
[36113.544825] [] ? _spin_lock+0xd/0x10
[36113.544879] [] ? __d_lookup+0x102/0x110
[36113.544882] [] ? dput+0x91/0x130
[36113.544919] [] ? path_to_nameidata+0x1e/0x50
[36113.544922] [] ? __link_path_walk+0x632/0xca0
[36113.544925] [] ? copy_to_user+0x39/0x130
[36113.544928] [] ? copy_termios+0x35/0x50
[36113.544931] [] ? mntput_no_expire+0x1f/0xe0
[36113.544935] [] ? syscall_call+0x7/0xb
[36113.544937] Code: fe ff ff 8d 85 f0 fd ff ff e8 c6 68 75 df 8b 5b 1c 85 db 75 a7 8d 85 f0 fd ff ff 31 db e8 62 6a 75 df 8d 95 f0 fd ff ff 8d 04 02 03 8b 85 e8 fd ff ff 8b 95 e8 fd ff ff 83 c0 01 89 85 ec fd
[36113.544968] EIP: [] get_fullname+0xd7/0x1f0 [GetModule] SS:ESP 0068:dfb11b44
[36113.544971] CR2: 0000000000000000
[36113.544974] ---[ end trace 847fe2f82bcb0ca1 ]---
get_fullname是这么写的。。。
void get_fullname(const char *pathname,char *fullname)
{
struct dentry *tmp_dentry = current->fs->pwd.dentry;
char *p;
char tmp_path[MAX_LENGTH];
char local_path[MAX_LENGTH];
memset(tmp_path,0,MAX_LENGTH);
memset(local_path,0,MAX_LENGTH);
if (*pathname == '/') {
strcpy(fullname,pathname);
return;
}
while (tmp_dentry != NULL)
{
if (!strcmp(tmp_dentry->d_iname,"/"))
break;
strcpy(tmp_path,"/");
strcat(tmp_path,tmp_dentry->d_iname);
strcat(tmp_path,local_path);
strcpy(local_path,tmp_path);
tmp_dentry = tmp_dentry->d_parent;
}
// strcpy(fullname,local_path);
// strcat(fullname,"/");
// strcat(fullname,pathname);
*p = local_path + strlen(local_path);
while (1){
if ( *pathname++ == '.' && *pathname++ == '.' ){
if ( *pathname == '/' ){
pathname++;
while( *p != '/' && p != NULL){
p--;
}
// p = rindex(local_path,'/');
memset(p,0,strlen(p));
} else { break; }
} else { break; }
}
strcpy(fullname,local_path);
strcat(fullname,"/");
strcat(fullname,pathname);
return;
}
不知道 怎么改 能正常
|
EIP is at get_fullname+0xd7/0x1f0 [GetModule]
这个地方出错了阿,根据这个你就可以定位错误在哪一行了阿,
用gcc -g 编译你的模块
然后gdb + 模块名
然后输入
info line *get_fullname+0xd7
就会提示你这个空指针的操作是在源码的哪一行了, 我猜你是没检查输入参数。
这个地方出错了阿,根据这个你就可以定位错误在哪一行了阿,
用gcc -g 编译你的模块
然后gdb + 模块名
然后输入
info line *get_fullname+0xd7
就会提示你这个空指针的操作是在源码的哪一行了, 我猜你是没检查输入参数。