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