From patchwork Wed Aug 21 11:49:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 11106479 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BA091813 for ; Wed, 21 Aug 2019 11:54:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4EDE233A1 for ; Wed, 21 Aug 2019 11:54:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="abTPfEJh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728061AbfHULyp (ORCPT ); Wed, 21 Aug 2019 07:54:45 -0400 Received: from mail-yw1-f73.google.com ([209.85.161.73]:46018 "EHLO mail-yw1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727877AbfHULy1 (ORCPT ); Wed, 21 Aug 2019 07:54:27 -0400 Received: by mail-yw1-f73.google.com with SMTP id z201so1258109ywz.12 for ; Wed, 21 Aug 2019 04:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=PMfgpvV4p29AlBNiXlEti/BQa916MI0li39A4AvOT8o=; b=abTPfEJhVwI/gTUYBSiD3/lNZoCFClIsVlF/S1LUw2hkn62URKuAwYcGeZTiMgflCE RH0FW4rwVygHz/irYwGK+2B8izibJphUwGkIg3MYKMiB94z2GaNprg8wrKbnbJxDAh7w LTTCqXeFZuXpWKiLLsFInxfjxXoQv05Woq/GeUH88OP6wdtiNh03LDNHrPVh/UmzbhTD D8DEHJnTdvf2WWeNotbNP3DawUqMAATGqe8bVNhGnamyNxb6t+fbpbmbuQWHhl09D6yh OyOPUn6H0uBx7epA7HzZ5sWn4sT8XEHjpqM1tqCiVYjla+4Wbs8sCnh0+SDMTc1QpD71 uuyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=PMfgpvV4p29AlBNiXlEti/BQa916MI0li39A4AvOT8o=; b=SXwQKU+KY6mUBilX0FHx+UJIcgyaKLPBykYHrKqQQXgTQFAyRZYW0dhFXxSo6K4NaD GXU+6o37Vyj/WwLvmDcY1bLyTeC7jg4raHQcQfKBCFgicBws/+YQjB3Tb47qCyLtQtgl YHAr3n+NbSOp3BffmL2uqMP34OO43E8bbyZm3CYqdUoslI31poytjX+TbN4BgZMZnZuV q9q1ZxSsPppBS3UKCnsBMTEq3gXt2lwWfGcuQg7zo2nrmfUMM8dd8Y4V8/Uu0pTKXIrp YFZIN4qu/Ze5t29eVY86pEVWyNib7xCzt6n8wmn0YplpRYzEMMIJKr7+pt9QVISDd+ZA K3bQ== X-Gm-Message-State: APjAAAV+EndVXAk4ppTj9SPzQnSPfs2OHkJAJWVN1NNAN2wYqrJyjCNR 9F7OkPeO2M0unuEW88lFXaqzoWqV21cHYA== X-Google-Smtp-Source: APXvYqxGjPF+kvZobt3ndd57e0J8cIy5FA7wdFldKnvqADf0nQHm5Fy15Hii56pIWC3eVZOoy4fG6NGLJXG+CQ== X-Received: by 2002:a0d:e14d:: with SMTP id k74mr23507585ywe.364.1566388466112; Wed, 21 Aug 2019 04:54:26 -0700 (PDT) Date: Wed, 21 Aug 2019 12:49:20 +0100 In-Reply-To: <20190821114955.12788-1-maennich@google.com> Message-Id: <20190821114955.12788-6-maennich@google.com> Mime-Version: 1.0 References: <20190813121733.52480-1-maennich@google.com> <20190821114955.12788-1-maennich@google.com> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog Subject: [PATCH v3 05/11] module: add config option MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS From: Matthias Maennich To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, maennich@google.com, arnd@arndb.de, geert@linux-m68k.org, gregkh@linuxfoundation.org, hpa@zytor.com, jeyu@kernel.org, joel@joelfernandes.org, kstewart@linuxfoundation.org, linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-modules@vger.kernel.org, linux-scsi@vger.kernel.org, linux-usb@vger.kernel.org, lucas.de.marchi@gmail.com, maco@android.com, maco@google.com, michal.lkml@markovi.net, mingo@redhat.com, oneukum@suse.com, pombredanne@nexb.com, sam@ravnborg.org, sspatil@google.com, stern@rowland.harvard.edu, tglx@linutronix.de, usb-storage@lists.one-eyed-alien.net, x86@kernel.org, yamada.masahiro@socionext.com, Andrew Morton , Johannes Weiner , Mauro Carvalho Chehab , David Howells , Patrick Bellasi , Dan Williams , Adrian Reber , Richard Guy Briggs Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 Reviewed-by: Greg Kroah-Hartman Signed-off-by: Matthias Maennich --- init/Kconfig | 13 +++++++++++++ kernel/module.c | 11 +++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index bd7d650d4a99..cc28561288a7 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -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 diff --git a/kernel/module.c b/kernel/module.c index 57e8253f2251..7c934aaae2d3 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -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; }