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