Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp944709ybl; Wed, 21 Aug 2019 07:51:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwm8bgHKA55xZDoMY5J1S55cVX+hhPT8OzNGzBdxT8uy/oWhVFKPRQrRGuVU9jkUKmd4QYQ X-Received: by 2002:a63:550d:: with SMTP id j13mr29772983pgb.173.1566399080597; Wed, 21 Aug 2019 07:51:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566399080; cv=none; d=google.com; s=arc-20160816; b=WiPynl+Ps/MI7AMr9Hca9jJQpkroppqlsT6omYCfTP5CS8ERnB4y8gPal8F9QLQhtM 3Sa9FCnryQ68sEMMdy/V/ynuFRLmF8lRZEQOq4kB1iUNEWZNGjGu/oiw1ZudUUB8rAWD xK0bhU2Ca27SSDScctxo93xvz6BUpxyXhvNa29vUXddh4rK72sZtEQWoXPEQhc+XtIlO rh6rk70FjMZpbwI/3robb78etsaZVvo5Rqb2AMeNHfq1CmEGf4wIpIbKD8/vasnI9G2e e4hAIv6nabxbM2exmKInlAK88jQUS8ldo/QMRQppA9PgevNEk6X22Zj971uVt1oljb7E GHXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=PMfgpvV4p29AlBNiXlEti/BQa916MI0li39A4AvOT8o=; b=yWZFLlEjhzkgpa/+RC/eHyBIeNlSSqimRDUXUh9Uzy9NzBPnhiNbdOZCWGJt95qxXy ztO91RiByIpqMWIzQhPjYePBafZ3BczhHXPtrPuNSqGiJ28kSXB+4PBNXBS3GIVsQA5p 7Wh2Tl/b/ranUgyZ5xQQa0AktzBRVgT2uTTWL1Z6yeHen1SRYixQkXnj668tP9E3FUsF K7jLusfZclNJfhIxGhc24SmvXtxIpn/7E0uOuCzJnQIU+sEzMnqLORG1x8gkdMBb11Sh sJYfsJtuXLBtmYYmYnulfXEydDTzbTQMUlODVbGzeVIKTn8OqVr+sAjJA1CxzNI25bzn qtyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=abTPfEJh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 132si14467004pgc.134.2019.08.21.07.51.05; Wed, 21 Aug 2019 07:51:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=abTPfEJh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727903AbfHULy3 (ORCPT + 99 others); Wed, 21 Aug 2019 07:54:29 -0400 Received: from mail-yb1-f202.google.com ([209.85.219.202]:52203 "EHLO mail-yb1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727874AbfHULy1 (ORCPT ); Wed, 21 Aug 2019 07:54:27 -0400 Received: by mail-yb1-f202.google.com with SMTP id m137so1328094ybf.18 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=QZb+UyPr1TNMsExJrSQWmW5Nn7AcuVRRBU8KyhhwZHzgrrpVP+5jhr+TzupDpYv/Lc Xoko128n6FhNhfQD4OJMpkBAw+WkZakgaov2rowo7pLSThQZdQxtBHY0dCTAFd+v1DVc /mnexrE/LswA6gymK+IsG8L4KbdaZW/8JHTROmjyAMs3M7psVQJhP/ICYKpGUdCYuduv VqTuFqsjTBoQig90o2l382AwhKbn6FJzXpG+sjm71zfio3FrF2/zFAu01rq6msO6esG9 3KfYBUsuwexEQrQoIVWW/rK9OyBu++4AR4vIYuqG4mg5F6DDsEbYwGRVjWMgOBr8aBzX jwpA== X-Gm-Message-State: APjAAAWCEkcuGa1Du7Y4NYAH44lTe6fji2DMy2VP3MYbekP7uSp9JHeG IbpkkwTy9oDzTywHPbJ94GIB/IOGwvhsJS7APZqOBmYkGV1Yj90RycHcvBTiN2awb7onj5X5VN0 wnN+QNhpX42AgwlRN1MTEMm1VzqV2LmDHe4iUdbJT0LWs8NXFR0OfSYyNpLEGtLivQqlx4m2ZVn M= 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; } -- 2.23.0.rc1.153.gdeed80330f-goog