[英]Change address of kernel function pointer
I'm written a module to try and change the address of the exported symbol 'do_fork' to point to my function first before calling the original do_fork address. 我编写了一个模块,尝试在调用原始do_fork地址之前,先更改导出符号'do_fork'的地址以指向我的函数。 So far I can't seem to change the address as it gives me the error 'lvalue required as left operand of assignment.'
到目前为止,我似乎无法更改地址,因为它给了我错误“需要左值作为赋值的左操作数”。
I'm not sure how to change the pointer to do_fork() to my function fake_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);
You cannot change do_fork
, it is a constant at run time. 您不能更改
do_fork
,它在运行时是一个常数。 It is the address of do_fork()
function. 它是
do_fork()
函数的地址。
You cannot assign anything to a function. 您不能为函数分配任何内容。 It is because name of a function is not a variable.
这是因为函数的名称不是变量。 It is a constant pointer.
它是一个常量指针。
It is the same as 与...相同
5 = 2 + 2;
You would get the same error message. 您将收到相同的错误消息。
I assume you want your function to be called every time do_fork()
is called. 我假设您希望您的函数在每次调用
do_fork()
被调用。 It it going to be more complicated to implement. 实现起来会更加复杂。 I would start for example with this link .
我将从这个链接开始 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.