How to find the compiled kernel module version?

I am in a situation where it would be very convenient to find the version of the loaded kernel module by requesting the loaded module or .ko file.

Is there a standard way to do this without breaking into the source code?

+8
linux kernel-module
source share
2 answers
$ apropos modinfo modinfo (8) - display information about a kernel module $ modinfo cpuid.ko filename: cpuid.ko author: H. Peter Anvin <hpa@zytor.com> description: x86 generic CPUID driver license: GPL vermagic: 2.6.37 SMP preempt mod_unload PENTIUM4 gcc-4.4.5 depends: 
+8
source share

Execution method

 insmod /module_version.ko cat /sys/modules/module_version/version # => 1.0 cat /sys/module/module_version/srcversion # => AB0F06618BC3A36B687CDC5 modinfo /module_version.ko | grep -E '^(src|)version' # => version: 1.0 # => srcversion: AB0F06618BC3A36B687CDC5 

Tested this setting in the kernel 4.9.6.

version

version is given by the expression MODULE_VERSION . The file does not exist if MODULE_VERSION not specified.

srcversion

srcversion is an MD4 hash of the source code used to compile the kernel module. It is calculated automatically during build from https://github.com/torvalds/linux/blob/v4.9/scripts/mod/modpost.c#L1978 using https://github.com/torvalds/linux/blob/ v4.9 / scripts / mod / sumversion.c # L400

To enable it, follow these steps:

  • set MODULE_VERSION for the module
  • compile with CONFIG_MODULE_SRCVERSION_ALL . srcversion then generated for all modules, including without MODULE_VERSION set: modinfo srcversion: How do I generate this from my source?

srcversion present only on job.

Then you can verify that the built-in .ko matches the built-in:

 modinfo mymod.ko 

This is a very useful health check when you develop your own kernel modules and copy modules between machines.

+1
source share

All Articles