clinuxlinux-kernellinux-device-driverinsmod

modprobe/insmod - ERROR: could not insert module Operation not permitted installing a kernel space module with root privileges


So, I was trying to install a hello world kernel shown the book "Linux Device Drivers" by Corbet, Jonathan.

This is the code for the file hello.c

#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void) {
    printk(KERN_ALERT "Hello World!!\n");
    return 0;
}

static void hello_exit(void) {
    printk(KERN_ALERT "Good Bye Module!!\n");
}

module_init(hello_init);
module_exit(hello_exit);

To build it, I use this makefile:

obj-m += hello.o
all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

After running

make all
sudo insmod ./hello.ko

and I have the error

ERROR: could not insert module Operation not permitted

Installing a kernel space module with root privileges. Also tried

sudo su
sudo insmod ./hello.ko

Also tried

sudo modprove -v hello.ko

With similar error.


Solution

  • So, there are several things going on, the main issue is that your computer(usually a laptop) have the secure boot option enabled in the bios.

    This usually does the trick, BUT, in some notebooks, the option does not appear(or is disabled) until you set the administration password for the bios.

    If after changing the secure boot option to disabled sometimes is not enough. In some newer Intel laptops, you need to disable the Intel Platform Trust Technology also from the BIOS.

    Finally, you can run insmod or modprobe without problem.

    To check the output of printk(KERN_ALERT "Hello World!!\n"); you need to do a

    tail -f /var/log/kern.log

    That should work.