From patchwork Mon Mar 25 22:09:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 10870207 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 B306614DE for ; Mon, 25 Mar 2019 22:11:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E6A428C1D for ; Mon, 25 Mar 2019 22:11:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92BF829067; Mon, 25 Mar 2019 22:11:56 +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 CD4E828C1D for ; Mon, 25 Mar 2019 22:11:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730384AbfCYWLt (ORCPT ); Mon, 25 Mar 2019 18:11:49 -0400 Received: from mail-oi1-f201.google.com ([209.85.167.201]:47422 "EHLO mail-oi1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731077AbfCYWKt (ORCPT ); Mon, 25 Mar 2019 18:10:49 -0400 Received: by mail-oi1-f201.google.com with SMTP id n84so4441247oia.14 for ; Mon, 25 Mar 2019 15:10:48 -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=5peyNALuutRmQZzMkIWMJWYer1k95cePDopKi9u624s=; b=Ts06+0QjEuiviBipZiSiGrSSEh1oAC6JXPVCji8k+m0Zn7BZRufrtCy2CLd89RguG/ pqF5duWLMmUdMagMdQxcHOy1Ya16712JpQfA06qm/8mDiShXQRnyP3ZBlhvYjnRIUuns REBRk+x9bmbUP/+6ON+WA3NQAqar+FQvhR92k4wnx+/dSybe3GhsixWyjYMGTlDZAf3T VjUKh6uzHjquj4+SuDrT+TyGzey7XVWBJ9NvQr6BYW4L1jumi0rW+6EkToTT9IkWJjEM BtAm5WCBi3AvlfUMG+MrRrYoH2guLFsdX3QrkudGMou3AqKjR9viLVQCcAZOry/Myn9C HIgg== 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=5peyNALuutRmQZzMkIWMJWYer1k95cePDopKi9u624s=; b=hR1TJoUI8nNvmZyeu4oTSLPBZ9hj3I3sm16PuNK4SrfjJ0G922AgqIr81Cn8M4e5il GJ9RlmlgzFpKlefzvaKBGWvHy7nH7aH13UVt0ObhIgf6g/Fh1XsWqfw9ObssAp+hC+9T DYEocGPG2Rvmnw6HqVDoaV0ZFUp+pl8lk0PDsVnyBqtiK6FrNr6NGT5njEr+fYev/u/c Ab4ARqOgm5hh1LigRbqds+XZ81/bddzl+g5Y6FuiINcf2zkELQeHjePaVH2bm7sSVdmT BH9WkSsAdOdr3sMUPgFFlZkmgRYAnm3PxkuLqB8WSyhXPXu4UIlt11N5twRlORiSfu8S XRjw== X-Gm-Message-State: APjAAAXJ9G4yRnbbYqTkp0gov419QhcQYY9xAEDkcpctGcTY7DWEeQR3 Xp8E5fQa+neuW/bhVb7uen3+Qi/ShgRBnDXgPTKTBQ== X-Google-Smtp-Source: APXvYqzrfrJ6dLUvhvcnrxQhK4/6Y5+EAbdM8OEOt13tQTMHBHg67bdirfW2qugW/qN0xzgtq59HKDHeAJRqD/lVMIYw7Q== X-Received: by 2002:aca:5108:: with SMTP id f8mr12490996oib.55.1553551848074; Mon, 25 Mar 2019 15:10:48 -0700 (PDT) Date: Mon, 25 Mar 2019 15:09:46 -0700 In-Reply-To: <20190325220954.29054-1-matthewgarrett@google.com> Message-Id: <20190325220954.29054-20-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190325220954.29054-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog Subject: [PATCH 19/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, Alan Cox , Matthew Garrett 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 Signed-off-by: Matthew Garrett --- 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;