From: Matthew Garrett Date: Fri, 8 Feb 2013 19:12:13 +0000 (-0800) Subject: x86: Restrict MSR access when securelevel is set X-Git-Tag: archive/raspbian/4.9.82-1+deb9u3+rpi1_jessie~10^2~41 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=aa5c8d9b215285ccb2f8a6c4cc5ce992a4b4cb62;p=linux-4.9.git x86: Restrict MSR access when securelevel is set 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 Signed-off-by: Matthew Garrett Gbp-Pq: Topic features/all/securelevel Gbp-Pq: Name x86-restrict-msr-access-when-securelevel-is-set.patch --- diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c index 7f3550acde1b..531d8dbc955d 100644 --- a/arch/x86/kernel/msr.c +++ b/arch/x86/kernel/msr.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -83,6 +84,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 */ @@ -130,6 +134,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(®s, uregs, sizeof regs)) { err = -EFAULT; break;