]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
insmod: Support --force-{vermagic,modversion} arguments
authorRong Tao <rongtao@cestc.cn>
Fri, 25 Apr 2025 07:47:28 +0000 (15:47 +0800)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 9 May 2025 14:07:14 +0000 (09:07 -0500)
Supports --force-{vermagic,modversion} parameter like modprobe.

Link: https://github.com/kmod-project/kmod/pull/340
Signed-off-by: Rong Tao <rongtao@cestc.cn>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
man/insmod.8.scd
shell-completion/bash/insmod
shell-completion/fish/insmod.fish
shell-completion/zsh/_insmod
tools/insmod.c

index a5c4264616fe6e7000bec3a6d1cf904568a6343c..ec53f8fb83abb25569082d26b562ee0f2358c2d5 100644 (file)
@@ -24,7 +24,23 @@ information about errors.
        This option can be extremely dangerous: it tells the kernel to ignore
        the module version and vermagic fields when loading. With this option,
        you can load modules build locally or by third parties, although this
-       can lead to memory corruption, system crashes and data loss.
+       can lead to memory corruption, system crashes and data loss. This is
+       the same as using both *--force-vermagic* and *--force-modversion*.
+
+*--force-modversion*
+       When modules are compiled with CONFIG_MODVERSIONS set, a section
+       detailing the versions of every interfaced used by (or supplied by) the
+       module is created. If a module fails to load and the kernel complains
+       that the module disagrees about a version of some interface, you can use
+       *--force-modversion* to remove the version information altogether.
+
+*--force-vermagic*
+       Every module contains a small string containing important information,
+       such as the kernel and compiler versions. If a module fails to load and
+       the kernel complains that the "version magic" doesn't match, you can use
+       this option to remove it. Naturally, this check is there for your
+       protection, so using this option is dangerous unless you know what
+       you're doing.
 
 *-s*, *--syslog*
        Send errors to syslog instead of standard error.
index 5741f3367e7459e9a0370d1f109be3c3256d9e2e..02b74ad452cdcc461ea6b92f4cdc3da4191cad25 100644 (file)
@@ -11,6 +11,8 @@ _insmod()
     # long/short opt pairs
     local -A opts=(
         ['force']='f'
+        ['force-modversion']=''
+        ['force-vermagic']=''
         ['syslog']='s'
         ['verbose']='v'
         ['version']='V'
index 606ab5cbf409ecdc14bb0cd14ac6f44ea8f8553a..91a09fb491819482cf2cf4c82327779cf59c4f08 100644 (file)
@@ -7,6 +7,8 @@
 complete -c insmod -f
 
 complete -c insmod -s f -l force   -d "DANGEROUS: forces a module load, may cause data corruption and crash your machine"
+complete -c insmod -l force-modversion -d "DANGEROUS: Ignore module's version, may cause data corruption and crash your machine"
+complete -c insmod -l force-vermagic -d "DANGEROUS: Ignore module's version magic, may cause data corruption and crash your machine"
 complete -c insmod -s s -l syslog  -d 'print to syslog, not stderr'
 complete -c insmod -s v -l verbose -d 'enables more messages'
 complete -c insmod -s V -l version -d 'show version'
index de2c7fff4e5584efdbeb7a3ff99615f724e553e6..3e7723e5c8467c04e14c6efb018dc1dc8e3a407a 100644 (file)
@@ -7,6 +7,8 @@
 
 _arguments \
     {-f,--force}'[DANGEROUS: forces a module load, may cause data corruption and crash your machine]' \
+    --force-modversion'[ignore module version, may cause data corruption and crash your machine]' \
+    --force-vermagic'[ignore module version magic, may cause data corruption and crash your machine]' \
     {-s,--syslog}'[print to syslog, not stderr]' \
     {-v,--verbose}'[enables more messages]' \
     {-V,--version}'[show version]' \
index fef00722a8b549c9dc639ed057a2102246a7f30b..cd93d159aad9336f5398839cc796c09551b404d2 100644 (file)
@@ -20,6 +20,8 @@ static const char cmdopts_s[] = "fsvVh";
 static const struct option cmdopts[] = {
        // clang-format off
        { "force", no_argument, 0, 'f' },
+       { "force-modversion", no_argument, 0, 2 },
+       { "force-vermagic", no_argument, 0, 1 },
        { "syslog", no_argument, 0, 's' },
        { "verbose", no_argument, 0, 'v' },
        { "version", no_argument, 0, 'V' },
@@ -33,12 +35,16 @@ static void help(void)
        printf("Usage:\n"
               "\t%s [options] filename [module options]\n"
               "Options:\n"
-              "\t-f, --force       DANGEROUS: forces a module load, may cause\n"
-              "\t                  data corruption and crash your machine\n"
-              "\t-s, --syslog      print to syslog, not stderr\n"
-              "\t-v, --verbose     enables more messages\n"
-              "\t-V, --version     show version\n"
-              "\t-h, --help        show this help\n",
+              "\t-f, --force              DANGEROUS: forces a module load, may cause\n"
+              "\t                         data corruption and crash your machine.\n"
+              "\t                         implies --force-modversion and\n"
+              "\t                         --force-vermagic\n"
+              "\t    --force-modversion   Ignore module's version\n"
+              "\t    --force-vermagic     Ignore module's version magic\n"
+              "\t-s, --syslog             print to syslog, not stderr\n"
+              "\t-v, --verbose            enables more messages\n"
+              "\t-V, --version            show version\n"
+              "\t-h, --help               show this help\n",
               program_invocation_short_name);
 }
 
@@ -76,6 +82,12 @@ static int do_insmod(int argc, char *argv[])
                        flags |= KMOD_PROBE_FORCE_MODVERSION;
                        flags |= KMOD_PROBE_FORCE_VERMAGIC;
                        break;
+               case 2:
+                       flags |= KMOD_PROBE_FORCE_MODVERSION;
+                       break;
+               case 1:
+                       flags |= KMOD_PROBE_FORCE_VERMAGIC;
+                       break;
                case 's':
                        use_syslog = true;
                        break;