c - 内核模块编程中的insmod错误

标签 c linux linux-kernel

我刚开始进行模块化编程。

上面是我的两个文件:

你好.c

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

static int hello_init(void)
{
    printk(KERN_ALERT "TEST: Hello world\n");
    return 0;
}

static void hello_exit(void)
{
    printk(KERN_ALERT "TEST: Good Bye");
}

module_init(hello_init);
module_exit(hello_exit);

生成文件

obj-m += hello.o

KDIR = /usr/src/linux-headers-3.13.0-46-generic

all:
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

clean:
    rm -rf *.o *.ko *.mod.* *.symvers *.order

这是我的终端输出,显示 insmod 命令出错,请帮忙。

anubhav@anubhav-Inspiron-3421:~/Desktop/os$ make
make -C /usr/src/linux-headers-3.13.0-46-generic  SUBDIRS=/home/anubhav/Desktop/os modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-46-generic'
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-46-generic'
anubhav@anubhav-Inspiron-3421:~/Desktop/os$ insmod hello.ko
insmod: ERROR: could not insert module hello.ko: Operation not permitted

最佳答案

如果您启用了安全启动,较新的内核将不允许插入任意内核模块。因此,您可以在 BIOS 中禁用安全启动,或者您需要签署要安装的内核模块。

安全签署内核模块的步骤:

  1. 创建一个可以在固件中导入的X509证书
  2. 注册刚刚创建的公钥
  3. 签署您要安装的模块
  4. 安装模块

您需要成为 root 用户才能执行第 2 步和第 4 步。详细过程在 nice Ubuntu blog 中有描述。 .

关于c - 内核模块编程中的insmod错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29036987/

相关文章:

linux - 如何修复 linter-flake8 的 "Spawn EACCES"错误

c - 溢出 scanf ("%8s",字符串)?

c++ - 等同于 Windows 操作系统的 Mac OSX API

linux - 套接字绑定(bind)在一个端口上,但 netstat 和 lsof 等工具显示它在其他端口上监听

linux - Linux 内置驱动加载顺序是什么?

c - 从 proc 获取进程信息

控制内核中的函数指针

c - 优化位标志检查

c++ - 回调函数的应用

php - 无法打开流 : Permission denied in/opt/lampp/htdocs