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