以下代码(粘贴在最后),主要取自 here , 是一个非常简单的内核模块,充当键盘记录器。我可以让它编译并生成一个 .ko 就好了,但是当我尝试加载它时,我在 dmesg 中收到以下错误:
[ 790.833828] keylogger: Unknown symbol unregister_keyboard_notifier (err 0)
[ 790.833846] keylogger: Unknown symbol register_keyboard_notifier (err 0)
我没有从源代码构建我的内核,而是使用 archlinux 提供的库存内核。但是,我确实安装了内核 header 包来编译模块。
所以我的问题是:我安装的内核中真的没有找到这两个符号吗?如果找到了,为什么它们没有正确链接(?)?
我可以找到符号存在的证据。首先,我可以在 /proc/kallsyms
中看到符号。另外,当我执行 nm/usr/src/vmlinux
时,我也可以看到这两个符号。他们不一样吗?
模块代码:
#include <linux/module.h> /* Needed by all modules */
#include <linux/keyboard.h>
EXPORT_SYMBOL_NOVERS(unregister_keyboard_notifier);
EXPORT_SYMBOL_NOVERS(register_keyboard_notifier);
int hello_notify(struct notifier_block *nblock, unsigned long code, void *_param) {
struct keyboard_notifier_param *param = _param;
struct vc_data *vc = param->vc;
int ret = NOTIFY_OK;
if (code == KBD_KEYCODE) {
printk(KERN_DEBUG "KEYLOGGER %i %s\n", param->value, (param->down ? "down" : "up"));
}
}
static struct notifier_block nb = {
.notifier_call = hello_notify
};
static int hello_init(void)
{
register_keyboard_notifier(&nb);
return 0;
}
static void hello_release(void)
{
unregister_keyboard_notifier(&nb);
}
module_init(hello_init);
module_exit(hello_release);
最佳答案
我需要将以下内容添加到我的模块源中:
MODULE_LICENSE("GPL");
关于linux - 加载我自己的内核模块时出现未知符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13467244/