mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
Less converstaion
This commit is contained in:
@@ -6,7 +6,10 @@
|
||||
1. [hello](hello.c)
|
||||
1. [hello2](hello2.c)
|
||||
1. [panic](panic.c)
|
||||
1. [params](params.c)
|
||||
1. Module utils
|
||||
1. [params](params.c)
|
||||
1. [vermagic](vermagic.c)
|
||||
1. [vermagic_fail](vermagic_fail.c)
|
||||
1. Pseudo filesystems
|
||||
1. [debugfs](debugfs.c)
|
||||
1. [procfs](procfs.c)
|
||||
|
||||
21
kernel_module/vermagic.c
Normal file
21
kernel_module/vermagic.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
insmod /vermagic.ko
|
||||
# => 4.9.6 SMP mod_unload modversions
|
||||
TODO how to get the vermagic from running kernel from userland? <https://lists.kernelnewbies.org/pipermail/kernelnewbies/2012-October/006306.html>
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/vermagic.h>
|
||||
|
||||
static int myinit(void)
|
||||
{
|
||||
pr_info(VERMAGIC_STRING "\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void myexit(void) {}
|
||||
|
||||
module_init(myinit)
|
||||
module_exit(myexit)
|
||||
MODULE_LICENSE("GPL");
|
||||
30
kernel_module/vermagic_fail.c
Normal file
30
kernel_module/vermagic_fail.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
insmod /vermagic_fail.ko
|
||||
# => insmod: can't insert '/vermagic_fail.ko': invalid module format
|
||||
|
||||
modinfo /vermagic_fail.ko | grep vermagic
|
||||
# => vermagic: asdfqwer
|
||||
# => vermagic: 4.9.6 SMP mod_unload modversions
|
||||
|
||||
kmod `modprobe` has a flag to skip the check:
|
||||
|
||||
--force-modversion
|
||||
|
||||
Looks like it just strips `modversion` information from the module before loading, and then the kernel skips the check.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
|
||||
static int myinit(void)
|
||||
{
|
||||
pr_info("vermagic_fail\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void myexit(void) {}
|
||||
|
||||
module_init(myinit)
|
||||
module_exit(myexit)
|
||||
MODULE_INFO(vermagic, "asdfqwer");
|
||||
MODULE_LICENSE("GPL");
|
||||
Reference in New Issue
Block a user