Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 内核模块编程中的insmod错误_C_Linux_Linux Kernel - Fatal编程技术网

C 内核模块编程中的insmod错误

C 内核模块编程中的insmod错误,c,linux,linux-kernel,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 B

我只是从模块化编程开始

以上是我的两个文件:

你好,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);
这是我的终端输出,显示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

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


执行
insmod hello
操作时,您会在
hello\u init()
中看到打印,执行
rmmod hello
操作时,您会在
hello\u exit()
中看到打印。如果启用了安全引导,则较新的内核将不允许插入任意内核模块。因此,您可以在BIOS中禁用安全引导,或者需要对要安装的内核模块进行签名

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

  • 创建可以在固件中导入的X509证书
  • 注册刚刚创建的公钥
  • 对要安装的模块进行签名
  • 安装模块

  • 您需要是root用户才能执行步骤2和4。详细的过程在nice中描述。

    执行
    cat/proc/sys/kernel/modules\u disabled
    ,如果您看到结果
    1
    然后执行
    echo'kernel.modules\u disabled=1'>/etc/sysctl.d/99 custom.conf
    然后重新启动并重试BR nu11secur1ty

    通常只有
    root
    用户具有插入/删除内核模块的权限。要么转到
    root
    ,要么使用(如果适用)以root身份运行命令。@lsowen我尝试了“su”和“su-”。但在提供密码后,我得到消息“su:Authentication failure”。任何其他移动头的方式此消息意味着您输入了错误的密码(或者您不是允许成为root用户的用户组成员)。您需要在
    su
    使用的密码是
    root
    密码,而不是您的用户密码。@lsowentubuntu网站说,用户可以使用sudo命令预先发送任何需要作为root用户执行的命令。我的insmod命令起作用了,我使用dmesg得到了消息。谢谢。你没有看到printk(KERN_ALERT“TEST:再见”)因为你没有做过
    rmmod hello
    是吗?
    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