[PATCH] module: report why forced module loading is rejected
From: Chao Huang
Date: Thu Nov 26 2026 - 22:43:32 EST
From: Chao Huang <huangchao@xxxxxxxxxx>
When CONFIG_MODULE_FORCE_LOAD is disabled, try_to_force_load() returns
-ENOEXEC without logging why the module was rejected. For example, with
CONFIG_MODVERSIONS enabled, finit_module() with
MODULE_INIT_IGNORE_MODVERSIONS suppresses the version sections and causes
the module_layout version check to take this path. Users only see
"Invalid module format" from insmod, without a diagnostic in the kernel
log explaining the failure.
Log the module name and the supplied reason, and state that
CONFIG_MODULE_FORCE_LOAD is not enabled before returning -ENOEXEC. This
also diagnoses the missing vermagic and exported-symbol version paths
that use the same helper.
Fixes: 826e4506a0ac ("Make forced module loading optional")
Signed-off-by: Chao Huang <huangchao@xxxxxxxxxx>
---
Testing: rebuilt the x86_64 bzImage and modules with CONFIG_MODVERSIONS=y
and CONFIG_MODULE_FORCE_LOAD disabled, and booted the patched kernel with:
vng --run out/arch/x86/boot/bzImage --cpus 2 --memory 2G \
--disable-microvm --verbose
A matching test module loaded and unloaded successfully without flags.
finit_module() with MODULE_INIT_IGNORE_MODVERSIONS,
MODULE_INIT_IGNORE_VERMAGIC, or both flags failed with ENOEXEC and logged
the corresponding reason and disabled configuration option.
kernel/module/main.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 34e0204ea37c..010b5d69e50c 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -1124,6 +1124,8 @@ int try_to_force_load(struct module *mod, const char *reason)
add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_NOW_UNRELIABLE);
return 0;
#else
+ pr_err("%s: %s: CONFIG_MODULE_FORCE_LOAD is not enabled\n",
+ mod->name, reason);
return -ENOEXEC;
#endif
}
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
--
2.25.1