]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
x86: Restrict MSR access when securelevel is set
authorMatthew Garrett <matthew.garrett@nebula.com>
Mon, 9 Sep 2013 22:49:44 +0000 (15:49 -0700)
committerSantosh Shilimkar <santosh.shilimkar@oracle.com>
Mon, 10 Aug 2015 16:24:06 +0000 (09:24 -0700)
Orabug: 21539498

Permitting write access to MSRs allows userspace to modify the running
kernel. Prevent this if securelevel has been set. Based on a patch by Kees
Cook.

Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
arch/x86/kernel/msr.c

index 113e70784854fb55bdc0eb08fe5e38bee4946126..979517195ec031b4fa757a2a24ba8da3e2b900e7 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/notifier.h>
 #include <linux/uaccess.h>
 #include <linux/gfp.h>
+#include <linux/security.h>
 
 #include <asm/processor.h>
 #include <asm/msr.h>
@@ -105,6 +106,9 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
        int err = 0;
        ssize_t bytes = 0;
 
+       if (get_securelevel() > 0)
+               return -EPERM;
+
        if (count % 8)
                return -EINVAL; /* Invalid chunk size */
 
@@ -152,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
                        err = -EBADF;
                        break;
                }
+               if (get_securelevel() > 0) {
+                       err = -EPERM;
+                       break;
+               }
                if (copy_from_user(&regs, uregs, sizeof regs)) {
                        err = -EFAULT;
                        break;