Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6089518ybh; Wed, 7 Aug 2019 17:09:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzG9gd3pVW/4lU7yETFnQWf9jjy1UQpxfRfwfAI1W+jgtVKpyhUCRy8rPfCKKi7205kUT1U X-Received: by 2002:a17:902:848b:: with SMTP id c11mr10630073plo.217.1565222976981; Wed, 07 Aug 2019 17:09:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565222976; cv=none; d=google.com; s=arc-20160816; b=XmUphcIycF5jDC5ynqpgAiemI9JK7ZO5PycqJyd4zLmFT4mFygP0ny7ufA4Q4qWqpb w1i0ItEwvOHyJtPiI4Kn0SBp1qIkC5HFMNIgy9wbjsJtqh/y09/csAOIrMtUKstujAEa 9eLkn8AoguRpERiNXCLoBV9BHHQlAd1Pq3jdsxyMhSQcIWNPPYLl8z0MkN7fdzJd3eWb aBTowk6nesLLJVBGHR7Mmjwwgy/MeqqmBwCjDQHRQ/hSDmvv76M5YCWOKy22UfK4oKTf f5YlBPCMrqbCunFo1/DYl82si+hcJ7SyVx3TpJOScxHoQiN9U1sVZvt0gJeUgYgVrCAD INZA== 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=6aduxenHUMLAdRKp6MotdzoJ4uvtyrO7PmmmKZqbApo=; b=tghBDRl9HPwxlYDJ9E0b3lZftk5yj6Oc2CKhJEiEBbbvos3dXfWW1zQnLSL0iZoGo7 n0vvkB9JVFa3H9+3UmvrnKVxx8php9amGHcjqTD6UfeLmTIN2KO1LZtWj6J/xshDMSig oApXciWHq69Cfg4/VSpqJMYxw0LYdpC4dQAxzaVbn0SZB9dkDXDsJQVgsdPXRZbvk4zW 64tT5ACRlaD+N0LYciNKTO8J7CV/hjZ7qdVB9XrJYhgJ1kqHbMOy64evznObBioiIFAh G+K/XxzWBD9V1+5TkPHb4k7O50bccPOKvRT0tFEK8+Vz7JVnMAK0idCaYjfDvDw/ljxh +bGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=j5tx231Y; 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 j185si50430263pge.91.2019.08.07.17.09.21; Wed, 07 Aug 2019 17:09:36 -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=j5tx231Y; 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 S2389706AbfHHAIR (ORCPT + 99 others); Wed, 7 Aug 2019 20:08:17 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:32840 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389691AbfHHAIO (ORCPT ); Wed, 7 Aug 2019 20:08:14 -0400 Received: by mail-pl1-f202.google.com with SMTP id f5so4485822plr.0 for ; Wed, 07 Aug 2019 17:08:14 -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=6aduxenHUMLAdRKp6MotdzoJ4uvtyrO7PmmmKZqbApo=; b=j5tx231Y0mVNxYudig/8nj6kcHI+p4B8cQgzlKqpa7X0AVceG335EYqBUA+mUrAHYJ 7pQB/gqcMV0g7OR97dEU7gjfUcWBnQSwLHnR7tjrDsuqxNFB9L1h8fbLHOS4iz0gFmgK eCE3n7IHAU2Pl/Lo6eHFS9LIBrQr3F9IqumqP0jbbLTLbf3FNvHvPAdb7qrHWWz91VcM bcEcNYV4F8IOvbgRkTkPkZlA2+YUPkuN1VDPrx7U5+hRkFBgJzwcGd7F5dCAiElTi+Gz IB9MOaGbPPKxOMRfbalnm85x8IBy0brYdm604Tlu+Msvn4/r14ZzZ19Uss9ZWzIiunMV 2hMg== 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=6aduxenHUMLAdRKp6MotdzoJ4uvtyrO7PmmmKZqbApo=; b=rYN43acQy1HNyGQ7og1ROFNGpDeXT/y9vwLe9L8eEJHrmrEMVJwboa3xrU4QxYRn6P 0PynBEX0ThaNLVWGENLh39xe/0qwWi598iBXOHJFwSquuZbMdOlKkjuqFm9WTYkHInWG k1y4GlbVtsIuw58wsxDeLsqgq9CWAD85oBwOFJ3NSrR4vz16Pj7O4VH+fO81SYXfh93X kobyoWIjfMi/hbDExSJutDI7TI+YHv3ks+zgttUm1Br9Xt+Rcj3+/AhjrWAZYEH5EiPT OVZYD/WJFhZhdne2e3FuDjq/iH25JMvnCLNhtZNSb6uVJZPMU6OmkrxGANmdOFCvONh4 w+Wg== X-Gm-Message-State: APjAAAVo0EHl+kjIPXijN1nBWOJfiSjuD9+mg4TimGVRs8llfN2jsqj6 b/cwtyWf5j8yqocpGlw0+QyrbiuyNwSsTImnRC/2zA== X-Received: by 2002:a63:de07:: with SMTP id f7mr10283613pgg.213.1565222893329; Wed, 07 Aug 2019 17:08:13 -0700 (PDT) Date: Wed, 7 Aug 2019 17:07:11 -0700 In-Reply-To: <20190808000721.124691-1-matthewgarrett@google.com> Message-Id: <20190808000721.124691-20-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190808000721.124691-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog Subject: [PATCH V38 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 , 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 | 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 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..35f138fce762 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; } @@ -541,6 +550,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, @@ -553,8 +568,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.22.0.770.g0f2c4a37fd-goog