Skip to content

Commit 9eff02e

Browse files
committed
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 <davem@davemloft.net> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent ede6f5a commit 9eff02e

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎drivers/pci/pci-sysfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ void pci_remove_legacy_files(struct pci_bus *b)
569569

570570
#ifdef HAVE_PCI_MMAP
571571

572-
static int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma)
572+
int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma)
573573
{
574574
unsigned long nr, start, size;
575575

‎drivers/pci/pci.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ extern int pci_uevent(struct device *dev, struct kobj_uevent_env *env);
1010
extern int pci_create_sysfs_dev_files(struct pci_dev *pdev);
1111
extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
1212
extern void pci_cleanup_rom(struct pci_dev *dev);
13+
#ifdef HAVE_PCI_MMAP
14+
extern int pci_mmap_fits(struct pci_dev *pdev, int resno,
15+
struct vm_area_struct *vma);
16+
#endif
1317

1418
/**
1519
* Firmware PM callbacks

‎drivers/pci/proc.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,20 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma)
252252
const struct proc_dir_entry *dp = PDE(inode);
253253
struct pci_dev *dev = dp->data;
254254
struct pci_filp_private *fpriv = file->private_data;
255-
int ret;
255+
int i, ret;
256256

257257
if (!capable(CAP_SYS_RAWIO))
258258
return -EPERM;
259259

260+
/* Make sure the caller is mapping a real resource for this device */
261+
for (i = 0; i < PCI_ROM_RESOURCE; i++) {
262+
if (pci_mmap_fits(dev, i, vma))
263+
break;
264+
}
265+
266+
if (i >= PCI_ROM_RESOURCE)
267+
return -ENODEV;
268+
260269
ret = pci_mmap_page_range(dev, vma,
261270
fpriv->mmap_state,
262271
fpriv->write_combine);

0 commit comments

Comments
 (0)