0f09adf
From: Matthew Garrett <matthew.garrett@nebula.com>
0f09adf
Date: Thu, 8 Mar 2012 10:35:59 -0500
0f09adf
Subject: [PATCH] x86: Lock down IO port access when module security is enabled
0f09adf
0f09adf
IO port access would permit users to gain access to PCI configuration
0f09adf
registers, which in turn (on a lot of hardware) give access to MMIO register
0f09adf
space. This would potentially permit root to trigger arbitrary DMA, so lock
0f09adf
it down by default.
0f09adf
0f09adf
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
0f09adf
---
0f09adf
 arch/x86/kernel/ioport.c | 5 +++--
0f09adf
 drivers/char/mem.c       | 4 ++++
0f09adf
 2 files changed, 7 insertions(+), 2 deletions(-)
0f09adf
0f09adf
diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
0f09adf
index 4ddaf66ea35f..00b440307419 100644
0f09adf
--- a/arch/x86/kernel/ioport.c
0f09adf
+++ b/arch/x86/kernel/ioport.c
0f09adf
@@ -15,6 +15,7 @@
0f09adf
 #include <linux/thread_info.h>
0f09adf
 #include <linux/syscalls.h>
0f09adf
 #include <linux/bitmap.h>
0f09adf
+#include <linux/module.h>
0f09adf
 #include <asm/syscalls.h>
0f09adf
 
0f09adf
 /*
0f09adf
@@ -28,7 +29,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
0f09adf
 
0f09adf
 	if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
0f09adf
 		return -EINVAL;
0f09adf
-	if (turn_on && !capable(CAP_SYS_RAWIO))
0f09adf
+	if (turn_on && (!capable(CAP_SYS_RAWIO) || secure_modules()))
0f09adf
 		return -EPERM;
0f09adf
 
0f09adf
 	/*
0f09adf
@@ -103,7 +104,7 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
0f09adf
 		return -EINVAL;
0f09adf
 	/* Trying to gain more privileges? */
0f09adf
 	if (level > old) {
0f09adf
-		if (!capable(CAP_SYS_RAWIO))
0f09adf
+		if (!capable(CAP_SYS_RAWIO) || secure_modules())
0f09adf
 			return -EPERM;
0f09adf
 	}
0f09adf
 	regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
0f09adf
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
ea45716
index 297110c12635..efe38c1bc234 100644
0f09adf
--- a/drivers/char/mem.c
0f09adf
+++ b/drivers/char/mem.c
0f09adf
@@ -27,6 +27,7 @@
0f09adf
 #include <linux/export.h>
0f09adf
 #include <linux/io.h>
0f09adf
 #include <linux/aio.h>
0f09adf
+#include <linux/module.h>
0f09adf
 
ea45716
 #include <linux/uaccess.h>
0f09adf
 
ea45716
@@ -577,6 +578,9 @@ static ssize_t write_port(struct file *file, const char __user *buf,
0f09adf
 	unsigned long i = *ppos;
0f09adf
 	const char __user *tmp = buf;
0f09adf
 
0f09adf
+	if (secure_modules())
0f09adf
+		return -EPERM;
0f09adf
+
0f09adf
 	if (!access_ok(VERIFY_READ, buf, count))
0f09adf
 		return -EFAULT;
0f09adf
 	while (count-- > 0 && i < 65536) {