Issue
I have a simple hello world kernel module on Ubuntu x86_64:
#include <linux/module.h>
static int
mod_init(void)
{
printk(KERN_INFO "RYANhello world\n");
return 0;
}
static void
mod_exit(void)
{
printk(KERN_INFO "RYANgoodbye world\n");
}
MODULE_LICENSE("GPL");
module_init(mod_init);
module_exit(mod_exit);
Makefile:
KERNEL_DIR := /lib/modules/$(shell uname -r)/build
CUR_DIR := $(shell pwd)
obj-m := module.o
default:
$(MAKE) -C $(KERNEL_DIR) M=$(CUR_DIR) modules
When I sudo insmod module.ko
I get insmod: ERROR: could not insert module module.ko: Invalid parameters
. Inspecting dmesg
:
loading out-of-tree module taints kernel
module verification failed: signature and/or required key missing - tainting kernel
Repeating insmod
yields module is already loaded
however /var/log/syslog
shows no trace of it loading (i.e printk
messages not present). Also, running sudo rmmod module.ko
:
rmmod: ERROR: ../libkmod/libkmod-module.c:1941 kmod_module_get_holders() could not open '/sys/module/module/holders': No such file or directory
rmmod: ERROR: Module unloading is not supported
This seems to indicate it's not loaded, even though dmesg
says it is?
Addressing common issues; my host kernel and gcc version are the same as ones I compiling with.
So, this leads me to think that the module not being signed is the issue. To disable this do I have to compile and install my own kernel with appropriate .config
? In other words, to write and test your own kernel modules on a modern GNU/Linux OS with enforced signing, do you have to compile and install your own kernel?
EDIT
CONFIG_MODULE_SIG_FORCE
is not set in my /boot/config-5.8.0-53-generic
, so it seems I should be able to load my module albeit with a tainted kernel message. So, why would I be getting Invalid parameters?
Solution
Inspecting dmesg
on first insmod
it was saying that the module was already loaded. As I had never loaded this before, this prompted me to think that this name was already taken.
Low and behold, renaming module.c/module.o --> example.c/example.o
fixed the problem. The invalid parameters
message was what threw me.
Answered By - Ryan McClue