linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "tip-bot2 for Zhang Xiaoxu" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>,
	Borislav Petkov <bp@suse.de>, "H. Peter Anvin" <hpa@zytor.com>,
	Colin Ian King <colin.king@canonical.com>,
	Ingo Molnar <mingo@redhat.com>, Kees Cook <keescook@chromium.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Tyler Hicks <tyhicks@canonical.com>, "x86-ml" <x86@kernel.org>,
	zhangxiaoxu@huawei.com, Ingo Molnar <mingo@kernel.org>,
	Borislav Petkov <bp@alien8.de>,
	linux-kernel@vger.kernel.org
Subject: [tip: x86/mtrr] x86/mtrr: Restrict MTRR ranges dumping and ioctl()
Date: Fri, 08 Nov 2019 20:06:58 -0000	[thread overview]
Message-ID: <157324361834.29376.5328593346754751963.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20191105071714.27376-1-zhangxiaoxu5@huawei.com>

The following commit has been merged into the x86/mtrr branch of tip:

Commit-ID:     d5a8b06841082ead88493eb918dd646a12c19d8e
Gitweb:        https://git.kernel.org/tip/d5a8b06841082ead88493eb918dd646a12c19d8e
Author:        Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
AuthorDate:    Tue, 05 Nov 2019 15:17:14 +08:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Fri, 08 Nov 2019 20:59:40 +01:00

x86/mtrr: Restrict MTRR ranges dumping and ioctl()

/proc/mtrr dumps the physical memory ranges of the variable range MTRRs
along with their respective sizes and caching attributes. Since that
file is world-readable, it presents a small information leak about the
physical address ranges of a system which should be blocked.

Make that file root-only.

Make the ioctl root-only as well because the $NAME read ioctl also
allows access. Replace the checks in the write ioctls with a single one
on entry.

 [ bp: rewrite commit message. ]

Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Colin Ian King <colin.king@canonical.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tyler Hicks <tyhicks@canonical.com>
Cc: x86-ml <x86@kernel.org>
Cc: zhangxiaoxu@huawei.com
Link: https://lkml.kernel.org/r/20191105071714.27376-1-zhangxiaoxu5@huawei.com
---
 arch/x86/kernel/cpu/mtrr/if.c | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
index 4d36dcc..8e0cee8 100644
--- a/arch/x86/kernel/cpu/mtrr/if.c
+++ b/arch/x86/kernel/cpu/mtrr/if.c
@@ -84,6 +84,15 @@ mtrr_file_del(unsigned long base, unsigned long size,
 	return reg;
 }
 
+static ssize_t
+mtrr_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	return seq_read(file, buf, size, ppos);
+}
+
 /*
  * seq_file can seek but we ignore it.
  *
@@ -165,6 +174,9 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
 	struct mtrr_gentry gentry;
 	void __user *arg = (void __user *) __arg;
 
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
 	memset(&gentry, 0, sizeof(gentry));
 
 	switch (cmd) {
@@ -226,8 +238,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 +246,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 +283,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 +291,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 +298,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:
@@ -387,7 +383,7 @@ static int mtrr_open(struct inode *inode, struct file *file)
 static const struct file_operations mtrr_fops = {
 	.owner			= THIS_MODULE,
 	.open			= mtrr_open,
-	.read			= seq_read,
+	.read			= mtrr_read,
 	.llseek			= seq_lseek,
 	.write			= mtrr_write,
 	.unlocked_ioctl		= mtrr_ioctl,
@@ -436,7 +432,7 @@ static int __init mtrr_if_init(void)
 	    (!cpu_has(c, X86_FEATURE_CENTAUR_MCR)))
 		return -ENODEV;
 
-	proc_create("mtrr", S_IWUSR | S_IRUGO, NULL, &mtrr_fops);
+	proc_create("mtrr", 0600, NULL, &mtrr_fops);
 	return 0;
 }
 arch_initcall(mtrr_if_init);

       reply	other threads:[~2019-11-08 20:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20191105071714.27376-1-zhangxiaoxu5@huawei.com>
2019-11-08 20:06 ` tip-bot2 for Zhang Xiaoxu [this message]
     [not found] ` <201911081236.57A127A@keescook>
     [not found]   ` <20191108205031.GH4503@zn.tnic>
     [not found]     ` <201911081320.5D3CD1A4CD@keescook>
     [not found]       ` <20191108213307.GI4503@zn.tnic>
2019-11-11 17:56         ` [PATCH] x86/mtrr: only administrator can read the configurations Kees Cook
2019-11-12 17:49           ` Borislav Petkov
2019-11-12 22:35             ` Kees Cook
2019-11-13 21:47               ` Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=157324361834.29376.5328593346754751963.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=bp@alien8.de \
    --cc=bp@suse.de \
    --cc=colin.king@canonical.com \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tyhicks@canonical.com \
    --cc=x86@kernel.org \
    --cc=zhangxiaoxu5@huawei.com \
    --cc=zhangxiaoxu@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).