From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Masahiro Yamada <masahiroy@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nicolas.schier@linux.dev>
Subject: [PATCH 1/3] modpost: check forbidden MODULE_IMPORT_NS("module:") at compile time
Date: Thu, 22 May 2025 16:17:20 +0900 [thread overview]
Message-ID: <20250522071744.2362563-1-masahiroy@kernel.org> (raw)
Explicitly adding MODULE_IMPORT_NS("module:...") is not allowed.
Currently, this is only checked at run time. That is, when such a
module is loaded, an error message like the following is shown:
foo: module tries to import module namespace: module:bar
Obviously, checking this at compile time improves usability.
In such a case, modpost will report the following error at compile time:
ERROR: modpost: foo: explicitly importing namespace "module:bar" is not allowed.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/mod/modpost.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 16a69a129805..5ca7c268294e 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -28,6 +28,8 @@
#include "modpost.h"
#include "../../include/linux/license.h"
+#define MODULE_NS_PREFIX "module:"
+
static bool module_enabled;
/* Are we using CONFIG_MODVERSIONS? */
static bool modversions;
@@ -1597,8 +1599,13 @@ static void read_symbols(const char *modname)
for (namespace = get_modinfo(&info, "import_ns");
namespace;
- namespace = get_next_modinfo(&info, "import_ns", namespace))
+ namespace = get_next_modinfo(&info, "import_ns", namespace)) {
+ if (strstarts(namespace, MODULE_NS_PREFIX))
+ error("%s: explicitly importing namespace \"%s\" is not allowed.\n",
+ mod->name, namespace);
+
add_namespace(&mod->imported_namespaces, namespace);
+ }
if (!get_modinfo(&info, "description"))
warn("missing MODULE_DESCRIPTION() in %s\n", modname);
--
2.43.0
next reply other threads:[~2025-05-22 7:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-22 7:17 Masahiro Yamada [this message]
2025-05-22 7:17 ` [PATCH 2/3] modpost: allow "make nsdeps" to skip module-specific symbol namespace Masahiro Yamada
2025-05-27 7:55 ` Petr Pavlu
2025-05-22 7:17 ` [PATCH 3/3] docs/core-api/symbol-namespaces: drop table of contents and section numbering Masahiro Yamada
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=20250522071744.2362563-1-masahiroy@kernel.org \
--to=masahiroy@kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=nicolas.schier@linux.dev \
/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