Skip to content

Commit 95f5e95

Browse files
mjg59xjamesmorris
authored andcommitted
x86/msr: Restrict MSR access when the kernel is locked down
Writing to MSRs should not be allowed if the kernel is locked down, since it could lead to execution of arbitrary code in kernel mode. Based on a patch by Kees Cook. Signed-off-by: Matthew Garrett <mjg59@google.com> Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: Kees Cook <keescook@chromium.org> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> cc: x86@kernel.org Signed-off-by: James Morris <jmorris@namei.org>
1 parent 96c4f67 commit 95f5e95

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎arch/x86/kernel/msr.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/notifier.h>
3535
#include <linux/uaccess.h>
3636
#include <linux/gfp.h>
37+
#include <linux/security.h>
3738

3839
#include <asm/cpufeature.h>
3940
#include <asm/msr.h>
@@ -79,6 +80,10 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
7980
int err = 0;
8081
ssize_t bytes = 0;
8182

83+
err = security_locked_down(LOCKDOWN_MSR);
84+
if (err)
85+
return err;
86+
8287
if (count % 8)
8388
return -EINVAL; /* Invalid chunk size */
8489

@@ -130,6 +135,9 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
130135
err = -EFAULT;
131136
break;
132137
}
138+
err = security_locked_down(LOCKDOWN_MSR);
139+
if (err)
140+
break;
133141
err = wrmsr_safe_regs_on_cpu(cpu, regs);
134142
if (err)
135143
break;

‎include/linux/security.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ enum lockdown_reason {
109109
LOCKDOWN_HIBERNATION,
110110
LOCKDOWN_PCI_ACCESS,
111111
LOCKDOWN_IOPORT,
112+
LOCKDOWN_MSR,
112113
LOCKDOWN_INTEGRITY_MAX,
113114
LOCKDOWN_CONFIDENTIALITY_MAX,
114115
};

‎security/lockdown/lockdown.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static char *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = {
2424
[LOCKDOWN_HIBERNATION] = "hibernation",
2525
[LOCKDOWN_PCI_ACCESS] = "direct PCI access",
2626
[LOCKDOWN_IOPORT] = "raw io port access",
27+
[LOCKDOWN_MSR] = "raw MSR access",
2728
[LOCKDOWN_INTEGRITY_MAX] = "integrity",
2829
[LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality",
2930
};

0 commit comments

Comments
 (0)