From patchwork Thu Feb 28 23:11:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 10834257 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 994B1139A for ; Thu, 28 Feb 2019 23:13:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89F79288E0 for ; Thu, 28 Feb 2019 23:13:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DCEB2897C; Thu, 28 Feb 2019 23:13:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2FCB2892E for ; Thu, 28 Feb 2019 23:13:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388046AbfB1XM6 (ORCPT ); Thu, 28 Feb 2019 18:12:58 -0500 Received: from mail-io1-f74.google.com ([209.85.166.74]:36248 "EHLO mail-io1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388044AbfB1XM5 (ORCPT ); Thu, 28 Feb 2019 18:12:57 -0500 Received: by mail-io1-f74.google.com with SMTP id v3so17184077iol.3 for ; Thu, 28 Feb 2019 15:12:57 -0800 (PST) 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=8KM4GPF8H/ZA8qZu4X13d5O4g08OSMJQgTj+Sn30UNM=; b=Z1+rvothKUqR2tRl+zH/aPd+au+70MAgtzcgA3i6y553uX+/QzIYSKO8X1D+XAkhO1 0cl1XIShXKMwqyV6SVOjdEECCNLnNp+Z+xJ+RdtzV7mU2UBm1BwrIw7MdCFoZGEPgTyo 9wjPyw6bEZD8qzrKYAL4ox04cDYhyezdGMVSzQSkQgBzEUNhcY/tY/qjGleZanIupMtu /RE567QzdS2BRSNaNuv19QZraWcbeTaKiX/lUHm8VfdT/iyEnAQ/QeymKlMFvz5QzdmQ 3y7uAMlcmrGK7Cd9rmYXZVD5vZxSWp/JwAVzW5gt5Xku7HymwCegv48ovK72haVv4bgM wxgA== 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=8KM4GPF8H/ZA8qZu4X13d5O4g08OSMJQgTj+Sn30UNM=; b=tQtVPuzN4duDB1VUgcyvm8i8RwFzRgmkYT+ILivvlPXzZHEbGKvhRdKBxZuGZ5RPHE R0jInrha/uV7DZE3pMcB7RNwLrWcv6ADSXJRH9s+nM6MJQ8EylQhnuMxSVPTWKHtLeuI 4bpPhmgGjRUzu+zYiUhsOQS4BDO4OOsRiAY2i21K8HyHj6QzYh2rlzgVL4yU8dB8fsib DP4N2oLwjkP/kw62J+LWNeEJ/bdN5YFs90RRdn5jYeShQMqGFgn8fPNRMHs3VpWPZY6L bAdg4kcW7vAmpcoMsKjOD+CsqglkJOb3eHOJDjECbAj/8ZK1VaMYs/FN3c27Fk5Hy2t1 /dhw== X-Gm-Message-State: AHQUAuZkDh7IqRGlLG+ZeG5TH6y/eGRDqd+zAgP/lHsJpQsrqTKYK2mV 4myCTycCZX9aQR5EyrD9jpJ136XmxEB5+5zHNCK53w== X-Google-Smtp-Source: APXvYqyYIIPpi6LMvPSKodYDlF1Q3NR9zGkxdJ+I+B3eh9JF55kOsrbcWMzonXnT5HJXudG42GD3brjdc1roSdr3TYkjjw== X-Received: by 2002:a24:612:: with SMTP id 18mr1507443itv.7.1551395576756; Thu, 28 Feb 2019 15:12:56 -0800 (PST) Date: Thu, 28 Feb 2019 15:11:56 -0800 In-Reply-To: <20190228231203.212359-1-matthewgarrett@google.com> Message-Id: <20190228231203.212359-20-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190228231203.212359-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.21.0.352.gf09ad66450-goog Subject: [PATCH 20/27] Lock down module params that specify hardware parameters (eg. ioport) From: Matthew Garrett To: jmorris@namei.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, dhowells@redhat.com Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: David Howells Provided an annotation for module parameters that specify hardware parameters (such as io ports, iomem addresses, irqs, dma channels, fixed dma buffers and other types). Suggested-by: Alan Cox Signed-off-by: David Howells --- kernel/params.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/kernel/params.c b/kernel/params.c index ce89f757e6da..8ac751c938f8 100644 --- a/kernel/params.c +++ b/kernel/params.c @@ -108,13 +108,19 @@ bool parameq(const char *a, const char *b) return parameqn(a, b, strlen(a)+1); } -static void param_check_unsafe(const struct kernel_param *kp) +static bool param_check_unsafe(const struct kernel_param *kp, + const char *doing) { if (kp->flags & KERNEL_PARAM_FL_UNSAFE) { pr_notice("Setting dangerous option %s - tainting kernel\n", kp->name); add_taint(TAINT_USER, LOCKDEP_STILL_OK); } + + if (kp->flags & KERNEL_PARAM_FL_HWPARAM && + kernel_is_locked_down("Command line-specified device addresses, irqs and dma channels")) + return false; + return true; } static int parse_one(char *param, @@ -144,8 +150,10 @@ static int parse_one(char *param, pr_debug("handling %s with %p\n", param, params[i].ops->set); kernel_param_lock(params[i].mod); - param_check_unsafe(¶ms[i]); - err = params[i].ops->set(val, ¶ms[i]); + if (param_check_unsafe(¶ms[i], doing)) + err = params[i].ops->set(val, ¶ms[i]); + else + err = -EPERM; kernel_param_unlock(params[i].mod); return err; } @@ -553,6 +561,12 @@ static ssize_t param_attr_show(struct module_attribute *mattr, return count; } +#ifdef CONFIG_MODULES +#define mod_name(mod) (mod)->name +#else +#define mod_name(mod) "unknown" +#endif + /* sysfs always hands a nul-terminated string in buf. We rely on that. */ static ssize_t param_attr_store(struct module_attribute *mattr, struct module_kobject *mk, @@ -565,8 +579,10 @@ static ssize_t param_attr_store(struct module_attribute *mattr, return -EPERM; kernel_param_lock(mk->mod); - param_check_unsafe(attribute->param); - err = attribute->param->ops->set(buf, attribute->param); + if (param_check_unsafe(attribute->param, mod_name(mk->mod))) + err = attribute->param->ops->set(buf, attribute->param); + else + err = -EPERM; kernel_param_unlock(mk->mod); if (!err) return len;