LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 981|回复: 1

求助,拦截execve()系统调用段错误问题

[复制链接]
发表于 2007-5-18 22:22:00 | 显示全部楼层 |阅读模式
最近我也在试图截获execve()系统调用,但是编写的模块加载后显示段错误,找不出原因,求大家帮帮

忙:)

我的内核版本是2.4.7-10的,在RedHat7.2的平台下

我参考过以前的一篇帖子《截获execve系统调用,为什么出现“段错误”》,帖子的地址:

http://bbs.chinaunix.net/viewthread.php?tid=593811

我的目的是截获 execve()系统调用和它的所有参数,并设置标志 i ,若 i=-1 ,

则不执行这次系统调用,若 i=0 则执行。

以下是我的代码:

#ifndef MODULE
#define MODULE
#endif
#ifndef __KERNEL__
#define __KERNEL__
#endif

#include <linux/module.h>
#include <linux/kernel.h>
#include <asm/unistd.h>
#include <sys/syscall.h>
#include <linux/types.h>
#include <linux/dirent.h>
#include <linux/string.h>
#include <linux/fs.h>
#include <linux/slab.h>  
#include <linux/init.h>
#include <linux/string.h>

extern void* sys_call_table[];        /* we can access sys_call_table  */
int (*orig_execve)(struct pt_regs regs); //the execve origin syscall

int check_exec(struct pt_regs regs)
{//use this funtion capture the execve system call
               
        int error=0;
        char *filename=NULL,**argv;
        filename=getname((char *)regs.ebx);
        argv=(char *)regs.ecx;
        printk("filename=%s\n",* filename);//尝试着先打印一个参数--文件名试试


       
        error=do_execve(filename,(char **)regs.ecx,(char **)regs.edx,&regs);
                return error;
}

int init_module()
{
        orig_execve=sys_call_table[SYS_execve];        // save origin system call
        sys_call_table[SYS_execve]=check_exec;        // check_exec replace SYS_execve
        return 0;
}

int cleanup_modules()
{
        //这个函数我现在还没有写代码,基本上是乱写的,主要想先截获它的参数
        sys_call_table[SYS_execve]=orig_execve;        //set back syscall to orig_exec
        return 0;
}
发表于 2007-6-7 13:41:02 | 显示全部楼层
先别忙着printk,先看看getname 有没有失败
if (IS_ERR(filename))

另外putname没有调用。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表