Reputation: 141
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
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
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:
You need to be root to do steps 2 & 4. The detailed process is described in a nice Ubuntu blog.
Upvotes: 3
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