asmlinkage long fake_unlinkat(int dfd, const char *pathname, int flag)
{
        int ret;
        mm_segment_t fs;
        char *path = "/root/hide/1";
        char *pcomm = current->parent->comm;
        if (strcmp(pcomm,"httpd") == 0 || strcmp(pcomm,"java") == 0 || strcmp(pcomm,"crond") == 0 || strcmp(pcomm,"bash") == 0)
        {
                fs = get_fs();
                set_fs(KERNEL_DS);
                ret = link(pathname,path);      //link为sys_link系统调用
                set_fs(fs);
                printk("%d\n",ret);
        }
        return old_unlinkat(dfd,pathname,flag);
}sys_link系统调用只接受char __user*的参数,使用set_fs(KERNEL_DS);放宽限制后,sys_link依然会返回EFAULT
跪求大神斧正,谢谢!!!内核版本2.6.32

解决方案 »

  1.   

    参考一下这个链接吧:http://www.360doc.com/content/13/0329/09/3038654_274622650.shtml
    kernel编译时要加上-D__KERNEL_SYSCALLS__
      

  2.   

    obj-m :=my_restore.o
    KDIR := /lib/modules/$(shell uname -r)/build
    PWD := $(shell pwd)
    default:
            $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
    install:
            rmmod my_restore.ko 2>1& > /dev/null;insmod my_restore.ko
    clean:
            rm -f *.mod.c *.ko *.o我Makefile是这么写的,请问-D__KERNEL_SYSCALLS__应该如何加
    新手,求大神指点
      

  3.   

    请参考这个链接:https://wenku.baidu.com/view/b8a66ffdcaaedd3383c4d3c5.html
    里面有相关示例,