Search code examples
clinuxlinux-kernelkernel-moduleinsmod

insmod error, invalid module format, fedora 35


I'm attempting to learn about kernel modules and followed along with a simple hello world example. My computer is running fedora 35. When I run sudo insmod mymodule.ko i get the error insmod: ERROR: could not insert module mymodule.ko: Invalid module format.

From reading other peoples issues it seems to do with the kernel version being mismatched with what the module was compiled for, however uname -r returns 5.16.18-200.fc35.x86_64 and modinfo mymodule.ko gives vermagic: 5.16.18-200.fc35.x86_64 SMP preempt mod_unload which seems to suggest they are the same.

Following some other posts I tried dmesg and got: [ 1689.372354] module: x86/modules: Skipping invalid relocation target, existing value is nonzero for type 1, loc 00000000d2334323, val ffffffffc140e000 which is quite different to what other users were experiencing (and doesn't seem to relate to kernel version), however I cannot make sense of it.

My makefile, in case it is useful:

obj-m += mymodule.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 

Solution

  • This post set me on the right path and might help others not using fedora Linux Kernel Module Development "module: x86/modules: Skipping invalid relocation target, existing value is nonzero for type 1"

    The issue was with the kernel headers, as always the problem was solved with the reliable uninstall and reinstall:

    sudo dnf remove kernel-devel
    sudo dnf install kernel-devel