Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3318808ybc; Mon, 18 Nov 2019 13:13:31 -0800 (PST) X-Google-Smtp-Source: APXvYqzboRNZ1N1mo76t0kVgj0F/UfLeNo484NMDOzpRSoWTsafHuoYdK3puUKsBrjcdfhMrcbTB X-Received: by 2002:a17:906:e110:: with SMTP id gj16mr27312185ejb.124.1574111611207; Mon, 18 Nov 2019 13:13:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574111611; cv=none; d=google.com; s=arc-20160816; b=S756fELqAlEJh1NwdNHJFIA3PnGJAwnyp7j3HhKDxEadYWSoKSXFlsqYdSesHEhVcK ys89rFghcak3wmbwT/6ZXzqnfJEVNq5rEs5ombIfAWogWaVLTM15Q+bpOQQYXUK7ZyK5 T3EcDNhgixSyQp+4UuDk70qVsO5JU5zz5Hud0KCSR/oJu1+Eh/IT/IowcRh1KjKiun7R A37jN5XjQ6I0XPJOun+ew+dBYoOivG9sxNTMA69p486IP8lnCyx+MXlJjIGRNPg8fvjv kKdthIHqAOeTeE/dXnJweEdTe1IyuGwQg38WQlNopKzAXhL7HpVGlHqMxLdYbs6I98Jt UTMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=brNqL6zVPSQ5JwzRtAwRvqEQVxU2P5eqAvSAOt7aHtM=; b=yONENQkAhnKBMdby+bAT790hPgU1MyIoKTWAA4iEYy0nMId7W1vg+5ZhJF/su0CyYK TCPwPM444cQxbB/0gaBTkH1qJvpX3KDhKDWNaufY593olS3QH1fWPilZpPGYq8XvPXJI FbjznR96Z7yclX98OK04b8fFlZa4nB4/eDVpfVf8qwQLAzX4jnB8W7MIq343EsoxAtXl Byf+wj1HgqPm05iS68VArMVESjZElhKZJ2DgmY/SuYjzUim59QF2hqfW/w+yNviVdyIm mnowsEe5AUmanZDwGB5Z/7iaxSIyRurf0azzDyYFzNVrGuvt07oTkWDfWWt52myagkU+ P2dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XQ6hYXLY; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s2si14863770edi.413.2019.11.18.13.13.03; Mon, 18 Nov 2019 13:13:31 -0800 (PST) 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=@chromium.org header.s=google header.b=XQ6hYXLY; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726714AbfKRVJZ (ORCPT + 99 others); Mon, 18 Nov 2019 16:09:25 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:37284 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726698AbfKRVJY (ORCPT ); Mon, 18 Nov 2019 16:09:24 -0500 Received: by mail-pf1-f196.google.com with SMTP id p24so10989709pfn.4 for ; Mon, 18 Nov 2019 13:09:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=brNqL6zVPSQ5JwzRtAwRvqEQVxU2P5eqAvSAOt7aHtM=; b=XQ6hYXLYNFdMJoP1GZVRliyiJQVEbteGvbXFZF1JTflyx/WMljc3NDpIeLFmJ3DWmp GG/P3cyqEgHEmUYIP3yH6SudKNm86c9ObEHQYLbq6Y+oKpxKqSBjL5rxns0mO231ltlx 5EddBxhbWUcKPvULCBAfpmVdBQtRNgw5I9ezk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=brNqL6zVPSQ5JwzRtAwRvqEQVxU2P5eqAvSAOt7aHtM=; b=Uz8n/lXEaxzCEw6oD4m3AhzxQvDX27cFxatN2/m35ToZJlfTPJix2GP2kPx/Aekrgo x7yufMf5+nxyPwM4pvjctfBViBBeyPv1rC6UbAieE3VKMT6fTzgIkLV1WTaLtXLhMxiT 9qlcqdwvEk6CUcvPh+eGoAxczbkTu8ul8e0ihuRu9XWjiQA9BnEfJTJI9YXFPSFFUtn7 JNZ7Wkyxi84sDgYev2VW+BFxyUz5A76r4/rfS073YoZnKp3QW0vjSGzUodRttl0RENbH DpCWv5On2wNZ/sG9rYuoma420pBlZB5oexHYSTDSl/o0O8f4ROLfcB0eqL9kNKjVsBIL /0Pw== X-Gm-Message-State: APjAAAXxC3VW8uUPePMR8HAWo2cnHU6tDs0tx5OvgQyP/c88/+ev9DA/ PMELbZsn6/S5gAfDWEevWm1lQg== X-Received: by 2002:a63:731a:: with SMTP id o26mr1504137pgc.108.1574111363777; Mon, 18 Nov 2019 13:09:23 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id i11sm8346900pgl.73.2019.11.18.13.09.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2019 13:09:22 -0800 (PST) Date: Mon, 18 Nov 2019 13:09:21 -0800 From: Kees Cook To: Borislav Petkov Cc: Thomas Gleixner , Zhang Xiaoxu , linux-kernel@vger.kernel.org, x86@kernel.org, tyhicks@canonical.com, colin.king@canonical.com, linux-security-module@vger.kernel.org, Matthew Garrett Subject: [PATCH] x86/mtrr: Require CAP_SYS_ADMIN for all access Message-ID: <201911181308.63F06502A1@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Zhang Xiaoxu noted that physical address locations for MTRR were visible to non-root users, which could be considered an information leak. In discussing[1] the options for solving this, it sounded like just moving the capable check into open() was the first step. If this breaks userspace, then we will have a test case for the more conservative approaches discussed in the thread. In summary: - MTRR should check capabilities at open time (or retain the checks on the opener's permissions for later checks). - changing the DAC permissions might break something that expects to open mtrr when not uid 0. - if we leave the DAC permissions alone and just move the capable check to the opener, we should get the desired protection. (i.e. check against CAP_SYS_ADMIN not just the wider uid 0.) - if that still breaks things, as in userspace expects to be able to read other parts of the file as non-uid-0 and non-CAP_SYS_ADMIN, then we need to censor the contents using the opener's permissions. For example, as done in other /proc cases, like commit 51d7b120418e ("/proc/iomem: only expose physical resource addresses to privileged users"). [1] https://lore.kernel.org/lkml/201911110934.AC5BA313@keescook/ Reported-by: Zhang Xiaoxu Signed-off-by: Kees Cook --- arch/x86/kernel/cpu/mtrr/if.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c index 4d36dcc1cf87..9c86aeae1b14 100644 --- a/arch/x86/kernel/cpu/mtrr/if.c +++ b/arch/x86/kernel/cpu/mtrr/if.c @@ -101,9 +101,6 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) int length; size_t linelen; - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - memset(line, 0, LINE_SIZE); len = min_t(size_t, len, LINE_SIZE - 1); @@ -226,8 +223,6 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) #ifdef CONFIG_COMPAT case MTRRIOC32_ADD_ENTRY: #endif - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; err = mtrr_file_add(sentry.base, sentry.size, sentry.type, true, file, 0); @@ -236,24 +231,18 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) #ifdef CONFIG_COMPAT case MTRRIOC32_SET_ENTRY: #endif - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; err = mtrr_add(sentry.base, sentry.size, sentry.type, false); break; case MTRRIOC_DEL_ENTRY: #ifdef CONFIG_COMPAT case MTRRIOC32_DEL_ENTRY: #endif - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; err = mtrr_file_del(sentry.base, sentry.size, file, 0); break; case MTRRIOC_KILL_ENTRY: #ifdef CONFIG_COMPAT case MTRRIOC32_KILL_ENTRY: #endif - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; err = mtrr_del(-1, sentry.base, sentry.size); break; case MTRRIOC_GET_ENTRY: @@ -279,8 +268,6 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) #ifdef CONFIG_COMPAT case MTRRIOC32_ADD_PAGE_ENTRY: #endif - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; err = mtrr_file_add(sentry.base, sentry.size, sentry.type, true, file, 1); @@ -289,8 +276,6 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) #ifdef CONFIG_COMPAT case MTRRIOC32_SET_PAGE_ENTRY: #endif - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; err = mtrr_add_page(sentry.base, sentry.size, sentry.type, false); break; @@ -298,16 +283,12 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) #ifdef CONFIG_COMPAT case MTRRIOC32_DEL_PAGE_ENTRY: #endif - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; err = mtrr_file_del(sentry.base, sentry.size, file, 1); break; case MTRRIOC_KILL_PAGE_ENTRY: #ifdef CONFIG_COMPAT case MTRRIOC32_KILL_PAGE_ENTRY: #endif - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; err = mtrr_del_page(-1, sentry.base, sentry.size); break; case MTRRIOC_GET_PAGE_ENTRY: @@ -381,6 +362,8 @@ static int mtrr_open(struct inode *inode, struct file *file) return -EIO; if (!mtrr_if->get) return -ENXIO; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; return single_open(file, mtrr_seq_show, NULL); } -- 2.17.1 -- Kees Cook