* [PATCH] pci/mmap: add pci device EBUSY check @ 2023-02-07 11:39 Seunggyun Lee 2023-02-08 8:09 ` Leon Romanovsky 2023-02-08 22:10 ` Bjorn Helgaas 0 siblings, 2 replies; 4+ messages in thread From: Seunggyun Lee @ 2023-02-07 11:39 UTC (permalink / raw) To: bhelgaas; +Cc: linux-pci, linux-kernel When using a pci device through the vfio-pci driver, other software was also able to access the pci device memory through sysfs. To prevent this, when mmap is performed through sysfs, a process of checking whether the device is in use is added. Signed-off-by: Seunggyun Lee <sglee97@dankook.ac.kr> --- drivers/pci/mmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/mmap.c b/drivers/pci/mmap.c index 4504039056d1..4c9df2e23e03 100644 --- a/drivers/pci/mmap.c +++ b/drivers/pci/mmap.c @@ -25,6 +25,8 @@ int pci_mmap_resource_range(struct pci_dev *pdev, int bar, { unsigned long size; int ret; + if (pdev->driver) + return -1; size = ((pci_resource_len(pdev, bar) - 1) >> PAGE_SHIFT) + 1; if (vma->vm_pgoff + vma_pages(vma) > size) -- 2.25.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] pci/mmap: add pci device EBUSY check 2023-02-07 11:39 [PATCH] pci/mmap: add pci device EBUSY check Seunggyun Lee @ 2023-02-08 8:09 ` Leon Romanovsky 2023-02-08 22:10 ` Bjorn Helgaas 1 sibling, 0 replies; 4+ messages in thread From: Leon Romanovsky @ 2023-02-08 8:09 UTC (permalink / raw) To: Seunggyun Lee; +Cc: bhelgaas, linux-pci, linux-kernel On Tue, Feb 07, 2023 at 08:39:49PM +0900, Seunggyun Lee wrote: > When using a pci device through the vfio-pci driver, other software was > also able to access the pci device memory through sysfs. And why is it wrong? > > To prevent this, when mmap is performed through sysfs, a process of > checking whether the device is in use is added. > > Signed-off-by: Seunggyun Lee <sglee97@dankook.ac.kr> > --- > drivers/pci/mmap.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/pci/mmap.c b/drivers/pci/mmap.c > index 4504039056d1..4c9df2e23e03 100644 > --- a/drivers/pci/mmap.c > +++ b/drivers/pci/mmap.c > @@ -25,6 +25,8 @@ int pci_mmap_resource_range(struct pci_dev *pdev, int bar, > { > unsigned long size; > int ret; > + if (pdev->driver) > + return -1; I doubt that it is correct/needed as every call to pci_mmap_resource_range() is guarded by iomem_is_exclusive() check. Also I'm not sure that pdev->driver can be accessed without any lock in this flow. Thanks > > size = ((pci_resource_len(pdev, bar) - 1) >> PAGE_SHIFT) + 1; > if (vma->vm_pgoff + vma_pages(vma) > size) > -- > 2.25.1 > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] pci/mmap: add pci device EBUSY check 2023-02-07 11:39 [PATCH] pci/mmap: add pci device EBUSY check Seunggyun Lee 2023-02-08 8:09 ` Leon Romanovsky @ 2023-02-08 22:10 ` Bjorn Helgaas 2023-02-08 22:43 ` Alex Williamson 1 sibling, 1 reply; 4+ messages in thread From: Bjorn Helgaas @ 2023-02-08 22:10 UTC (permalink / raw) To: Seunggyun Lee Cc: bhelgaas, linux-pci, linux-kernel, Alex Williamson, Cornelia Huck, kvm, Leon Romanovsky [+cc VFIO folks, Leon] On Tue, Feb 07, 2023 at 08:39:49PM +0900, Seunggyun Lee wrote: > When using a pci device through the vfio-pci driver, other software was > also able to access the pci device memory through sysfs. > > To prevent this, when mmap is performed through sysfs, a process of > checking whether the device is in use is added. > > Signed-off-by: Seunggyun Lee <sglee97@dankook.ac.kr> > --- > drivers/pci/mmap.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/pci/mmap.c b/drivers/pci/mmap.c > index 4504039056d1..4c9df2e23e03 100644 > --- a/drivers/pci/mmap.c > +++ b/drivers/pci/mmap.c > @@ -25,6 +25,8 @@ int pci_mmap_resource_range(struct pci_dev *pdev, int bar, > { > unsigned long size; > int ret; > + if (pdev->driver) > + return -1; > > size = ((pci_resource_len(pdev, bar) - 1) >> PAGE_SHIFT) + 1; > if (vma->vm_pgoff + vma_pages(vma) > size) > -- > 2.25.1 > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] pci/mmap: add pci device EBUSY check 2023-02-08 22:10 ` Bjorn Helgaas @ 2023-02-08 22:43 ` Alex Williamson 0 siblings, 0 replies; 4+ messages in thread From: Alex Williamson @ 2023-02-08 22:43 UTC (permalink / raw) To: Bjorn Helgaas Cc: Seunggyun Lee, bhelgaas, linux-pci, linux-kernel, Cornelia Huck, kvm, Leon Romanovsky On Wed, 8 Feb 2023 16:10:10 -0600 Bjorn Helgaas <helgaas@kernel.org> wrote: > [+cc VFIO folks, Leon] > > On Tue, Feb 07, 2023 at 08:39:49PM +0900, Seunggyun Lee wrote: > > When using a pci device through the vfio-pci driver, other software was > > also able to access the pci device memory through sysfs. > > > > To prevent this, when mmap is performed through sysfs, a process of > > checking whether the device is in use is added. > > > > Signed-off-by: Seunggyun Lee <sglee97@dankook.ac.kr> > > --- > > drivers/pci/mmap.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/drivers/pci/mmap.c b/drivers/pci/mmap.c > > index 4504039056d1..4c9df2e23e03 100644 > > --- a/drivers/pci/mmap.c > > +++ b/drivers/pci/mmap.c > > @@ -25,6 +25,8 @@ int pci_mmap_resource_range(struct pci_dev *pdev, int bar, > > { > > unsigned long size; > > int ret; > > + if (pdev->driver) Maintain the blank line after variable declarations. > > + return -1; Surely there's a better errno value for this. > > > > size = ((pci_resource_len(pdev, bar) - 1) >> PAGE_SHIFT) + 1; > > if (vma->vm_pgoff + vma_pages(vma) > size) Regardless of the above, what's the point of this? There are already checks for LOCKDOWN_PCI_ACCESS in the sysfs and proc interfaces to this function, so we can already activate restrictions to protect this scenario via kernel config, kernel cmdline options, or runtime with securityfs. This is redundant and a blanket restriction as implemented here seems liable to break some obscure use case. Thanks, Alex ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-02-08 22:44 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-02-07 11:39 [PATCH] pci/mmap: add pci device EBUSY check Seunggyun Lee 2023-02-08 8:09 ` Leon Romanovsky 2023-02-08 22:10 ` Bjorn Helgaas 2023-02-08 22:43 ` Alex Williamson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox