内核模块系统调用覆盖

时间:2016-05-01 17:37:07

标签: c linux linux-kernel archlinux

我正试图覆盖4.5.1-1-ARCH上的开放系统调用,运气不佳。我没有错误,但是从不调用custom_open函数,所以它实际上没有被覆盖。

代码:

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/kallsyms.h>
#include <asm/unistd.h>
#include <linux/uaccess.h>

MODULE_LICENSE("GPL");

static void **sys_call_table = NULL;

static asmlinkage long (*old_open) (const char __user *filename, int flags, umode_t mode);

static asmlinkage long custom_open(const char __user *filename, int flags, umode_t mode)
{
      printk(KERN_INFO "Custom open invoked");

      return old_open(filename, flags, mode);
}

static int init(void)
{
    sys_call_table = (void *)kallsyms_lookup_name("sys_call_table");
    pr_info("sys_call_table address: %p\n", sys_call_table);

    old_open = sys_call_table[__NR_open];
    sys_call_table[__NR_open] = custom_open;

    pr_info("Original open: %p; New open: %p\n", old_open, custom_open);

    return 0;
}

static void exit(void)
{
        pr_info("exit");
        sys_call_table[__NR_open] = old_open;
}

module_init(init);
module_exit(exit);

加载模块后,我在dmesg中得到以下内容:

[ 8027.331315] sys_call_table address: f97fe204
[ 8027.331320] Original open:   (null); New open: f97fc000

1 个答案:

答案 0 :(得分:1)

您声明了一个本地符号sys_call_table。

难道你不认为旧的开放是空的吗?更有趣的是,sys_call_table符号的找到地址与custom_open的地址相差不远。这是一个强烈的暗示,你发现的是你自己的sys_call_table符号的地址。'

你想要达到什么目标?

作为附注,我刚刚确认支持syscall表的页面是以只读方式映射的,所以如果仅仅写入没有使内核崩溃,那么你知道你没有找到它。

编辑:

所以,我检查了arch配置,本地查找可能是CONFIG_KALLSYMS_ALL未设置的副作用。这也意味着kallsyms将无法找到你想要的符号,但这并不重要。

http://maitesin.github.io/Module_prank/处的模块质量不合格,不得使用。我前段时间遇到过这个问题并解释了这里的主要缺陷:https://www.reddit.com/r/programming/comments/4b757p/linux_kernel_module_example_rickroll_prank/d16q5v5

由于你只是在玩,这种活动没用,特别是在这个阶段。我只能建议你暂时坚持用户空间。

相关问题