From 9eff02e2042f96fb2aedd02e032eca1c5333d767 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Fri, 24 Oct 2008 10:32:33 -0700 Subject: PCI: check mmap range of /proc/bus/pci files too /proc/bus/pci allows you to mmap resource ranges too, so we should probably be checking to make sure the mapping is somewhat valid. Uses the same code as the recent sysfs mmap range checking patch from Linus. Acked-by: David Miller Signed-off-by: Jesse Barnes --- drivers/pci/proc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'drivers/pci/proc.c') diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c index e1098c302c45..7fb086d39617 100644 --- a/drivers/pci/proc.c +++ b/drivers/pci/proc.c @@ -252,11 +252,20 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma) const struct proc_dir_entry *dp = PDE(inode); struct pci_dev *dev = dp->data; struct pci_filp_private *fpriv = file->private_data; - int ret; + int i, ret; if (!capable(CAP_SYS_RAWIO)) return -EPERM; + /* Make sure the caller is mapping a real resource for this device */ + for (i = 0; i < PCI_ROM_RESOURCE; i++) { + if (pci_mmap_fits(dev, i, vma)) + break; + } + + if (i >= PCI_ROM_RESOURCE) + return -ENODEV; + ret = pci_mmap_page_range(dev, vma, fpriv->mmap_state, fpriv->write_combine); -- cgit v1.2.3-58-ga151