Linux kernel version magic

Trick on the Version Magic number of Linux Kernel__linux

Recently, I was working on building a modified wireless driver for Nexus
7 to support monitor mode. There are quite a few things that are very
Subtle and easy to get confused. I ‘ ll just write down the steps in case
That I forgot and might need them again.

This
is actually a very good guide for building customized kernel module
Except the issue I’ll talk about below.

Kernel vermagic

The version magic number of the kernel that being used to build the
Externel module has to is exactly the same as the kernel on the
Device. It won ‘ t be a problem if you build the module and kernel, then
Load both of them to the device. However, in the case, I would like to
Avoid to build and replace the whole kernel. The wireless driver is the
Only kernel module-I want to build. Therefore, the kernel version
Magic has to be modified. The vermagic for the device is
«3.1.10-g05b777c SMP preempt mod_unload ARMv7» while my source code
Gives «3.1.10-g22b4fcd-dirty SMP preempt mod_unload ARMv7». So «3.1.10»
is the kernel version, it should match with the version of the kernel
Source. It consists the following four parts which can is found at
The beginning of Makefile:

The Guide
Indicates that modifying the Makefile as shown below and simply use the VC
Number as extraversion which is originaly omitted would solve the
Problem. However, you’ll end up with the something like
«3.1.10-g05b777c-g22b4fcd-dirty SMP preempt mod_unload ARMv7».

«-g05b777c» is the number of current version generated by the version
Control system (git, SVN, etc.). After the a little dig into Makefile, it
Turns out version number are stored in the file
Include/config/kernel.release and the local version are generated by the
Script Scripts/setlocalversion. By default, it would check if version
Control system is available. If So, then it would append «dirty» to the local
Version after the commit number if the commit haven ‘ t been submitted.
Where «-g22b4fcd-dirty» comes from. We could simply supplement a
Parameter as Scripts/setlocalversion–save-scmversion and it won ‘ t
Generate the local version number.

Читайте также:  Astra linux dhcp server

Kernel source Root Path:makefile

This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or complaint, to info-contact@alibabacloud.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.

Источник

Linux kernel version magic: Adding the missing plus suffix

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
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//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.

Читайте также:  Vmware server для linux

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.

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.

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.

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?

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#

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

Thanks for the article. Very useful.

Источник

How To Fix The Kernel Version Magic Easily

I hope this article will help you when you see the magic of the kernel version.

When I tried to inject an absolute kernel module that compiled and was incompatible with kernel headers, I got:

PC running slow?

ASR Pro is the ultimate solution for your PC repair needs! Not only does it swiftly and safely diagnose and repair various Windows issues, but it also increases system performance, optimizes memory, improves security and fine tunes your PC for maximum reliability. So why wait? Get started today!

# insmod mymodule.koinsmod: Error saving mymodule.ko: -1 Invalid module format
mymodule: power version "3.3.0-xxx Preempt smp mod_unload ARMv7" should become "3.3.0-xxx + SMP preempt mod_unload ARMv7"

Really? Are you choosing me to Reject my portion just because of a missing character? !

The plus sign comes first because the kernel was compiled using the git repository, which shows the removed changes compared to the official tree. To avoid this situation, I could quickly compile the kernel after renaming the .git directory to something else before compiling the kernel. But I forgot.

Читайте также:  Linux ascii art generator

Actually, maybe I would make the kernel completely separate for magic versioning.

The plus sign is missing from the latest kernel headers because they were generated without a git repository (the target’s own). Hence the difference.

You can use modprobe – force it, but wouldn’t it be better to just generate the magic version, right?

Thisthe solution applies to the 3.3.0 kernel, but will probably work for others as well.

The file you want to manage is /usr/src/kernels/your version/include/generated/utsrelease.h and just include a “+” sign at the end between the version number. For example,

#define UTS_RELEASE "3.3.0-xxx+"

kernel version magic

And currently all modules compiled with the kernel are loaded without problems.

For those interested in the gory details: mymodule.mod.c takes care of providing the Magic version. It is compiled into mymodule.mod.o and then combined with everything else using mymodule.o to become mymodule.ko. This is exactly what the famous “MODPOST” compilation phase does (it’s actually make -f scripts/Makefile on.modpost , which turns into calls to scripts/mod/modpost).

mymodule.mod.c is added first, including linux/vermagic.h (in fact, other similar files are coming too), which in turn includes generate/utsrelease.h, which explicitly magically provides your current version.

Why Do I Have To Complete A Very CAPTCHA?

Completing a CAPTCHA test verifies that you are a human and grants someone temporary access to a web resource.

What Should I Do To Prevent This From Happening In The Future?

kernel version magic

If you do have a private connection, such as at home, you can run a virus scan on your device to make sure it’s not infected with malware.

If you are in an office or on a public network, you can ask your network administrator to run a network scan for misconfigured or infected devices.

One way to prevent future access to this page is to use the Privacy Pass. You may need to download version 2.0 from the Firefox Add-ons Store right now.

Not The Answer You’re Looking For? Browse Other Questions Tagged Linux Kernel Kernel Kernel Modules Or Ask Your Own Question.

So, you really want to build the module without recompiling the kernel, if I understand correctly. The problem with the turbulence version can be fixed in the mainin your module’s makefile by setting EXTRAVERSION to the desired value. Can you find out what it is by running modinfo $module which makes $module a module of a running kernel, e.g. on my laptop, /lib/modules/5.4.0-3-amd64 /kernel/sound/ac97_bus.ko . … … Link to consultation https://linux.die.net/lkmpg/x380.html

replied February 1, 2020 at 10:00 am.

Источник

Оцените статью
Adblock
detector