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

module: add config option MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS

If MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS is enabled (default=n), the
requirement for modules to import all namespaces that are used by
the module is relaxed.

Enabling this option effectively allows (invalid) modules to be loaded
while only a warning is emitted.

Disabling this option keeps the enforcement at module loading time and
loading is denied if the module's imports are not satisfactory.

Reviewed-by: Martijn Coenen <maco@android.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Jessica Yu <jeyu@kernel.org>

authored by

Matthias Maennich and committed by
Jessica Yu
3d52ec5e cb9b55d2

+22 -2
+13
init/Kconfig
··· 2119 2119 2120 2120 endchoice 2121 2121 2122 + config MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS 2123 + bool "Allow loading of modules with missing namespace imports" 2124 + help 2125 + Symbols exported with EXPORT_SYMBOL_NS*() are considered exported in 2126 + a namespace. A module that makes use of a symbol exported with such a 2127 + namespace is required to import the namespace via MODULE_IMPORT_NS(). 2128 + There is no technical reason to enforce correct namespace imports, 2129 + but it creates consistency between symbols defining namespaces and 2130 + users importing namespaces they make use of. This option relaxes this 2131 + requirement and lifts the enforcement when loading a module. 2132 + 2133 + If unsure, say N. 2134 + 2122 2135 config TRIM_UNUSED_KSYMS 2123 2136 bool "Trim unused exported kernel symbols" 2124 2137 depends on MODULES && !UNUSED_SYMBOLS
+9 -2
kernel/module.c
··· 1408 1408 imported_namespace = get_next_modinfo( 1409 1409 info, "import_ns", imported_namespace); 1410 1410 } 1411 - pr_err("%s: module uses symbol (%s) from namespace %s, but does not import it.\n", 1412 - mod->name, kernel_symbol_name(sym), namespace); 1411 + #ifdef CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS 1412 + pr_warn( 1413 + #else 1414 + pr_err( 1415 + #endif 1416 + "%s: module uses symbol (%s) from namespace %s, but does not import it.\n", 1417 + mod->name, kernel_symbol_name(sym), namespace); 1418 + #ifndef CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS 1413 1419 return -EINVAL; 1420 + #endif 1414 1421 } 1415 1422 return 0; 1416 1423 }