简体   繁体   中英

Error after compiling kernel module: sys/syscall.h: No such file or directory

I am implementing a kernel module that edits the whoami command after being inserted, I am compiling it with a Makefile which content is as follows:

obj-m+=holamundo.o
obj-m+=acumulador.o
obj-m+=cliente.o
obj-m+=intercept.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
    make -C /lib/modules/$(shell uname -r )/build M=$(PWD) clean

and my module code:

#define MODULE
#define __KERNEL__
#include <linux/module.h>
#include <linux/kernel.h>
#include </usr/src/kernels/linux/arch/x86/include/asm/unistd.h>
#include <asm/unistd.h>
#include <linux/unistd.h>
#include <linux/syscalls.h>
#include <sys/syscall.h>
#include <asm/fcntl.h>
#include <asm/errno.h>
#include <linux/types.h>
#include <linux/dirent.h>
#include <linux/mman.h>
#include <linux/string.h>
#include <linux/fs.h>

extern void *sys_call_table[];
int (*orig_geteuid)(const char *path);

int hacked_geteuid(const char *path) {
return 78;
}

int init_module(void) {

orig_geteuid = sys_call_table[SYS_geteuid32];

sys_call_table[SYS_geteuid32] = hacked_geteuid;
return 0;

}

void cleanup_module(void) {
    sys_call_table[SYS_geteuid32] = orig_geteuid;
}

The problem I am facing is when I execute the make command I get the error:

/usr/src/kernels/intercept.c:9:25: fatal error: sys/syscall.h: No such file or directory

I am using the linux kernel 4.12.10 in RedHat 7.3

After removing #include <sys/syscall.h> from the code, I get the following error:

/usr/src/kernels/intercept.c:27:31: error: ‘SYS_geteuid32’ undeclared (first use in this function)
 orig_geteuid = sys_call_table[SYS_geteuid32];
                               ^
/usr/src/kernels/intercept.c:27:31: note: each undeclared identifier is reported only once for each function it appears in
/usr/src/kernels/intercept.c: In function ‘cleanup_module’:
/usr/src/kernels/intercept.c:35:17: error: ‘SYS_geteuid32’ undeclared (first use in this function)
  sys_call_table[SYS_geteuid32] = orig_geteuid;

Does anybody know what I am doing wrong ?

您要查找的常量是__NR_geteuid ,它在asm/unistd.h定义。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM