diff --git a/README.md b/README.md index e46dcad..05063df 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Linux Kernel Module Cheat -Run one command, get into QEMU Buildroot BusyBox virtual machine with several minimal Linux kernel 4.9 module example tutorials with GDB and KGDB debug. Tested in x86 and ARM guests, Ubuntu 14.04 - 16.10 hosts. +Run one command, get into QEMU Buildroot BusyBox virtual machine with several minimal Linux kernel 4.9 module development example tutorials with GDB and KGDB debug. Tested in x86 and ARM guests, Ubuntu 14.04 - 16.10 hosts. ![](screenshot.png) @@ -345,6 +345,7 @@ You can still send key presses to QEMU however even without the mouse capture, j 1. [Introduction](introduction.md) 1. [Build](build.md) 1. [kmod](kmod.md) +1. [vermagic](vermagic.md) 1. [Bibliography](bibliography.md) 1. Examples 1. [Host](host/) diff --git a/kernel_module/poll.c b/kernel_module/poll.c index 6f34a7c..d582289 100644 --- a/kernel_module/poll.c +++ b/kernel_module/poll.c @@ -2,6 +2,8 @@ /poll.sh Outcome: user echoes jiffies every second. + +https://stackoverflow.com/questions/30035776/how-to-add-poll-function-to-the-kernel-module-code/44645336#44645336 */ #include /* copy_from_user, copy_to_user */ diff --git a/vermagic.md b/vermagic.md new file mode 100644 index 0000000..73d4826 --- /dev/null +++ b/vermagic.md @@ -0,0 +1,27 @@ +# vermagic + +If the module does not match that of the kernel, `insmod` is unhappy and fails. + +Get it from kernel module: + + modinfo mymod.ko + +Override it on module source: + + MODULE_INFO(vermagic, "newver"); + +On the Linux kernel 4.9.6, it is defined under `include/linux/vermagic.h`: + + #define VERMAGIC_STRING \ + UTS_RELEASE " " \ + MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \ + MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \ + MODULE_ARCH_VERMAGIC + +TODO can you get it from running kernel from userland? + +Desktop `modprobe` has a flag to skip the check: + + `--force-modversion` + +Looks like it just strips `modversion` information from the module, and then the kernel skips the check.