簡體   English   中英

內核模塊編程中的insmod錯誤

[英]insmod error in kernel module programming

我只是從模塊化編程開始。

以上是我的兩個文件:

你好ç

#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 步。詳細過程在一個不錯的Ubuntu 博客中有所描述。

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

你看在打印hello_init()當你做insmod hello ,你會看到在打印hello_exit()當你rmmod hello

執行cat /proc/sys/kernel/modules_disabled ,如果看到結果1則執行echo 'kernel.modules_disabled=1' >> /etc/sysctl.d/99-custom.conf然后重新啟動echo 'kernel.modules_disabled=1' >> /etc/sysctl.d/99-custom.conf試。 ;) BR nu11secur1ty

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM