All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Garrett <matthew.garrett@nebula.com>
To: linux-kernel@vger.kernel.org
Cc: linux-security-module@vger.kernel.org, linux-efi@vger.kernel.org,
	kexec@lists.infradead.org, linux-pci@vger.kernel.org,
	Matthew Garrett <matthew.garrett@nebula.com>
Subject: [PATCH 06/12] x86: Require CAP_COMPROMISE_KERNEL for IO port access
Date: Mon, 18 Mar 2013 17:32:27 -0400	[thread overview]
Message-ID: <1363642353-30749-6-git-send-email-matthew.garrett@nebula.com> (raw)
In-Reply-To: <1363642353-30749-1-git-send-email-matthew.garrett@nebula.com>

IO port access would permit users to gain access to PCI configuration
registers, which in turn (on a lot of hardware) give access to MMIO register
space. This would potentially permit root to trigger arbitrary DMA, so lock
it down by default.

Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
---
 arch/x86/kernel/ioport.c | 4 ++--
 drivers/char/mem.c       | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
index 4ddaf66..f505995 100644
--- a/arch/x86/kernel/ioport.c
+++ b/arch/x86/kernel/ioport.c
@@ -28,7 +28,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
 
 	if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
 		return -EINVAL;
-	if (turn_on && !capable(CAP_SYS_RAWIO))
+	if (turn_on && (!capable(CAP_SYS_RAWIO) || !capable(CAP_COMPROMISE_KERNEL)))
 		return -EPERM;
 
 	/*
@@ -103,7 +103,7 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
 		return -EINVAL;
 	/* Trying to gain more privileges? */
 	if (level > old) {
-		if (!capable(CAP_SYS_RAWIO))
+		if (!capable(CAP_SYS_RAWIO) || !capable(CAP_COMPROMISE_KERNEL))
 			return -EPERM;
 	}
 	regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 2c644af..7eee4d8 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -597,6 +597,9 @@ static ssize_t write_port(struct file *file, const char __user *buf,
 	unsigned long i = *ppos;
 	const char __user *tmp = buf;
 
+	if (!capable(CAP_COMPROMISE_KERNEL))
+		return -EPERM;
+
 	if (!access_ok(VERIFY_READ, buf, count))
 		return -EFAULT;
 	while (count-- > 0 && i < 65536) {
-- 
1.8.1.2


WARNING: multiple messages have this Message-ID (diff)
From: Matthew Garrett <matthew.garrett@nebula.com>
To: linux-kernel@vger.kernel.org
Cc: linux-pci@vger.kernel.org, linux-security-module@vger.kernel.org,
	linux-efi@vger.kernel.org, kexec@lists.infradead.org,
	Matthew Garrett <matthew.garrett@nebula.com>
Subject: [PATCH 06/12] x86: Require CAP_COMPROMISE_KERNEL for IO port access
Date: Mon, 18 Mar 2013 17:32:27 -0400	[thread overview]
Message-ID: <1363642353-30749-6-git-send-email-matthew.garrett@nebula.com> (raw)
In-Reply-To: <1363642353-30749-1-git-send-email-matthew.garrett@nebula.com>

IO port access would permit users to gain access to PCI configuration
registers, which in turn (on a lot of hardware) give access to MMIO register
space. This would potentially permit root to trigger arbitrary DMA, so lock
it down by default.

Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
---
 arch/x86/kernel/ioport.c | 4 ++--
 drivers/char/mem.c       | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
index 4ddaf66..f505995 100644
--- a/arch/x86/kernel/ioport.c
+++ b/arch/x86/kernel/ioport.c
@@ -28,7 +28,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
 
 	if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
 		return -EINVAL;
-	if (turn_on && !capable(CAP_SYS_RAWIO))
+	if (turn_on && (!capable(CAP_SYS_RAWIO) || !capable(CAP_COMPROMISE_KERNEL)))
 		return -EPERM;
 
 	/*
@@ -103,7 +103,7 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
 		return -EINVAL;
 	/* Trying to gain more privileges? */
 	if (level > old) {
-		if (!capable(CAP_SYS_RAWIO))
+		if (!capable(CAP_SYS_RAWIO) || !capable(CAP_COMPROMISE_KERNEL))
 			return -EPERM;
 	}
 	regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 2c644af..7eee4d8 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -597,6 +597,9 @@ static ssize_t write_port(struct file *file, const char __user *buf,
 	unsigned long i = *ppos;
 	const char __user *tmp = buf;
 
+	if (!capable(CAP_COMPROMISE_KERNEL))
+		return -EPERM;
+
 	if (!access_ok(VERIFY_READ, buf, count))
 		return -EFAULT;
 	while (count-- > 0 && i < 65536) {
-- 
1.8.1.2


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  parent reply	other threads:[~2013-03-18 21:34 UTC|newest]

Thread overview: 133+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-18 21:32 [PATCH 01/12] Security: Add CAP_COMPROMISE_KERNEL Matthew Garrett
2013-03-18 21:32 ` Matthew Garrett
2013-03-18 21:32 ` [PATCH 02/12] SELinux: define mapping for CAP_COMPROMISE_KERNEL Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32 ` [PATCH 03/12] Secure boot: Add a dummy kernel parameter that will switch on Secure Boot mode Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32 ` [PATCH 04/12] efi: Enable secure boot lockdown automatically when enabled in firmware Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32 ` [PATCH 05/12] PCI: Require CAP_COMPROMISE_KERNEL for PCI BAR access Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-27 15:03   ` Josh Boyer
2013-03-27 15:03     ` Josh Boyer
2013-03-27 15:08     ` Kyle McMartin
2013-03-27 15:08       ` Kyle McMartin
2013-03-28 12:46       ` Josh Boyer
2013-03-28 12:46         ` Josh Boyer
2013-03-18 21:32 ` Matthew Garrett [this message]
2013-03-18 21:32   ` [PATCH 06/12] x86: Require CAP_COMPROMISE_KERNEL for IO port access Matthew Garrett
2013-03-20  1:00   ` H. Peter Anvin
2013-03-20  1:00     ` H. Peter Anvin
2013-03-18 21:32 ` [PATCH 07/12] ACPI: Limit access to custom_method Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32 ` [PATCH 08/12] asus-wmi: Restrict debugfs interface Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32 ` [PATCH 09/12] Require CAP_COMPROMISE_KERNEL for /dev/mem and /dev/kmem access Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32 ` [PATCH 10/12] acpi: Ignore acpi_rsdp kernel parameter in a secure boot environment Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-19  8:47   ` Dave Young
2013-03-19  8:47     ` Dave Young
2013-03-19  8:47     ` Dave Young
2013-03-19 11:19     ` Josh Boyer
2013-03-19 11:19       ` Josh Boyer
2013-03-19 11:19       ` Josh Boyer
2013-03-19 17:07       ` [PATCH v2] " Josh Boyer
2013-03-19 17:07         ` Josh Boyer
2013-03-18 21:32 ` [PATCH 11/12] x86: Require CAP_COMPROMISE_KERNEL for MSR writing Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32 ` [PATCH 12/12] kexec: Require CAP_SYS_COMPROMISE_KERNEL Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-18 21:32   ` Matthew Garrett
2013-03-19  4:47 ` [PATCH 01/12] Security: Add CAP_COMPROMISE_KERNEL James Morris
2013-03-19  4:47   ` James Morris
2013-03-19  4:47   ` James Morris
2013-03-20  1:03   ` H. Peter Anvin
2013-03-20  1:03     ` H. Peter Anvin
2013-03-20 16:41   ` Mimi Zohar
2013-03-20 16:41     ` Mimi Zohar
2013-03-20 16:49     ` Matthew Garrett
2013-03-20 16:49       ` Matthew Garrett
2013-03-20 16:49       ` Matthew Garrett
2013-03-20 16:49       ` Matthew Garrett
2013-03-20 18:01       ` Mimi Zohar
2013-03-20 18:01         ` Mimi Zohar
2013-03-20 18:01         ` Mimi Zohar
2013-03-20 18:12         ` Matthew Garrett
2013-03-20 18:12           ` Matthew Garrett
2013-03-20 18:12           ` Matthew Garrett
2013-03-20 18:12           ` Matthew Garrett
2013-03-20 19:16           ` Mimi Zohar
2013-03-20 19:16             ` Mimi Zohar
2013-03-20 19:16             ` Mimi Zohar
2013-03-20 19:16             ` Mimi Zohar
2013-03-20 20:37             ` Matthew Garrett
2013-03-20 20:37               ` Matthew Garrett
2013-03-20 20:37               ` Matthew Garrett
2013-03-20 20:37               ` Matthew Garrett
2013-03-20 21:11               ` Mimi Zohar
2013-03-20 21:11                 ` Mimi Zohar
2013-03-20 21:11                 ` Mimi Zohar
2013-03-20 21:18                 ` Matthew Garrett
2013-03-20 21:18                   ` Matthew Garrett
2013-03-20 21:18                   ` Matthew Garrett
2013-03-20 21:18                   ` Matthew Garrett
2013-03-21 13:43                   ` Vivek Goyal
2013-03-21 13:43                     ` Vivek Goyal
2013-03-21 13:43                     ` Vivek Goyal
2013-03-21 13:43                     ` Vivek Goyal
2013-03-21 15:37                     ` Serge E. Hallyn
2013-03-21 15:37                       ` Serge E. Hallyn
2013-03-21 15:37                       ` Serge E. Hallyn
2013-03-21 15:37                       ` Serge E. Hallyn
2013-03-21 15:52                       ` Vivek Goyal
2013-03-21 15:52                         ` Vivek Goyal
2013-03-21 15:52                         ` Vivek Goyal
2013-03-21 15:52                         ` Vivek Goyal
2013-03-21 15:58                         ` Serge E. Hallyn
2013-03-21 15:58                           ` Serge E. Hallyn
2013-03-21 15:58                           ` Serge E. Hallyn
2013-03-21 15:58                           ` Serge E. Hallyn
2013-03-21 16:04                           ` Vivek Goyal
2013-03-21 16:04                             ` Vivek Goyal
2013-03-21 16:04                             ` Vivek Goyal
2013-03-21 16:19                             ` Serge E. Hallyn
2013-03-21 16:19                               ` Serge E. Hallyn
2013-03-21 16:19                               ` Serge E. Hallyn
2013-03-21 16:19                               ` Serge E. Hallyn
2013-03-21 17:15                               ` Vivek Goyal
2013-03-21 17:15                                 ` Vivek Goyal
2013-03-21 17:15                                 ` Vivek Goyal
2013-03-21 17:15                                 ` Vivek Goyal
2013-03-21  1:58     ` James Morris
2013-03-21  1:58       ` James Morris
2013-03-19  7:18 ` Yves-Alexis Perez
2013-03-19  7:18   ` Yves-Alexis Perez
2013-03-20  1:02 ` H. Peter Anvin
2013-03-20  1:02   ` H. Peter Anvin
2013-03-20  1:05   ` H. Peter Anvin
2013-03-20  1:05     ` H. Peter Anvin
2013-03-20 13:15   ` Matthew Garrett
2013-03-20 13:15     ` Matthew Garrett
2013-03-20 13:15     ` Matthew Garrett
2013-03-20 13:15     ` Matthew Garrett
2013-03-20 15:03     ` H. Peter Anvin
2013-03-20 15:03       ` H. Peter Anvin
2013-03-20 15:03       ` H. Peter Anvin
2013-03-20 15:03       ` H. Peter Anvin
2013-03-20 15:14       ` Matthew Garrett
2013-03-20 15:14         ` Matthew Garrett
2013-03-20 15:14         ` Matthew Garrett
2013-03-20 15:14         ` Matthew Garrett
2013-03-20 16:45         ` H. Peter Anvin
2013-03-20 16:45           ` H. Peter Anvin
2013-03-20 16:45           ` H. Peter Anvin
2013-03-20  1:05 [PATCH 06/12] x86: Require CAP_COMPROMISE_KERNEL for IO port access Matthew Garrett
2013-03-20  1:05 ` Matthew Garrett
2013-03-20  1:05 ` Matthew Garrett
2013-03-20  1:05 ` Matthew Garrett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1363642353-30749-6-git-send-email-matthew.garrett@nebula.com \
    --to=matthew.garrett@nebula.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.