module: add config option MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS
authorMatthias Maennich <maennich@google.com>
Fri, 6 Sep 2019 10:32:29 +0000 (11:32 +0100)
committerJessica Yu <jeyu@kernel.org>
Tue, 10 Sep 2019 08:30:27 +0000 (10:30 +0200)
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>
init/Kconfig
kernel/module.c

index bd7d650d4a996c7c10d2349a340f52c1f99c1e49..cc28561288a7d7756bb5c408b88ab71be51519aa 100644 (file)
@@ -2119,6 +2119,19 @@ config MODULE_COMPRESS_XZ
 
 endchoice
 
+config MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS
+       bool "Allow loading of modules with missing namespace imports"
+       help
+         Symbols exported with EXPORT_SYMBOL_NS*() are considered exported in
+         a namespace. A module that makes use of a symbol exported with such a
+         namespace is required to import the namespace via MODULE_IMPORT_NS().
+         There is no technical reason to enforce correct namespace imports,
+         but it creates consistency between symbols defining namespaces and
+         users importing namespaces they make use of. This option relaxes this
+         requirement and lifts the enforcement when loading a module.
+
+         If unsure, say N.
+
 config TRIM_UNUSED_KSYMS
        bool "Trim unused exported kernel symbols"
        depends on MODULES && !UNUSED_SYMBOLS
index 6bb9b938f9c7d68db07be2ebc8153f4f1e931322..f76efcf2043ef32cf9044dc0db81610bf2fe4845 100644 (file)
@@ -1408,9 +1408,16 @@ static int verify_namespace_is_imported(const struct load_info *info,
                        imported_namespace = get_next_modinfo(
                                info, "import_ns", imported_namespace);
                }
-               pr_err("%s: module uses symbol (%s) from namespace %s, but does not import it.\n",
-                      mod->name, kernel_symbol_name(sym), namespace);
+#ifdef CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS
+               pr_warn(
+#else
+               pr_err(
+#endif
+                       "%s: module uses symbol (%s) from namespace %s, but does not import it.\n",
+                       mod->name, kernel_symbol_name(sym), namespace);
+#ifndef CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS
                return -EINVAL;
+#endif
        }
        return 0;
 }