rpms/kernel/F-8 linux-2.6-pci-check-mapped-ranges-on-sysfs-resource-files.patch, NONE, 1.1 kernel.spec, 1.550, 1.551
Chuck Ebbert
cebbert at fedoraproject.org
Fri Oct 10 22:17:00 UTC 2008
Author: cebbert
Update of /cvs/pkgs/rpms/kernel/F-8
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv9370
Modified Files:
kernel.spec
Added Files:
linux-2.6-pci-check-mapped-ranges-on-sysfs-resource-files.patch
Log Message:
pci: check range on sysfs mmapped resources
linux-2.6-pci-check-mapped-ranges-on-sysfs-resource-files.patch:
--- NEW FILE linux-2.6-pci-check-mapped-ranges-on-sysfs-resource-files.patch ---
From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Fri, 3 Oct 2008 01:52:51 +0000 (-0700)
Subject: Check mapped ranges on sysfs resource files
X-Git-Tag: v2.6.27-rc9~28
X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=b5ff7df3df9efab511244d5a299fce706c71af48
Check mapped ranges on sysfs resource files
This is loosely based on a patch by Jesse Barnes to check the user-space
PCI mappings though the sysfs interfaces. Quoting Jesse's original
explanation:
It's fairly common for applications to map PCI resources through sysfs.
However, with the current implementation, it's possible for an application
to map far more than the range corresponding to the resourceN file it
opened. This patch plugs that hole by checking the range at mmap time,
similar to what is done on platforms like sparc64 in their lower level
PCI remapping routines.
It was initially put together to help debug the e1000e NVRAM corruption
problem, since we initially thought an X driver might be walking past the
end of one of its mappings and clobbering the NVRAM. It now looks like
that's not the case, but doing the check is still important for obvious
reasons.
and this version of the patch differs in that it uses a helper function
to clarify the code, and does all the checks in pages (instead of bytes)
in order to avoid overflows when doing "<< PAGE_SHIFT" etc.
Acked-by: Jesse Barnes <jbarnes at virtuousgeek.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 9c71858..77baff0 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -16,6 +16,7 @@
#include <linux/kernel.h>
+#include <linux/sched.h>
#include <linux/pci.h>
#include <linux/stat.h>
#include <linux/topology.h>
@@ -484,6 +485,21 @@ pci_mmap_legacy_mem(struct kobject *kobj, struct bin_attribute *attr,
#endif /* HAVE_PCI_LEGACY */
#ifdef HAVE_PCI_MMAP
+
+static int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma)
+{
+ unsigned long nr, start, size;
+
+ nr = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
+ start = vma->vm_pgoff;
+ size = pci_resource_len(pdev, resno) >> PAGE_SHIFT;
+ if (start < size && size - start >= nr)
+ return 1;
+ WARN(1, "process \"%s\" tried to map 0x%08lx-0x%08lx on %s BAR %d (size 0x%08lx)\n",
+ current->comm, start, start+nr, pci_name(pdev), resno, size);
+ return 0;
+}
+
/**
* pci_mmap_resource - map a PCI resource into user memory space
* @kobj: kobject for mapping
@@ -510,6 +526,9 @@ pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
if (i >= PCI_ROM_RESOURCE)
return -ENODEV;
+ if (!pci_mmap_fits(pdev, i, vma))
+ return -EINVAL;
+
/* pci_mmap_page_range() expects the same kind of entry as coming
* from /proc/bus/pci/ which is a "user visible" value. If this is
* different from the resource itself, arch will do necessary fixup.
Index: kernel.spec
===================================================================
RCS file: /cvs/pkgs/rpms/kernel/F-8/kernel.spec,v
retrieving revision 1.550
retrieving revision 1.551
diff -u -r1.550 -r1.551
--- kernel.spec 10 Oct 2008 22:06:49 -0000 1.550
+++ kernel.spec 10 Oct 2008 22:16:30 -0000 1.551
@@ -595,6 +595,7 @@
Patch120: linux-2.6-pci-disable-aspm-per-acpi-fadt-setting.patch
Patch121: linux-2.6-pci-disable-aspm-on-pre-1.1-devices.patch
Patch122: linux-2.6-pci-add-an-option-to-allow-aspm-enabled-forcibly.patch
+Patch123: linux-2.6-pci-check-mapped-ranges-on-sysfs-resource-files.patch
#ALSA
@@ -1048,6 +1049,8 @@
ApplyPatch linux-2.6-pci-disable-aspm-per-acpi-fadt-setting.patch
ApplyPatch linux-2.6-pci-disable-aspm-on-pre-1.1-devices.patch
ApplyPatch linux-2.6-pci-add-an-option-to-allow-aspm-enabled-forcibly.patch
+# check range on pci mmap
+ApplyPatch linux-2.6-pci-check-mapped-ranges-on-sysfs-resource-files.patch
#
# PowerPC
@@ -1865,6 +1868,9 @@
%changelog
+* Fri Oct 10 2008 Chuck Ebbert <cebbert at redhat.com> 2.6.26.6-41
+- pci: check range on sysfs mmapped resources
+
* Fri Oct 10 2008 Chuck Ebbert <cebbert at redhat.com> 2.6.26.6-40
- Don't allow splice to files opened with O_APPEND.
More information about the fedora-extras-commits
mailing list