Received: by 10.192.165.156 with SMTP id m28csp935095imm; Wed, 11 Apr 2018 09:30:49 -0700 (PDT) X-Google-Smtp-Source: AIpwx48DW+95PXfH8hBTRWHSOkSrc/MgypHHDW91uzlEz+IaigmAfHG7wxyXvPJ9IH4FiMmvpPX5 X-Received: by 2002:a17:902:2941:: with SMTP id g59-v6mr5827251plb.55.1523464249216; Wed, 11 Apr 2018 09:30:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523464249; cv=none; d=google.com; s=arc-20160816; b=kP7GJvz6JxWOks4mFXeDYvxYishRUEQr9HtyDY49bRZyvhDSBMfz7L/yOeJsH5l8vO ww6ZBK9scZrvPoCmiAjRcC5V4I0sXq0zDQN2fGXzKIHZ7i3AliSLODiZM5PlVKIP0itj mbSEVD9gAM1v0MeAXPe67kg+fqKYnhLGVUSNdw4/yj4o+NMuQ9/bo10cKA1m3vCqbMwA cdcRERr1+vdva9vsCGy/Nuq3crgPg+YBU3KmcJLmu2FTDU6LMwe1Q1vMIvlMJzuAAS0Z q7H1cUzij66AC/Dl9gbZLak1GIRvsdTsRiw23FCU6FIRZ1lc1WwQzN2U7/ZFOZ4HOjl9 BbSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:arc-authentication-results; bh=IIikW/ZtBOD4HMlg7lT1fV9LiBJH1HoN2/YJQhFxjCI=; b=SVpJWoFbaGqYNcEX1oVDjOjmyGZKUyoA6/sHWsDgsep5QTL77ailoI6yLUHOgMzmW7 hNn0PPTpiHMVeE+8+WPrhNVBZE/xwajdLnQ/UiF+On6SuOo7/EkX5S0NXjL8FsAORXM4 03jX6BOKUVN5IA2pllYuG3AXjruDoHESg5qgdpu7/lYZ2gLmldMdaHZfuzkKKh0o6DHR bZrNFcK2ZJ/S4mm9Q6LxhU68LlfoRWMH/sA8wH/F7ZDm0GKCU0yf+2xfEynkDkLMCY/r KEdidiBfGF9NCe7VqwRvJNaTnfuuvcL8aJn+Pa18BLsp3PMkjhuBd0hNRFHh24XgZ417 MYkw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c15si956101pgn.25.2018.04.11.09.30.11; Wed, 11 Apr 2018 09:30:49 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754287AbeDKQ0l (ORCPT + 99 others); Wed, 11 Apr 2018 12:26:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54384 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754271AbeDKQ0i (ORCPT ); Wed, 11 Apr 2018 12:26:38 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8FE5B406F890; Wed, 11 Apr 2018 16:26:37 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-8.rdu2.redhat.com [10.10.120.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA8EF2024CA4; Wed, 11 Apr 2018 16:26:36 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 18/24] Lock down module params that specify hardware parameters (eg. ioport) From: David Howells To: torvalds@linux-foundation.org Cc: linux-man@vger.kernel.org, linux-api@vger.kernel.org, jmorris@namei.org, linux-kernel@vger.kernel.org, dhowells@redhat.com, linux-security-module@vger.kernel.org Date: Wed, 11 Apr 2018 17:26:36 +0100 Message-ID: <152346399627.4030.8043878470312297727.stgit@warthog.procyon.org.uk> In-Reply-To: <152346387861.4030.4408662483445703127.stgit@warthog.procyon.org.uk> References: <152346387861.4030.4408662483445703127.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 11 Apr 2018 16:26:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 11 Apr 2018 16:26:37 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 cc9108c2a1fd..2c08c4aa376b 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_warn("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;