Merge branch 'x86-mtrr-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 mtrr updates from Ingo Molnar:
 "Two changes: restrict /proc/mtrr to CAP_SYS_ADMIN, plus a cleanup"

* 'x86-mtrr-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86/mtrr: Require CAP_SYS_ADMIN for all access
  x86/mtrr: Get rid of mtrr_seq_show() forward declaration
This commit is contained in:
Linus Torvalds 2020-01-28 13:06:05 -08:00
commit 511fdb7844

View File

@ -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)
#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)
#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)
#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)
#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)
#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:
@ -373,28 +354,6 @@ static int mtrr_close(struct inode *ino, struct file *file)
return single_release(ino, file); return single_release(ino, file);
} }
static int mtrr_seq_show(struct seq_file *seq, void *offset);
static int mtrr_open(struct inode *inode, struct file *file)
{
if (!mtrr_if)
return -EIO;
if (!mtrr_if->get)
return -ENXIO;
return single_open(file, mtrr_seq_show, NULL);
}
static const struct file_operations mtrr_fops = {
.owner = THIS_MODULE,
.open = mtrr_open,
.read = seq_read,
.llseek = seq_lseek,
.write = mtrr_write,
.unlocked_ioctl = mtrr_ioctl,
.compat_ioctl = mtrr_ioctl,
.release = mtrr_close,
};
static int mtrr_seq_show(struct seq_file *seq, void *offset) static int mtrr_seq_show(struct seq_file *seq, void *offset)
{ {
char factor; char factor;
@ -426,6 +385,28 @@ static int mtrr_seq_show(struct seq_file *seq, void *offset)
return 0; return 0;
} }
static int mtrr_open(struct inode *inode, struct file *file)
{
if (!mtrr_if)
return -EIO;
if (!mtrr_if->get)
return -ENXIO;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
return single_open(file, mtrr_seq_show, NULL);
}
static const struct file_operations mtrr_fops = {
.owner = THIS_MODULE,
.open = mtrr_open,
.read = seq_read,
.llseek = seq_lseek,
.write = mtrr_write,
.unlocked_ioctl = mtrr_ioctl,
.compat_ioctl = mtrr_ioctl,
.release = mtrr_close,
};
static int __init mtrr_if_init(void) static int __init mtrr_if_init(void)
{ {
struct cpuinfo_x86 *c = &boot_cpu_data; struct cpuinfo_x86 *c = &boot_cpu_data;