Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp788873ybl; Fri, 9 Aug 2019 13:59:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBYOhJhvgk79v7Mps7sL6z1ZoKpMXIRQ+wK2JmIsmWOJAdK8SOes4v6n8rUfmytpJdEOig X-Received: by 2002:aa7:93bb:: with SMTP id x27mr24158166pff.10.1565384395339; Fri, 09 Aug 2019 13:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565384395; cv=none; d=google.com; s=arc-20160816; b=JgaYCJlNokTmLSyWjC/yDo9hDj3vVUFaBYGLcSGw4uRVBvNY7WGfK85jkrWwe2xECy J0g/a8RxQSrXg4H0e+2HvM6OMcArcW9VvLTy5AuwSrx9IpT57xEdivXprk+l8Dc13pub kaW8cpNYfRV7CmvIFUyxbKQRPix/nsWf5bUc1S9i7/gIuT7j97mDSqMMHhEer1PP/+P5 kALZp/fO6TYy5zf7gtTlFwyepd3CV8AKa/WBz1jrjzuteVCMb8uPEHeatcjVv4m1B2qE 6NbTfdJclngDB4vVPLwz/HAlsJ7JMHuW5RwAIu6oA0+1wH+5CNKj1MMtRwFYy5nWIYa6 HNCg== 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=eBQXEUJ4xG90qgyQmq59kEIpLR58l2iNnVeP+k7a23g=; b=rlmMFR39YXsaNf8uOePENGeKEeBPJAu7P8Ra0kkohTpoupScIfxl14b6dEo4cxUY9S /Q0yq6pGGRSn7028Bnto4ioiiM2VYwLxT+iMHLDzXUyi3teXsw/VfiVcQ3LTJtwc0L+Z 3xfOWufom4DnUWNj2UaK/uPZ3jSeJ8A4gcfeXEepeAm1IWYPmx+5EXZoA9IQNOFZmBlY T+RKotSszGPTn8QRTXy4yZK6DDVjVTKlN8gKAX3mnr2x/u0EjqV4/50mcRXDQtnsQYKF pIgXc9RkUSqz51CUfzhlWYEBMoUYE6dJzA31UjEJblwlVEs5ktPPhxEeyPcHqkr05qt6 aDjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=rMxaNl5A; 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 h32si52615406pld.402.2019.08.09.13.59.39; Fri, 09 Aug 2019 13:59:55 -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=rMxaNl5A; 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 S1727498AbfHIU6t (ORCPT + 99 others); Fri, 9 Aug 2019 16:58:49 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:42222 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726137AbfHIU6t (ORCPT ); Fri, 9 Aug 2019 16:58:49 -0400 Received: by mail-pg1-f201.google.com with SMTP id l12so13715131pgt.9 for ; Fri, 09 Aug 2019 13:58: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=eBQXEUJ4xG90qgyQmq59kEIpLR58l2iNnVeP+k7a23g=; b=rMxaNl5AsKq6YNwTXpua2sqDDA43FqhpUtJC7gyxqzGgupGFiMHIUyB7l/nDHPs2OE K1BnIyyLb4DD+tUtFKgJFNisQHq2ugAQS39MnTZyf86sdiRJxTaX2Se11M5G2oXCq1Wg 0XavWtwnmGlFHooR8j5BIhZ/+SzDyom/Ot0q/CX4iFTq/lDouinbfWVfjYMDvCGJ+yos 2GA2CzGK6mxom7oMSYSMg6U4hpjfeX1ncO5zQwsj3yXdv6Ms/GHmfhu1tt8sOp+y1p0G kDb1s2/Z7cxAzLMyBY+zRoZu3brFFWE0QBlXQA+vq0Xo3kTawHhb3EjzQLimYqVmEKZ0 p4gg== 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=eBQXEUJ4xG90qgyQmq59kEIpLR58l2iNnVeP+k7a23g=; b=V+0KJMLco33WkCg7O9hTIIvv7bK1F2/JKhaerHxGLaarH/2PqFqWURcxousqaLFhco ONioKHx6V6Jp4TiTIESQGo31XHDVDibqRMLBdcYqwj+YKkRc6byM8vvrnNeA+Mm08Vne mLwIf7lqN/qZmlzYkYgba8/xHUvRsMTmRbCp6QIyCw/7yjV46uSbSRYBtawe9latHaUq jmhLrDJXBrEz1vmLsGcYBecRFOHmvrSxUOfLWlGVsjgyLP4LR37AeprU7ixxYcZuUND7 M5GhjHxcdHSxo/WqTpJtmKjlJMQmMQvYo1m8Fob6mFgfzL5Y1xpTh+hEfPsu/Asq5h6z X1JA== X-Gm-Message-State: APjAAAVn36Nf8iyt7zFpI5lVLvaWye/+6RbYXschODJeyY2CuDqZqRGA XRxBW4KypA0fcw6xULw/f2DxJhW/Yf3aHD6cZSpe/w== X-Received: by 2002:a63:484a:: with SMTP id x10mr18952600pgk.430.1565384328279; Fri, 09 Aug 2019 13:58:48 -0700 (PDT) Date: Fri, 9 Aug 2019 13:58:22 -0700 In-Reply-To: <20190808111246.GA29211@linux-8ccs> Message-Id: <20190809205822.109793-1-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190808111246.GA29211@linux-8ccs> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog Subject: [PATCH V39] 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, linux-api@vger.kernel.org, David Howells , Alan Cox , Matthew Garrett , Kees Cook , Jessica Yu 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 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 Reviewed-by: Kees Cook Cc: Jessica Yu --- include/linux/security.h | 1 + kernel/params.c | 21 ++++++++++++++++----- security/lockdown/lockdown.c | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 8f7048395114..43fa3486522b 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -113,6 +113,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 cf448785d058..8e56f8b12d8f 100644 --- a/kernel/params.c +++ b/kernel/params.c @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef CONFIG_SYSFS /* Protects all built-in parameters, modules use their own param_lock */ @@ -96,13 +97,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) { + if (kp->flags & KERNEL_PARAM_FL_HWPARAM && + security_locked_down(LOCKDOWN_MODULE_PARAMETERS)) + return false; + 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); } + + return true; } static int parse_one(char *param, @@ -132,8 +139,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])) + err = params[i].ops->set(val, ¶ms[i]); + else + err = -EPERM; kernel_param_unlock(params[i].mod); return err; } @@ -553,8 +562,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)) + 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 00a3a6438dd2..5177938cfa0d 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] = "modifying 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.23.0.rc1.153.gdeed80330f-goog