[英]Change address of kernel function pointer
我编写了一个模块,尝试在调用原始do_fork地址之前,先更改导出符号'do_fork'的地址以指向我的函数。 到目前为止,我似乎无法更改地址,因为它给了我错误“需要左值作为赋值的左操作数”。
我不确定如何将指向do_fork()的指针更改为我的函数fake_fork();
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/sched.h>
#include <linux/module.h>
int c=0;
long fake_fork(unsigned long a, unsigned long b, unsigned long c, int __user *d, int __user *e)
{
++c;
return do_fork(a, b, c, d, e);
}
EXPORT_SYMBOL(fake_fork);
static int fork_proc_show(struct seq_file *m, void *v)
{
seq_printf(m, "System Call fork called: %d times.\n", c);
return 0;
}
static int fork_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, fork_proc_show, NULL);
}
static const struct file_operations fork_proc_fops = {
.open = fork_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int __init proc_fork_init(void)
{
do_fork = fake_fork; // <-- Not working
printk("init proc forkcounter\n");
proc_create("forkcounter", 0, NULL, &fork_proc_fops);
return 0;
}
static void __exit cleanup_fork_module(void)
{
remove_proc_entry("forkcounter",NULL);
printk("cleanup proc forkcounter\n");
}
module_init(proc_fork_init);
module_exit(cleanup_fork_module);
您不能更改do_fork
,它在运行时是一个常数。 它是do_fork()
函数的地址。
您不能为函数分配任何内容。 这是因为函数的名称不是变量。 它是一个常量指针。
与...相同
5 = 2 + 2;
您将收到相同的错误消息。
我假设您希望您的函数在每次调用do_fork()
被调用。 实现起来会更加复杂。 我将从这个链接开始 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.