anubhav
anubhav

Reputation: 141

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

Upvotes: 4

Views: 7891

Answers (3)

nu11secur1ty
nu11secur1ty

Reputation: 41

execute cat /proc/sys/kernel/modules_disabled and if you see the result 1 then execute echo 'kernel.modules_disabled=1' >> /etc/sysctl.d/99-custom.conf then reboot and try again. ;) BR nu11secur1ty

Upvotes: 0

Abhishek Jaisingh
Abhishek Jaisingh

Reputation: 1730

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.

Upvotes: 3

Milind Dumbare
Milind Dumbare

Reputation: 3244

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.

Upvotes: 1

Related Questions