From patchwork Thu Aug 8 00:07:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 11082933 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 3BA6913B1 for ; Thu, 8 Aug 2019 00:08:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BB5528AB7 for ; Thu, 8 Aug 2019 00:08:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1ECB928AC8; Thu, 8 Aug 2019 00:08:22 +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 B91EB28AB7 for ; Thu, 8 Aug 2019 00:08:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389714AbfHHAIU (ORCPT ); Wed, 7 Aug 2019 20:08:20 -0400 Received: from mail-pl1-f201.google.com ([209.85.214.201]:45815 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389712AbfHHAIT (ORCPT ); Wed, 7 Aug 2019 20:08:19 -0400 Received: by mail-pl1-f201.google.com with SMTP id y9so54389046plp.12 for ; Wed, 07 Aug 2019 17:08:19 -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=FIo2fvd2ZRzAOCkOenwujWvUsEXtgcv+etTkEkyg1xI=; b=HlI7Rts+QtzRW4GLuPztGKD87kPYSJpcD3OcKSF7X6Jeb+mS7V0K0o+ODF2M0pKW/6 hoY6BTWys59pq3J8kngkIEDoJ8ojECUgkCBjrcuXzU5T8AXEKSmWLwFa4Jy7mn/EcZ4u RRE/0qOmbsCIC3kJ9SRcwCm+0BZFq2evgpl7Mmuc9q6iwW2hNjJ7riryL9Hzqmp6OuAs GesRAMU2i91ckfgz34XqnR1B+65GbI2mHCxbduG2FfQqEFUm1sOXOXwTRYeKAkJS8Sp7 mqVoQHjMSHglXCEX3tU0WQnI3P/41LOjRdnHyq5Unv+q0EPR+Ej9jiXyD0QsqXXsMK6c QTZA== 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=FIo2fvd2ZRzAOCkOenwujWvUsEXtgcv+etTkEkyg1xI=; b=HYLJrQAs5+iV8Pb1cRr2qiFSrZt2Wl5g9ZKG5jVv/240zrHddAs3ZFAdcvN8efvCJy lBhPo3a7weXtJ5FzwSuv9lc/snWmDQUpxmU0SgV2QO64H70j5rpb/C66nvfNiIX6Tk2I NKP3df6pR2TnPCHgLAP3vepKfXipWQs/aIFDo6TtY4m1DgBKwC7k7/N47V3I2q94dJSv mCGsQvB9+pc36RFUvb0Uesk0TBBRYxiVIzHiAe/Lnujr48VCwbHUrzAoJycujTZZDOfD yhP0nlSh7v8eBz/Wz6hAjnApzJUbzBr2lC+rqNKclvLPA2+/Da5FabOB3ruNlZrqWa80 mFlQ== X-Gm-Message-State: APjAAAUbAZdFlZc2FRG2+u31csCdpu2bYf6SmYXP8qMIZ68xSXd1k9UC h+KyLU0e0QyWBGVUtyzbqxsAaa98In4+PBVy7AQMaQ== X-Google-Smtp-Source: APXvYqzKY7wvOvJHauSEDw4LLkZ+RRap1la60w5DLrgKijg8RNHHD9Stn9spETv3/0cCk0lp2pzTJcX639VU3uIGImRybg== X-Received: by 2002:a65:458d:: with SMTP id o13mr9885716pgq.34.1565222898530; Wed, 07 Aug 2019 17:08:18 -0700 (PDT) Date: Wed, 7 Aug 2019 17:07:13 -0700 In-Reply-To: <20190808000721.124691-1-matthewgarrett@google.com> Message-Id: <20190808000721.124691-22-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 21/29] Lock down /proc/kcore 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 , Matthew Garrett , Kees Cook Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: David Howells Disallow access to /proc/kcore when the kernel is locked down to prevent access to cryptographic data. This is limited to lockdown confidentiality mode and is still permitted in integrity mode. Signed-off-by: David Howells Signed-off-by: Matthew Garrett Reviewed-by: Kees Cook --- fs/proc/kcore.c | 5 +++++ include/linux/security.h | 1 + security/lockdown/lockdown.c | 1 + 3 files changed, 7 insertions(+) diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index f5834488b67d..ee2c576cc94e 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "internal.h" @@ -545,6 +546,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) static int open_kcore(struct inode *inode, struct file *filp) { + int ret = security_locked_down(LOCKDOWN_KCORE); + + if (ret) + return ret; if (!capable(CAP_SYS_RAWIO)) return -EPERM; diff --git a/include/linux/security.h b/include/linux/security.h index 3f7b6a4cd65a..f0cffd0977d3 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -116,6 +116,7 @@ enum lockdown_reason { LOCKDOWN_MODULE_PARAMETERS, LOCKDOWN_MMIOTRACE, LOCKDOWN_INTEGRITY_MAX, + LOCKDOWN_KCORE, LOCKDOWN_CONFIDENTIALITY_MAX, }; diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c index 37b7d7e50474..c050b82c7f9f 100644 --- a/security/lockdown/lockdown.c +++ b/security/lockdown/lockdown.c @@ -31,6 +31,7 @@ static char *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { [LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters", [LOCKDOWN_MMIOTRACE] = "unsafe mmio", [LOCKDOWN_INTEGRITY_MAX] = "integrity", + [LOCKDOWN_KCORE] = "/proc/kcore access", [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality", };