I am currently trying to develop a simple linux kernel module. It should just log something, its 1:1 copied from the internet.
I have the following files:lkm_example.c
#include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h>MODULE_LICENSE("GPL");MODULE_AUTHOR("Robert W. Oliver II");MODULE_DESCRIPTION("A simple example Linux module.");MODULE_VERSION("0.01");static int __init lkm_example_init(void) { printk(KERN_INFO "Hello, World!\n"); return 0;}static void __exit lkm_example_exit(void) { printk(KERN_INFO "Goodbye, World!\n");}module_init(lkm_example_init);module_exit(lkm_example_exit);
Makefile:
obj-m += lkm_example.oall: make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modulesclean: make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
I also did the following:
sudo apt-get install build-essential linux-headers-`uname -r`
For compilation i used:
stbau@kernel-dev-vm:~/src/lkm_example$ sudo makemake -C /lib/modules/5.13.0-39-generic/build M=/home/stbau/src/lkm_example modulesmake[1]: Entering directory '/usr/src/linux-headers-5.13.0-39-generic' CC [M] /home/stbau/src/lkm_example/lkm_example.o MODPOST /home/stbau/src/lkm_example/Module.symvers CC [M] /home/stbau/src/lkm_example/lkm_example.mod.o LD [M] /home/stbau/src/lkm_example/lkm_example.komake[1]: Leaving directory '/usr/src/linux-headers-5.13.0-39-generic'
Executing with insmod:
stbau@kernel-dev-vm:~/src/lkm_example$ sudo insmod lkm_example.koinsmod: ERROR: could not insert module lkm_example.ko: Invalid module format
The dmesg log gives the following error:
[ 49.272618] lkm_example: module verification failed: signature and/or required key missing - tainting kernel[ 49.272630] module: x86/modules: Skipping invalid relocation target, existing value is nonzero for type 1, loc 0000000054f3f1c5, val ffffffffc0a0a000
I am using the following kernel:
stbau@kernel-dev-vm:~/src/lkm_example$ uname -aLinux kernel-dev-vm 5.13.0-39-generic #44-Ubuntu SMP Thu Mar 24 15:35:05 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
As you can see in the dmesg log, i only get an error and not the messages i expected. I have no idea what i did wrong/what is missing.
I think the problem is that the module is not signed. I tried signing it using the sign-file but i was not able to generate a private/public key file.