Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

insmod error in kernel module programming

I am just starting with modular programming.

Above are my two files:

hello.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);

Makefile

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

And here's my terminal output showing error in insmod command, kindly help.

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
like image 898
anubhav Avatar asked Oct 29 '25 00:10

anubhav


2 Answers

If you have secure boot enabled, the newer kernels won't allow inserting arbitrary kernel modules. So, either you can disable secure boot in your BIOS or you need to sign the kernel modules you want to install.

Steps to securely sign your kernel modules:

  1. Create a X509 certificate that can be imported in firmware
  2. Enrolling the public key just created
  3. Sign the module you want to install
  4. Install the module

You need to be root to do steps 2 & 4. The detailed process is described in a nice Ubuntu blog.

like image 179
Abhishek Jaisingh Avatar answered Oct 30 '25 16:10

Abhishek Jaisingh


As isowen mentioned only root can load or unload the module.

You see the print in hello_init() when you do insmod hello and you see the print in hello_exit() when you do rmmod hello.

like image 26
Milind Dumbare Avatar answered Oct 30 '25 16:10

Milind Dumbare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!