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