Commit 4fc265a9 authored by Kees Cook's avatar Kees Cook Committed by Borislav Petkov

x86/mtrr: Require CAP_SYS_ADMIN for all access

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

  51d7b120 ("/proc/iomem: only expose physical resource addresses to privileged users").

[1] https://lore.kernel.org/lkml/201911110934.AC5BA313@keescook/Reported-by: default avatarZhang Xiaoxu <zhangxiaoxu5@huawei.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Acked-by: default avatarJames Morris <jamorris@linux.microsoft.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Colin Ian King <colin.king@canonical.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: linux-security-module@vger.kernel.org
Cc: Matthew Garrett <mjg59@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tyler Hicks <tyhicks@canonical.com>
Cc: x86-ml <x86@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/201911181308.63F06502A1@keescook
parent 2e30dd9e
...@@ -101,9 +101,6 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) ...@@ -101,9 +101,6 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
int length; int length;
size_t linelen; size_t linelen;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
memset(line, 0, LINE_SIZE); memset(line, 0, LINE_SIZE);
len = min_t(size_t, len, LINE_SIZE - 1); len = min_t(size_t, len, LINE_SIZE - 1);
...@@ -226,8 +223,6 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -226,8 +223,6 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
case MTRRIOC32_ADD_ENTRY: case MTRRIOC32_ADD_ENTRY:
#endif #endif
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
err = err =
mtrr_file_add(sentry.base, sentry.size, sentry.type, true, mtrr_file_add(sentry.base, sentry.size, sentry.type, true,
file, 0); file, 0);
...@@ -236,24 +231,18 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -236,24 +231,18 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
case MTRRIOC32_SET_ENTRY: case MTRRIOC32_SET_ENTRY:
#endif #endif
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
err = mtrr_add(sentry.base, sentry.size, sentry.type, false); err = mtrr_add(sentry.base, sentry.size, sentry.type, false);
break; break;
case MTRRIOC_DEL_ENTRY: case MTRRIOC_DEL_ENTRY:
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
case MTRRIOC32_DEL_ENTRY: case MTRRIOC32_DEL_ENTRY:
#endif #endif
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
err = mtrr_file_del(sentry.base, sentry.size, file, 0); err = mtrr_file_del(sentry.base, sentry.size, file, 0);
break; break;
case MTRRIOC_KILL_ENTRY: case MTRRIOC_KILL_ENTRY:
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
case MTRRIOC32_KILL_ENTRY: case MTRRIOC32_KILL_ENTRY:
#endif #endif
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
err = mtrr_del(-1, sentry.base, sentry.size); err = mtrr_del(-1, sentry.base, sentry.size);
break; break;
case MTRRIOC_GET_ENTRY: case MTRRIOC_GET_ENTRY:
...@@ -279,8 +268,6 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -279,8 +268,6 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
case MTRRIOC32_ADD_PAGE_ENTRY: case MTRRIOC32_ADD_PAGE_ENTRY:
#endif #endif
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
err = err =
mtrr_file_add(sentry.base, sentry.size, sentry.type, true, mtrr_file_add(sentry.base, sentry.size, sentry.type, true,
file, 1); file, 1);
...@@ -289,8 +276,6 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -289,8 +276,6 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
case MTRRIOC32_SET_PAGE_ENTRY: case MTRRIOC32_SET_PAGE_ENTRY:
#endif #endif
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
err = err =
mtrr_add_page(sentry.base, sentry.size, sentry.type, false); mtrr_add_page(sentry.base, sentry.size, sentry.type, false);
break; break;
...@@ -298,16 +283,12 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -298,16 +283,12 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
case MTRRIOC32_DEL_PAGE_ENTRY: case MTRRIOC32_DEL_PAGE_ENTRY:
#endif #endif
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
err = mtrr_file_del(sentry.base, sentry.size, file, 1); err = mtrr_file_del(sentry.base, sentry.size, file, 1);
break; break;
case MTRRIOC_KILL_PAGE_ENTRY: case MTRRIOC_KILL_PAGE_ENTRY:
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
case MTRRIOC32_KILL_PAGE_ENTRY: case MTRRIOC32_KILL_PAGE_ENTRY:
#endif #endif
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
err = mtrr_del_page(-1, sentry.base, sentry.size); err = mtrr_del_page(-1, sentry.base, sentry.size);
break; break;
case MTRRIOC_GET_PAGE_ENTRY: case MTRRIOC_GET_PAGE_ENTRY:
...@@ -410,6 +391,8 @@ static int mtrr_open(struct inode *inode, struct file *file) ...@@ -410,6 +391,8 @@ static int mtrr_open(struct inode *inode, struct file *file)
return -EIO; return -EIO;
if (!mtrr_if->get) if (!mtrr_if->get)
return -ENXIO; return -ENXIO;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
return single_open(file, mtrr_seq_show, NULL); return single_open(file, mtrr_seq_show, NULL);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment