Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp1480436ybd; Wed, 26 Jun 2019 18:51:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDhyOC7Q/9vUpAVP6pcvYfSZO4WUnBEFTfhAyh9L3kNx/ME+CVi2N3AhUFk9U1dc4wBXZf X-Received: by 2002:a17:90a:9f0b:: with SMTP id n11mr2652309pjp.98.1561600309147; Wed, 26 Jun 2019 18:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561600309; cv=none; d=google.com; s=arc-20160816; b=zgubMSHWji4cultB83cY8xzaCfKy7r+mPsJusXFNO3YyWnyxC6BiH3LyMzRfL2Mr3P CcwiS5+WoYiU9B/RIS80+GAGj4cU+Pj9fcgyQacSaaJAwQsoWiUXcBGau60YFJu71BcY EIlKMVBSLPbI8eVvJF45E9nmztyXlzwimmh29yYIC9nnAJ22Vl8a8UvIuHyJq5b7fstM cRqfRY8FSUFsTeQ7jC3lK6KvVikNiWJ1M8evG7kcLwaS1d9lrVtJBWzKQqgpmg4H7G9f aCJv87Jcrv1HwvRVl8Yaa4C7HSaFGZdnQlJXwGcdsjDe3Cx1RUAYtXRt6WgC7zPXoWvN ALyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=WM6uPUMLAmx7AP//rA8fowctOYQ/AmGg6H1et0/fxeQ=; b=AeUhRANO/M9VWaFdRS9rZcBL/azd/oi8EBCmoqybNAEksAASxGmGri0gN3fCmuF9Z+ vFKwidh4q/cxJNV7V93zsrgRHsB1hllilYWTrOtUi4hxkkn+CqCXgqFQmm5RuVWUOC5M wRTaw1aCs53Gy30xLn9QzMbIKYanUY/8p6pWhaSyxSdiaWLH03YvhKNeNtrSWhT/of9e 8TjhWhzur69v2dSaVmRgplsWfvPolmqCZ8L6aooDEuUU1uegvchZYVI1NvEuc/zkvAYV Ts4VtELZR67kxj5nk+lRy0fFMyzNBNHLVecclnlVFgOasubwqzJoyxGsBOaEubU32xUr P9aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@axtens.net header.s=google header.b=GPMwtTE+; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q2si940765plh.59.2019.06.26.18.51.10; Wed, 26 Jun 2019 18:51: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; dkim=pass header.i=@axtens.net header.s=google header.b=GPMwtTE+; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727200AbfF0Btj (ORCPT + 99 others); Wed, 26 Jun 2019 21:49:39 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:36980 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727185AbfF0Bth (ORCPT ); Wed, 26 Jun 2019 21:49:37 -0400 Received: by mail-pl1-f193.google.com with SMTP id bh12so350834plb.4 for ; Wed, 26 Jun 2019 18:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=WM6uPUMLAmx7AP//rA8fowctOYQ/AmGg6H1et0/fxeQ=; b=GPMwtTE+s4FHnzPCcPaRaca9fFeyCQYdJ+4Pqg5rcV3ZwX+TwMkiFLiXjV7VmYZu0A 1nqQJfF8eMw4jnIntXT1hv8EkQ40QlF4yk/dLswm4q4y2Feza716oSK+ZuJdrAXPJBj2 6ox2mI9ni7ucak56kwY5tWcZ650K94V5UXoNE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=WM6uPUMLAmx7AP//rA8fowctOYQ/AmGg6H1et0/fxeQ=; b=J9dE+fFz5z2eU7InKtnliaEJuypgOn/GAoHLfhQ76CPvbX5/0EZlOv8J18br/WPxa/ zApdL91TbJ/96hL3jpEtc3ZVwRLR6Y4BEmPgPlFqpqV6+Qvdy/UptDcYrMvn5RBrUeLR Su+j9Gc62mCAR7IXmy6XnklMgy5rttdvs1bbgZWJWMA1y/6M1cqBW2YyRd9G0k3IzDWJ Ivf2dObrsy/UYWVMvRkpz1B0wfSKK0Qb/f5EWWppEpfDuvLt9BQHh54okttfoNny6z0W mGU7pA0vH/ei+fYrVn31xeesHd2dHjtA7qKId90FEWxSjxH/nRABDjgaR7HQpyQMY6vA GYbA== X-Gm-Message-State: APjAAAUx4ifwcwepPnMSaHvNOjUlDoRyiwVn57G+TV1eM/ArrYZl+z/I vTekLSnywknPALU9NCXwHalCUQ== X-Received: by 2002:a17:902:e582:: with SMTP id cl2mr1492748plb.60.1561600176417; Wed, 26 Jun 2019 18:49:36 -0700 (PDT) Received: from localhost (ppp167-251-205.static.internode.on.net. [59.167.251.205]) by smtp.gmail.com with ESMTPSA id o16sm395909pgi.36.2019.06.26.18.49.34 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 26 Jun 2019 18:49:35 -0700 (PDT) From: Daniel Axtens To: Matthew Garrett , jmorris@namei.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, David Howells , Alan Cox , Matthew Garrett Subject: Re: [PATCH V34 19/29] Lock down module params that specify hardware parameters (eg. ioport) In-Reply-To: <20190622000358.19895-20-matthewgarrett@google.com> References: <20190622000358.19895-1-matthewgarrett@google.com> <20190622000358.19895-20-matthewgarrett@google.com> Date: Thu, 27 Jun 2019 11:49:30 +1000 Message-ID: <87ef3f3ihh.fsf@dja-thinkpad.axtens.net> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Matthew Garrett writes: > 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 > Signed-off-by: Matthew Garrett > --- > include/linux/security.h | 1 + > kernel/params.c | 27 ++++++++++++++++++++++----- > security/lockdown/lockdown.c | 1 + > 3 files changed, 24 insertions(+), 5 deletions(-) > > diff --git a/include/linux/security.h b/include/linux/security.h > index 61e3f4a62d16..88064d7f6827 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -92,6 +92,7 @@ enum lockdown_reason { > LOCKDOWN_ACPI_TABLES, > LOCKDOWN_PCMCIA_CIS, > LOCKDOWN_TIOCSSERIAL, > + LOCKDOWN_MODULE_PARAMETERS, > LOCKDOWN_INTEGRITY_MAX, > LOCKDOWN_CONFIDENTIALITY_MAX, > }; > diff --git a/kernel/params.c b/kernel/params.c > index ce89f757e6da..f94fe79e331d 100644 > --- a/kernel/params.c > +++ b/kernel/params.c > @@ -24,6 +24,7 @@ > #include > #include > #include > +#include > > #ifdef CONFIG_SYSFS > /* Protects all built-in parameters, modules use their own param_lock */ > @@ -108,13 +109,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 && > + security_locked_down(LOCKDOWN_MODULE_PARAMETERS)) > + return false; > + return true; > } Should this test occur before tainting the kernel? Regards, Daniel > > static int parse_one(char *param, > @@ -144,8 +151,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 +562,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 +580,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; > diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c > index c89046dc2155..d03c4c296af7 100644 > --- a/security/lockdown/lockdown.c > +++ b/security/lockdown/lockdown.c > @@ -28,6 +28,7 @@ static char *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { > [LOCKDOWN_ACPI_TABLES] = "modified ACPI tables", > [LOCKDOWN_PCMCIA_CIS] = "direct PCMCIA CIS storage", > [LOCKDOWN_TIOCSSERIAL] = "reconfiguration of serial port IO", > + [LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters", > [LOCKDOWN_INTEGRITY_MAX] = "integrity", > [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality", > }; > -- > 2.22.0.410.gd8fdbe21b5-goog