Blob Blame History Raw
From aa2c63fe074c0074a44cc89641e955ba9948e428 Mon Sep 17 00:00:00 2001
From: Matthew Garrett <mjg59@srcf.ucam.org>
Date: Fri, 8 Feb 2013 11:12:13 -0800
Subject: [PATCH 10/16] x86: Restrict MSR access when securelevel is set

Patch-mainline: Queued in subsystem maintainer repository
Git-repo: https://github.com/mjg59/linux
Git-commit: aa2c63fe074c0074a44cc89641e955ba9948e428
References: fate#320387

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 <mjg59@srcf.ucam.org>
Acked-by: Lee, Chun-Yi <jlee@suse.com>
---
 arch/x86/kernel/msr.c |    8 ++++++++
 1 file changed, 8 insertions(+)

--- a/arch/x86/kernel/msr.c
+++ b/arch/x86/kernel/msr.c
@@ -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 *fi
 	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,
 			err = -EBADF;
 			break;
 		}
+		if (get_securelevel() > 0) {
+			err = -EPERM;
+			break;
+		}
 		if (copy_from_user(&regs, uregs, sizeof regs)) {
 			err = -EFAULT;
 			break;