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