Linux EFI development
 help / color / mirror / Atom feed
From: Matthew Garrett <matthew.garrett@nebula.com>
To: linux-kernel@vger.kernel.org
Cc: linux-efi@vger.kernel.org, linux-security-module@vger.kernel.org,
	Matthew Garrett <matthew.garrett@nebula.com>
Subject: [PATCH 05/15] PCI: Lock down BAR access in secure boot environments
Date: Mon, 28 Jan 2013 11:42:29 -0500	[thread overview]
Message-ID: <1359391359-25783-6-git-send-email-matthew.garrett@nebula.com> (raw)
In-Reply-To: <1359391359-25783-1-git-send-email-matthew.garrett@nebula.com>

Any hardware that can potentially generate DMA has to be locked down from
userspace in order to avoid it being possible for an attacker to cause
arbitrary kernel behaviour. Default to paranoid - in future we can
potentially relax this for sufficiently IOMMU-isolated devices.

Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
---
 drivers/pci/pci-sysfs.c | 9 +++++++++
 drivers/pci/proc.c      | 8 +++++++-
 drivers/pci/syscall.c   | 2 +-
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 9c6e9bb..b966089 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -622,6 +622,9 @@ pci_write_config(struct file* filp, struct kobject *kobj,
 	loff_t init_off = off;
 	u8 *data = (u8*) buf;
 
+	if (!capable(CAP_COMPROMISE_KERNEL))
+		return -EPERM;
+
 	if (off > dev->cfg_size)
 		return 0;
 	if (off + count > dev->cfg_size) {
@@ -928,6 +931,9 @@ pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
 	resource_size_t start, end;
 	int i;
 
+	if (!capable(CAP_COMPROMISE_KERNEL))
+		return -EPERM;
+
 	for (i = 0; i < PCI_ROM_RESOURCE; i++)
 		if (res == &pdev->resource[i])
 			break;
@@ -1035,6 +1041,9 @@ pci_write_resource_io(struct file *filp, struct kobject *kobj,
 		      struct bin_attribute *attr, char *buf,
 		      loff_t off, size_t count)
 {
+	if (!capable(CAP_COMPROMISE_KERNEL))
+		return -EPERM;
+
 	return pci_resource_io(filp, kobj, attr, buf, off, count, true);
 }
 
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 9b8505c..35580bc 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -139,6 +139,9 @@ proc_bus_pci_write(struct file *file, const char __user *buf, size_t nbytes, lof
 	int size = dp->size;
 	int cnt;
 
+	if (!capable(CAP_COMPROMISE_KERNEL))
+		return -EPERM;
+
 	if (pos >= size)
 		return 0;
 	if (nbytes >= size)
@@ -219,6 +222,9 @@ static long proc_bus_pci_ioctl(struct file *file, unsigned int cmd,
 #endif /* HAVE_PCI_MMAP */
 	int ret = 0;
 
+	if (!capable(CAP_COMPROMISE_KERNEL))
+		return -EPERM;
+
 	switch (cmd) {
 	case PCIIOC_CONTROLLER:
 		ret = pci_domain_nr(dev->bus);
@@ -259,7 +265,7 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma)
 	struct pci_filp_private *fpriv = file->private_data;
 	int i, ret;
 
-	if (!capable(CAP_SYS_RAWIO))
+	if (!capable(CAP_SYS_RAWIO) || !capable(CAP_COMPROMISE_KERNEL))
 		return -EPERM;
 
 	/* Make sure the caller is mapping a real resource for this device */
diff --git a/drivers/pci/syscall.c b/drivers/pci/syscall.c
index e1c1ec5..97e785f 100644
--- a/drivers/pci/syscall.c
+++ b/drivers/pci/syscall.c
@@ -92,7 +92,7 @@ SYSCALL_DEFINE5(pciconfig_write, unsigned long, bus, unsigned long, dfn,
 	u32 dword;
 	int err = 0;
 
-	if (!capable(CAP_SYS_ADMIN))
+	if (!capable(CAP_SYS_ADMIN) || !capable(CAP_COMPROMISE_KERNEL))
 		return -EPERM;
 
 	dev = pci_get_bus_and_slot(bus, dfn);
-- 
1.8.0.2


  parent reply	other threads:[~2013-01-28 16:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-28 16:42 [PATCH 00/15] Secure boot policy support Matthew Garrett
2013-01-28 16:42 ` [PATCH 01/15] Secure boot: Add new capability Matthew Garrett
2013-01-28 16:42 ` [PATCH 02/15] SELinux: define mapping for new Secure Boot capability Matthew Garrett
2013-01-28 16:42 ` Matthew Garrett [this message]
2013-01-28 16:42 ` [PATCH 07/15] ACPI: Limit access to custom_method Matthew Garrett
2013-01-28 16:42 ` [PATCH 08/15] asus-wmi: Restrict debugfs interface Matthew Garrett
2013-01-28 16:42 ` [PATCH 09/15] Restrict /dev/mem and /dev/kmem in secure boot setups Matthew Garrett
2013-01-28 16:42 ` [PATCH 10/15] acpi: Ignore acpi_rsdp kernel parameter in a secure boot environment Matthew Garrett
2013-02-17  9:00   ` Dave Young
     [not found]     ` <CABqxG0cJGp7UEREvMW49QA0BfDXPsyEbAuMMLZwcHPdUAKT+Dw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-02-20 13:39       ` Josh Boyer
2013-01-28 16:42 ` [PATCH 11/15] Add EFI signature data types Matthew Garrett
2013-01-28 16:42 ` [PATCH 12/15] Add an EFI signature blob parser and key loader Matthew Garrett
2013-01-28 16:42 ` [PATCH 13/15] MODSIGN: Add module certificate blacklist keyring Matthew Garrett
     [not found] ` <1359391359-25783-1-git-send-email-matthew.garrett-05XSO3Yj/JvQT0dZR+AlfA@public.gmane.org>
2013-01-28 16:42   ` [PATCH 03/15] Secure boot: Add a dummy kernel parameter that will switch on Secure Boot mode Matthew Garrett
2013-01-28 16:42   ` [PATCH 04/15] efi: Enable secure boot lockdown automatically when enabled in firmware Matthew Garrett
2013-01-28 16:42   ` [PATCH 06/15] x86: Lock down IO port access in secure boot environments Matthew Garrett
2013-01-28 16:42   ` [PATCH 14/15] MODSIGN: Import certificates from UEFI Secure Boot Matthew Garrett
2013-01-28 16:42   ` [PATCH 15/15] MODSIGN: Always enforce module signing in a Secure Boot environment Matthew Garrett
2013-02-17 19:19   ` [PATCH 00/15] Secure boot policy support Yves-Alexis Perez

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=1359391359-25783-6-git-send-email-matthew.garrett@nebula.com \
    --to=matthew.garrett@nebula.com \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox