Как я могу избежать ошибки при загрузке модуля для обработки open ()? - PullRequest
0 голосов
/ 23 апреля 2019

Я пытаюсь загрузить следующий код:

#include <linux/module.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <asm/uaccess.h>

extern void *sys_call_table[];
int (*orig_open)(const char *pathname, int flag, int mode);

int own_open(const char *pathname, int flag, int mode)
{
    char *kernel_path;
    char hide[]="test.txt";

    kernel_path=(char *)kmalloc(255,GFP_KERNEL);
    copy_from_user(kernel_path, pathname, 255);

    if(strstr(kernel_path,(char *)&hide) != NULL) {

    kfree(kernel_path);
    return -ENOENT;
    }

    else {

    kfree(kernel_path);
    return orig_open(pathname, flag, mode);
    }
}
int init_module()
{
    orig_open=sys_call_table[SYS_open];
    sys_call_table[SYS_open]=own_open;
    return 0;
}

void cleanup_module()
{
    sys_call_table[SYS_open]=orig_open;
}

но в результате я получил ошибки:

sys_open_call.c:34:30: error: ‘__NR_open’ undeclared (first use in this function)
     orig_open=sys_call_table[SYS_open];
                              ^

sys_open_call.c: In function ‘cleanup_module’:
sys_open_call.c:41:20: error: ‘__NR_open’ undeclared (first use in this function)
     sys_call_table[SYS_open]=orig_open;
                    ^

make: *** [sys_open_call.o] Error 1

Как я могу это объявить?

...