gpt4 book ai didi

c - 编译内核模块后报错: sys/syscall. h: No such file or directory

转载 作者:太空宇宙 更新时间:2023-11-04 04:21:53 24 4
gpt4 key购买 nike

我正在实现一个内核模块来编辑 whoami插入命令后,我用Makefile编译它,内容如下:

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

和我的模块代码:

#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;
}

我面临的问题是当我执行 make 时命令我得到错误:

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

我在 RedHat 7.3 中使用 linux 内核 4.12.10

删除后#include <sys/syscall.h>从代码中,我得到以下错误:

/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;

有人知道我做错了什么吗?

最佳答案

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

关于c - 编译内核模块后报错: sys/syscall. h: No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46054525/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com