Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <masahiroy@kernel.org>

+8 -1
+8 -1
scripts/mod/modpost.c
··· 28 28 #include "modpost.h" 29 29 #include "../../include/linux/license.h" 30 30 31 + #define MODULE_NS_PREFIX "module:" 32 + 31 33 static bool module_enabled; 32 34 /* Are we using CONFIG_MODVERSIONS? */ 33 35 static bool modversions; ··· 1599 1597 1600 1598 for (namespace = get_modinfo(&info, "import_ns"); 1601 1599 namespace; 1602 - namespace = get_next_modinfo(&info, "import_ns", namespace)) 1600 + namespace = get_next_modinfo(&info, "import_ns", namespace)) { 1601 + if (strstarts(namespace, MODULE_NS_PREFIX)) 1602 + error("%s: explicitly importing namespace \"%s\" is not allowed.\n", 1603 + mod->name, namespace); 1604 + 1603 1605 add_namespace(&mod->imported_namespaces, namespace); 1606 + } 1604 1607 1605 1608 if (!get_modinfo(&info, "description")) 1606 1609 warn("missing MODULE_DESCRIPTION() in %s\n", modname);