]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.30/pci-fix-pci_mmap_fits-for-have_pci_resource_to_user-platforms.patch
Linux 4.14.95
[thirdparty/kernel/stable-queue.git] / releases / 4.9.30 / pci-fix-pci_mmap_fits-for-have_pci_resource_to_user-platforms.patch
1 From 6bccc7f426abd640f08d8c75fb22f99483f201b4 Mon Sep 17 00:00:00 2001
2 From: David Woodhouse <dwmw@amazon.co.uk>
3 Date: Wed, 12 Apr 2017 13:25:50 +0100
4 Subject: PCI: Fix pci_mmap_fits() for HAVE_PCI_RESOURCE_TO_USER platforms
5
6 From: David Woodhouse <dwmw@amazon.co.uk>
7
8 commit 6bccc7f426abd640f08d8c75fb22f99483f201b4 upstream.
9
10 In the PCI_MMAP_PROCFS case when the address being passed by the user is a
11 'user visible' resource address based on the bus window, and not the actual
12 contents of the resource, that's what we need to be checking it against.
13
14 Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
15 Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
16 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
17
18 ---
19 drivers/pci/pci-sysfs.c | 10 +++++++---
20 1 file changed, 7 insertions(+), 3 deletions(-)
21
22 --- a/drivers/pci/pci-sysfs.c
23 +++ b/drivers/pci/pci-sysfs.c
24 @@ -974,15 +974,19 @@ void pci_remove_legacy_files(struct pci_
25 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
26 enum pci_mmap_api mmap_api)
27 {
28 - unsigned long nr, start, size, pci_start;
29 + unsigned long nr, start, size;
30 + resource_size_t pci_start = 0, pci_end;
31
32 if (pci_resource_len(pdev, resno) == 0)
33 return 0;
34 nr = vma_pages(vma);
35 start = vma->vm_pgoff;
36 size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
37 - pci_start = (mmap_api == PCI_MMAP_PROCFS) ?
38 - pci_resource_start(pdev, resno) >> PAGE_SHIFT : 0;
39 + if (mmap_api == PCI_MMAP_PROCFS) {
40 + pci_resource_to_user(pdev, resno, &pdev->resource[resno],
41 + &pci_start, &pci_end);
42 + pci_start >>= PAGE_SHIFT;
43 + }
44 if (start >= pci_start && start < pci_start + size &&
45 start + nr <= pci_start + size)
46 return 1;