Linux kernel version magic: Adding the missing plus suffix

This post was written by eli on October 2, 2013
Posted Under: Linux,Linux kernel

Trying to insmod a kernel module, which was just compiled against the true headers of the running kernel, I got:

# insmod mymodule.ko
insmod: error inserting 'mymodule.ko': -1 Invalid module format

And this in /var/log/syslog:

mymodule: version magic '3.3.0-xxx SMP preempt mod_unload ARMv7 ' should be '3.3.0-xxx+ SMP preempt mod_unload ARMv7 '

Really? Are you picking on me? Rejecting my module just because of a missing plus sign?!

The plus sign is there in the first place because the kernel was compiled with a git repository, which displayed modifications relative to the official tree. To avoid it, I could have compiled the kernel after renaming the .git directory to something else prior to compiling the kernel. But I forgot to do that.

In fact, I should have turned kernel magic versioning off altogether.

The plus sign is absent in the current kernel headers, because they were generated without the git repository (natively on the target). Hence the difference.

One could use modprobe –force, but isn’t it nicer to just get the version magic right?

This solution holds for the 3.3.0 kernel, but probably works on others as well.

The file you want to edit is /usr/src/kernels/{your version}/include/generated/utsrelease.h and just add the ‘+’ sign to the end of the version number. E.g.

#define UTS_RELEASE "3.3.0-xxx+"

And now all modules compiled against the kernel will load with no issues.

For those interested in the gory details: It’s mymodule.mod.c that is responsible for supplying the version magic. It’s compiled into mymodule.mod.o, and then fused together with mymodule.o to become mymodule.ko. This is what the famous “MODPOST” compilation stage does (in fact, it’s a make -f on scripts/Makefile.modpost, which in turn calls scripts/mod/modpost).

mymodule.mod.c gets the number by including linux/vermagic.h (actually, it includes other similar files as well) which in turn includes generated/utsrelease.h, which supplies the version magic explicitly.

Reader Comments

I can’t thank you enough for posting this. Your description of the “gory details” allowed me to complete a compiling project I’ve been working on for some time now. Thanks.

#1 
Written By Dominic on October 17th, 2014 @ 23:50

hey i have a question on the same matter of versioning:

so i am trying to cross compile the prolific module for mirabox, and i am running into:

pl2303: version magic ’3.2.36 mod_unload ARMv7 p2v8 ‘ should be ’3.2.36 mod_unload ARMv7 ‘

what does the p2v8 stand for and how can i get the versions to match? i am using the same kernel versions.

any help would be appreciated.

thanks

#2 
Written By stefanita rares dumitrescu on January 25th, 2015 @ 15:49

Thank you very much. This article immediately solved a problem that I had during a build/git transition, and where the target busybox insmod did not have a –force option to work around the version mismatch.

#3 
Written By Yearwood on April 24th, 2015 @ 19:25

Hi Eli

What if turn ON the CONFIG_MODVERSIONS support while compiling the kernel?

I believe this is for those times when we DO NOT have access to the kernel source just the header files. AM I right?

#4 
Written By Mohammad Ejaz on April 26th, 2015 @ 09:26

I have the opposite problem. Any idea how to resolve it?

root@kvmhost:/lib/modules/3.14.32# insmod /lib/modules/3.14.32/build/drivers/net
/vxlan.ko
[15913.580905] vxlan: version magic ’3.14.32+ SMP mod_unload ARMv7 thumb2 p2v8 ‘
should be ’3.14.32 SMP mod_unload ARMv7 thumb2 p2v8 ‘
insmod: error inserting ‘/lib/modules/3.14.32/build/drivers/net/vxlan.ko’: -1 In
valid module format
root@kvmhost:/lib/modules/3.14.32# uname -a
Linux kvmhost 3.14.32 #1 SMP Wed Apr 8 01:33:33 MST 2015 armv7l armv7l armv7l GN
U/Linux
root@kvmhost:/lib/modules/3.14.32#

#5 
Written By Ankur on May 14th, 2015 @ 07:34

Have only heard about “hitting the nail on the head”. Read it now in your blog. Cheers!!

#6 
Written By sabin on August 11th, 2016 @ 11:38

Thanks for the article. Very useful.

#7 
Written By Sukanya on June 26th, 2017 @ 03:12

Thank you so much for posting this. I had to same problem with the vermagic being socfpga-ltsi vs. socfpga-ltsi-altera. The source code given to me by altera did not match what they preloaded onto the board! Wonderful fix!

#8 
Written By Jennifer Reid on February 13th, 2019 @ 04:54

Hey I am getting the error as below:

version magic ’5.0.19-armv7-x15 SMP preempt mod_unload modversions ARMv7 thumb2 p2v8 ‘ should be ’5.0.19-armv7-x15 SMP preempt ARMv7 p2v8 ‘

insmod: ERROR: could not insert module adv7381.ko: Invalid module format

What could be the issue?

#9 
Written By Angu on August 7th, 2019 @ 09:59

Many thanks to the author of this article. Worth bookmarking.

@ANGU, it seems your module is compiled for thumb2 however it was needed to be compiled for ARMv7. Check in your config file for the settings.

#10 
Written By Raj on September 13th, 2019 @ 20:57

Add a Comment

required, use real name
required, will not be published
optional, your blog address