发新话题
打印

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

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

最近我也在试图截获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;
}      

TOP

printk("filename=%s\n",[COLOR="Red"]*[/COLOR] filename)
。。。。。。笔误?      
上帝说,有问题,找GOOGLE 写程序是很神圣的事情!同样只是装系统,卖菜的大娘会的事情不见得就跟卖菜一样了。

TOP

发新话题