【问题标题】:insmod error in kernel module programming内核模块编程中的 insmod 错误
【发布时间】:2020-04-26 21:32:48
【问题描述】:

我刚刚开始使用模块化编程。

以上是我的两个文件:

你好.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

【问题讨论】:

  • 只有root 用户通常有权插入/删除内核模块。 suroot,或使用 sudo(如果适用)以 root 身份运行命令。
  • @lsowen 我试过“su”和“su -”。但是在提供密码后,我得到了消息“su:身份验证失败”。任何其他前进的方式
  • 此消息意味着您输入了错误的密码(或者不是允许成为 root 的用户组的成员)。您需要在su 使用的密码是root 密码,而不是您的用户密码。
  • @lsowen ubuntu 网站说,用户可以使用 sudo 命令添加任何需要以 root 身份执行的命令。我的 insmod 命令有效,我使用 dmesg 收到了消息。谢谢。
  • 而你没有看到printk(KERN_ALERT "TEST: Good Bye"); 因为你还没有完成rmmod hello 是吗?

标签: c linux linux-kernel


【解决方案1】:

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

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

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

您需要是 root 才能执行第 2 步和第 4 步。详细的过程在一个不错的Ubuntu blog 中进行了描述。

【讨论】:

    【解决方案2】:

    正如 isowen 提到的,只有 root 可以加载或卸载模块。

    执行insmod hello 时会看到hello_init() 中的打印,执行rmmod hello 时会看到hello_exit() 中的打印。

    【讨论】:

      【解决方案3】:

      执行cat /proc/sys/kernel/modules_disabled,如果你看到结果 1 然后执行 echo 'kernel.modules_disabled=1' &gt;&gt; /etc/sysctl.d/99-custom.conf 然后重新启动并重试。 ;) BR nu11secur1ty

      【讨论】:

        猜你喜欢
        • 2013-03-28
        • 2017-10-01
        • 2012-11-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多