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 <rongtao@cestc.cn>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This commit is contained in:
Rong Tao 2025-04-25 15:47:28 +08:00 committed by Lucas De Marchi
parent 7b728f179f
commit c494150668
5 changed files with 41 additions and 7 deletions

View 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.

View 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'

View 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'

View 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]' \

View 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;