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
  2026-11-28 13:14 ` Bradley Morgan
  0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread

* Re: [PATCH] module: report why forced module loading is rejected
  2026-11-27  3:43 [PATCH] module: report why forced module loading is rejected Chao Huang
@ 2026-11-28 13:14 ` Bradley Morgan
  0 siblings, 0 replies; 2+ messages in thread
From: Bradley Morgan @ 2026-11-28 13:14 UTC (permalink / raw)
  To: 958028483
  Cc: atomlin, da.gomez, huangchao, linux-kernel, linux-modules,
	mcgrof, petr.pavlu, samitolvanen

On 27 November 2026 03:43:17 GMT, Chao Huang <958028483@qq.com> wrote:
>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")

This is correct.

Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>


>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

Suggestion:


/* CONFIG_MODULE_FORCE_LOAD is not
 * enabled, let's just tell the user
 * that it won't forcefully load
 */

I'm aware that's very long, you can shorten down or decline suggestion.

>+	pr_err("%s: %s: CONFIG_MODULE_FORCE_LOAD is not enabled\n",
>+	       mod->name, reason);
> 	return -ENOEXEC;
> #endif
> }
>
>base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
>

--- Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-28 13:15 UTC | newest]

Thread overview: 2+ messages (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
2026-11-28 13:14 ` Bradley Morgan

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®