Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1239023ybi; Fri, 21 Jun 2019 17:07:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWsxDct5zItgYjbFUKUbZ+x7zlkkopFfn1+WBVCV9VJGoAf9efC+UZjbiPk2qt/85dHwWA X-Received: by 2002:a17:90a:37ac:: with SMTP id v41mr9510316pjb.6.1561162037290; Fri, 21 Jun 2019 17:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561162037; cv=none; d=google.com; s=arc-20160816; b=iK23kCZ3l0dj8nLdKxDhle5EMWNUFXHQTXBF5hPfyBQ2onkiIAAcs1IGu98+rqNF9P uTh5Q7KmkYQuS8xsAokuDx9/E8XBTJexz0D21vfOdZEdDqTzcU9SbXlE7Z15Y6t8XEGX 8AC0Y2ENppTOXtgnPv2Ys7MTyknSc+pz09cw4+j502nfVrI7vjnWyGvx2X+dqzerjlsh GuiTFfzjeFO6YzK+R380WajAusqf1n7IK3PbJqh8qmU5L+O5qIprf6k4XDx1Yk/Uw6Xu 8fIDbBAKBAt7BhX8VK8Z2umzYoffZKmzGbE1SDgRSeboz4e40ybHwwEAYPTge1/eF32K 1Nuw== 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=DcYA884YGcGGdCYTloo9C5D9P2JdZYIZcuEODFPPdyE=; b=Dc/mcDbLyCLbiIOuIVqhs2kDfKhdsaLrjMc5glZv01m3UWn3XiW6Mh1nYyrYz5D31M fkr3fo+GxjntBmu0fUSzGhjZiMOKnZKSOzcEcLVQ1B2qoMS/5boaWNgDgLaChbgXzuZ3 A+uFY1QzOERv7SN3EPSAdK8jvO2JLWl5zUgb+jTg7ErkglnTsAm7Tp83Z/nU6aT/Ecg0 yOozFIZsUTklbDgAeLRzi7CDj+jeNRHoE1nqOjzrVp/46fWYyBP5ZIqm94aIM2NYoD1H kPyoN7h9xqIuNw67VYZtm/bYJU3yyFbXQeph9aVPMOc/UzcjtkrDLT+CxdTk3piUBZD9 sfyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FpAHE5nR; 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 d23si3962601pjw.37.2019.06.21.17.07.02; Fri, 21 Jun 2019 17:07:17 -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=FpAHE5nR; 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 S1727050AbfFVAGT (ORCPT + 99 others); Fri, 21 Jun 2019 20:06:19 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:33888 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726871AbfFVAEu (ORCPT ); Fri, 21 Jun 2019 20:04:50 -0400 Received: by mail-pf1-f202.google.com with SMTP id y75so5338526pfg.1 for ; Fri, 21 Jun 2019 17:04:50 -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=DcYA884YGcGGdCYTloo9C5D9P2JdZYIZcuEODFPPdyE=; b=FpAHE5nRtiq8twPnU2FiA6jLImIS9YqBG0kkzIsrD6OMZiYkZhbmyWygj1lEcLXZZ+ yhPzB8BSVUrcxee0v1jTxwyQ+nDZsbbYuryXRtruDeoXjlY+p0iYOpq7nKjz9aZ0qq/p /O2JfwU8M+jWw2Z9YuevmCs/eS4sN2vfFq0jaX0aCGRgjNzl5lcYsGj/jofyaP4CDRBt 0bN/jvJwoS9wJWP3S5dhVrX0L2iP0Ds82S3TrvG0hfHn3FJuvD905D7I/fQBcx2+B0Aa 273VlHuxdXiojhQkEa6oLg1y3gOOQCYo8Ldrh1xgfRjUEcXzF02eN6AaKuUrFSY255is 9IxA== 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=DcYA884YGcGGdCYTloo9C5D9P2JdZYIZcuEODFPPdyE=; b=oTWqGL68p3uk/resAYrwnd66dSySfHIfORWwRER/xSMxIxbNf7VOuUeNIDZf71iE08 aTgsWlNnI1ADlkIbOgUWNvza41UwCwBZoz4b08AiRfK0XTeIABo7cBm7pshqt+4Gz1uL KOd1LPTsMK7bvxZDGvJ3bnlCDwbwbYMmhzD9Dvo2yQlxghknSdp3lE8a+Hkf94hJx1g3 uJbvWB4FsyBQrq4GGL+o2cLu3zb0/AzqycnlrigPxegp9qBOQWVwsHAHZ1OsSA+STvFP AT73L7KSQ9l4ONYy4BO16G/ZOesOnHuXqEWWL7A4rVaA2SIpVU+5IzFfuCqLCuMP8X/9 pXzA== X-Gm-Message-State: APjAAAXu6diTM8rXwjyap0D+9Ui8lXt/zfAhb9pw7W49WXQRIs890Ne3 SgigMRskvpWJlQ0tEamvRTn4Y4Y2DYGJ9ulN0YTC9g== X-Received: by 2002:a63:5152:: with SMTP id r18mr20149468pgl.94.1561161889779; Fri, 21 Jun 2019 17:04:49 -0700 (PDT) Date: Fri, 21 Jun 2019 17:03:48 -0700 In-Reply-To: <20190622000358.19895-1-matthewgarrett@google.com> Message-Id: <20190622000358.19895-20-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190622000358.19895-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [PATCH V34 19/29] 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 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 --- 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; } 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