Skip to content

Commit 9c036cf

Browse files
committed
modpost: check forbidden MODULE_IMPORT_NS("module:") at compile time
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 <[email protected]>
1 parent 8f81d85 commit 9c036cf

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

scripts/mod/modpost.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "modpost.h"
2929
#include "../../include/linux/license.h"
3030

31+
#define MODULE_NS_PREFIX "module:"
32+
3133
static bool module_enabled;
3234
/* Are we using CONFIG_MODVERSIONS? */
3335
static bool modversions;
@@ -1597,8 +1599,13 @@ static void read_symbols(const char *modname)
15971599

15981600
for (namespace = get_modinfo(&info, "import_ns");
15991601
namespace;
1600-
namespace = get_next_modinfo(&info, "import_ns", namespace))
1602+
namespace = get_next_modinfo(&info, "import_ns", namespace)) {
1603+
if (strstarts(namespace, MODULE_NS_PREFIX))
1604+
error("%s: explicitly importing namespace \"%s\" is not allowed.\n",
1605+
mod->name, namespace);
1606+
16011607
add_namespace(&mod->imported_namespaces, namespace);
1608+
}
16021609

16031610
if (!get_modinfo(&info, "description"))
16041611
warn("missing MODULE_DESCRIPTION() in %s\n", modname);

0 commit comments

Comments
 (0)