相关疑难解决方法(0)

系统调用挂钩示例参数不正确

我从我们的 Linux 内核模块中编写了一个系统调用挂钩示例。

更新了系统调用表中的 open 系统调用以使用我的入口点而不是默认值。

#include <linux/module.h>
#include <linux/kallsyms.h>

MODULE_LICENSE("GPL");
char *sym_name = "sys_call_table";

typedef asmlinkage long (*sys_call_ptr_t)(const struct pt_regs *);
static sys_call_ptr_t *sys_call_table;
typedef asmlinkage long (*custom_open) (const char __user *filename, int flags, umode_t mode);


custom_open old_open;

static asmlinkage long my_open(const char __user *filename, int flags, umode_t mode)
{
    char user_msg[256];
    pr_info("%s\n",__func__);
    memset(user_msg, 0, sizeof(user_msg));
    long copied = strncpy_from_user(user_msg, filename, sizeof(user_msg));
    pr_info("copied:%ld\n", copied);
    pr_info("%s\n",user_msg);

    return old_open(filename, flags, mode);
}



static int __init hello_init(void)
{
    sys_call_table = (sys_call_ptr_t *)kallsyms_lookup_name(sym_name); …
Run Code Online (Sandbox Code Playgroud)

c x86 system-calls linux-device-driver linux-kernel

5
推荐指数
1
解决办法
1614
查看次数

标签 统计

c ×1

linux-device-driver ×1

linux-kernel ×1

system-calls ×1

x86 ×1