diff options
author | David Woodhouse <dwmw@amazon.co.uk> | 2017-04-12 08:25:51 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-05-25 09:44:47 -0400 |
commit | 6bec009a2f690c69239ab8c002aa1f5eca8c480e (patch) | |
tree | 95f33ede9670444a66c85bf7b40b8531dd398534 | |
parent | fa3bbb1c7f06e4e09f3c72ef42622ba260c77dc4 (diff) |
PCI: Fix another sanity check bug in /proc/pci mmap
commit 17caf56731311c9596e7d38a70c88fcb6afa6a1b upstream.
Don't match MMIO maps with I/O BARs and vice versa.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/pci/proc.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c index 2408abe4ee8c..78802ee42878 100644 --- a/drivers/pci/proc.c +++ b/drivers/pci/proc.c | |||
@@ -231,14 +231,20 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma) | |||
231 | { | 231 | { |
232 | struct pci_dev *dev = PDE_DATA(file_inode(file)); | 232 | struct pci_dev *dev = PDE_DATA(file_inode(file)); |
233 | struct pci_filp_private *fpriv = file->private_data; | 233 | struct pci_filp_private *fpriv = file->private_data; |
234 | int i, ret, write_combine; | 234 | int i, ret, write_combine, res_bit; |
235 | 235 | ||
236 | if (!capable(CAP_SYS_RAWIO)) | 236 | if (!capable(CAP_SYS_RAWIO)) |
237 | return -EPERM; | 237 | return -EPERM; |
238 | 238 | ||
239 | if (fpriv->mmap_state == pci_mmap_io) | ||
240 | res_bit = IORESOURCE_IO; | ||
241 | else | ||
242 | res_bit = IORESOURCE_MEM; | ||
243 | |||
239 | /* Make sure the caller is mapping a real resource for this device */ | 244 | /* Make sure the caller is mapping a real resource for this device */ |
240 | for (i = 0; i < PCI_ROM_RESOURCE; i++) { | 245 | for (i = 0; i < PCI_ROM_RESOURCE; i++) { |
241 | if (pci_mmap_fits(dev, i, vma, PCI_MMAP_PROCFS)) | 246 | if (dev->resource[i].flags & res_bit && |
247 | pci_mmap_fits(dev, i, vma, PCI_MMAP_PROCFS)) | ||
242 | break; | 248 | break; |
243 | } | 249 | } |
244 | 250 | ||