Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6539786ybi; Wed, 31 Jul 2019 16:36:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxlD5gObook/OcchDUvTBXbhDnjySNS8SqqcOTusp5t6gRSloSp0xfNFqXXph89Wc7YYH8H X-Received: by 2002:a17:902:d892:: with SMTP id b18mr114950495plz.165.1564616217488; Wed, 31 Jul 2019 16:36:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564616217; cv=none; d=google.com; s=arc-20160816; b=M7N6vtb+J5pfHmXV6FB5J7RtEE2fiAQYrqPDjN/5Wv76ZgXoW13XobxvkloMnFTgHp NbMLGmnphJunvUZnjvNkQNDC02SC1zg+rbWqZPOEAPPuRtuHobkbFg/iRUhICdFgoXze jVmcdIBTW6hdCQs8PMbqHEWc4ESr6KmLLBWJSJ67U+NrDKEI/Quhj/axyOlmy5uvdYGI +IIl+fQmAgtVd1Xq2P+Tmg0k69hz6iTqXtLVQSpHxVNxcuN+BFft8qOmyESiNGX+qtsa Iij89+xJpSrrHmmTeLLuuMU8D8tUIMWP3Ka0LlMdQ0el75IGLiexZrbp+TfSdD4R3QMv HnlQ== 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=ar9F1ezXL3PnxEqF0y9aMqfwFMY9y395H3iSelAOa90=; b=ISoFdj8PW2yCaP8+AhTQY4lb5MvUdkmfcgnXWrxuYpXK1t12zLynHMVZOXoseDhi+b 7Lr91OU/wlSbQCLphXAQaNHidVQ/ZiVqGqlyBqLrutiDKG/hO7jxDcKoUjjWFxipr2ML tHn2qMdmLaahViuLv6Tm3IRQ6RruC57mr/4ew2QGTUFwNfVj4efDGLKGzptlfX7X9rao gE1on+ilz1YfGyRetqnxOv35ZhKgRHa0usOwgUY2PiRTiuapLDczykvCQFnuIIVy1TTY BHD59ZT2xSS8iaovS7L19yMTyUXTRl96PtrYjGObM6sLkqCZEFOmJiaiz0c5GGidMwhW r0qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KWryge+y; 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 s24si27308951pgi.450.2019.07.31.16.36.42; Wed, 31 Jul 2019 16:36:57 -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=KWryge+y; 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 S1728540AbfGaWS4 (ORCPT + 99 others); Wed, 31 Jul 2019 18:18:56 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:55035 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731078AbfGaWRP (ORCPT ); Wed, 31 Jul 2019 18:17:15 -0400 Received: by mail-pf1-f202.google.com with SMTP id y66so44180371pfb.21 for ; Wed, 31 Jul 2019 15:17:15 -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=ar9F1ezXL3PnxEqF0y9aMqfwFMY9y395H3iSelAOa90=; b=KWryge+ybANXRbNwbUlERn6tPnwObLcAGOMqHbxqjgpCmsk/Mut4arFhCyIb2hfV9o EB8iIwoveNQHMvvNvyxTyS/VzhNO7cqfI1jcH5rLsrEgZtM0txb1f5q8bGplFaDdTsci Hs5qgHmgKnDAxCCreraAX4kWLdnl9aI+/ysG9zmGFWxnMHaI7YpHKqGUYXKrNByUNwLA IYXzRZxeDx2m8D5owUvvR/boWpHMxnOTFIEe9l3Ogpxti1aHnVn8g4VRwrDHOBdXGeqH q8NuCf8RuwoDuvwll7S3PdWmI2wr9oFVVsM7EWoWcwcvLfKfMVMHOmO20T0SXWJ7JDzD mTOQ== 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=ar9F1ezXL3PnxEqF0y9aMqfwFMY9y395H3iSelAOa90=; b=oz5vzvnm+Q4zJEg5rd6LNQ2driFed5DejewFpI/UtgX4actYtp+UjAKYgA7/s520dX awG1Kpb4ee7hPGG8v+D3sKoBI9yaNdU0YDCve/wF7hPyUNq+55TJbiKg5tx+a1V8EA+d 6sjW239T//ZRC2OsOs+tvpipQbc7p9I4+J0xGV4agDhisiJIKtcles1rHv4dPReKu4Tw Pa4Q4/NQ2WT86SVBmD8ruOwPedqlybxKj7H3lGrqG6Z6nCvt1mAx+Zu0GhMmLxF4d+4K 9qdeHGcljWyRivGdUksl6TpP18KRympmh0mEjUpFJAbFh0l72EUhkM3LAxYGQyMM2A2r dQKg== X-Gm-Message-State: APjAAAV+i2A/dS9IVOTbrv6c1u+KHuLd6VTBwT7GpTFsdXwic7fKmv1i xz0VfYaaXzxFau2NHZdQdomS8I+6i4OwsKm7EsyS5A== X-Received: by 2002:a65:5342:: with SMTP id w2mr31174414pgr.261.1564611434315; Wed, 31 Jul 2019 15:17:14 -0700 (PDT) Date: Wed, 31 Jul 2019 15:16:07 -0700 In-Reply-To: <20190731221617.234725-1-matthewgarrett@google.com> Message-Id: <20190731221617.234725-20-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190731221617.234725-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog Subject: [PATCH V37 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 | 28 +++++++++++++++++++++++----- security/lockdown/lockdown.c | 1 + 3 files changed, 25 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..f2779a76d39a 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,20 @@ 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_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 +140,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; } @@ -541,6 +551,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 +569,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 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