mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] module: report why forced module loading is rejected
@ 2026-11-27  3:43 Chao Huang
  0 siblings, 0 replies; only message in thread
From: Chao Huang @ 2026-11-27  3:43 UTC (permalink / raw)
  To: linux-modules
  Cc: mcgrof, petr.pavlu, da.gomez, samitolvanen, atomlin,
	linux-kernel, huangchao

From: Chao Huang <huangchao@kylinos.cn>

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@kylinos.cn>
---
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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-27  3:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27  3:43 [PATCH] module: report why forced module loading is rejected Chao Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®