From: Rong Tao Date: Fri, 25 Apr 2025 07:47:28 +0000 (+0800) Subject: insmod: Support --force-{vermagic,modversion} arguments X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c494150668decca294de64c5fb083978c0d7fbc4;p=thirdparty%2Fkmod.git insmod: Support --force-{vermagic,modversion} arguments Supports --force-{vermagic,modversion} parameter like modprobe. Link: https://github.com/kmod-project/kmod/pull/340 Signed-off-by: Rong Tao Reviewed-by: Emil Velikov Signed-off-by: Lucas De Marchi --- diff --git a/man/insmod.8.scd b/man/insmod.8.scd index a5c42646..ec53f8fb 100644 --- a/man/insmod.8.scd +++ b/man/insmod.8.scd @@ -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. diff --git a/shell-completion/bash/insmod b/shell-completion/bash/insmod index 5741f336..02b74ad4 100644 --- a/shell-completion/bash/insmod +++ b/shell-completion/bash/insmod @@ -11,6 +11,8 @@ _insmod() # long/short opt pairs local -A opts=( ['force']='f' + ['force-modversion']='' + ['force-vermagic']='' ['syslog']='s' ['verbose']='v' ['version']='V' diff --git a/shell-completion/fish/insmod.fish b/shell-completion/fish/insmod.fish index 606ab5cb..91a09fb4 100644 --- a/shell-completion/fish/insmod.fish +++ b/shell-completion/fish/insmod.fish @@ -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' diff --git a/shell-completion/zsh/_insmod b/shell-completion/zsh/_insmod index de2c7fff..3e7723e5 100644 --- a/shell-completion/zsh/_insmod +++ b/shell-completion/zsh/_insmod @@ -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]' \ diff --git a/tools/insmod.c b/tools/insmod.c index fef00722..cd93d159 100644 --- a/tools/insmod.c +++ b/tools/insmod.c @@ -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;