mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chao Huang <958028483@qq.com>
To: linux-modules@vger.kernel.org
Cc: mcgrof@kernel.org, petr.pavlu@suse.com, da.gomez@kernel.org,
	samitolvanen@google.com, atomlin@atomlin.com,
	linux-kernel@vger.kernel.org, huangchao@kylinos.cn
Subject: [PATCH] module: report why forced module loading is rejected
Date: Fri, 27 Nov 2026 11:43:17 +0800	[thread overview]
Message-ID: <tencent_192A8A137B6CC69DDBF028C27205824BAC09@qq.com> (raw)

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


                 reply	other threads:[~2026-11-27  3:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_192A8A137B6CC69DDBF028C27205824BAC09@qq.com \
    --to=958028483@qq.com \
    --cc=atomlin@atomlin.com \
    --cc=da.gomez@kernel.org \
    --cc=huangchao@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=samitolvanen@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®