linux-stable/drivers/vfio
Yan Zhao 4752354af7 vfio/type1: check pfn valid before converting to struct page
Check physical PFN is valid before converting the PFN to a struct page
pointer to be returned to caller of vfio_pin_pages().

vfio_pin_pages() pins user pages with contiguous IOVA.
If the IOVA of a user page to be pinned belongs to vma of vm_flags
VM_PFNMAP, pin_user_pages_remote() will return -EFAULT without returning
struct page address for this PFN. This is because usually this kind of PFN
(e.g. MMIO PFN) has no valid struct page address associated.
Upon this error, vaddr_get_pfns() will obtain the physical PFN directly.

While previously vfio_pin_pages() returns to caller PFN arrays directly,
after commit
34a255e676 ("vfio: Replace phys_pfn with pages for vfio_pin_pages()"),
PFNs will be converted to "struct page *" unconditionally and therefore
the returned "struct page *" array may contain invalid struct page
addresses.

Given current in-tree users of vfio_pin_pages() only expect "struct page *
returned, check PFN validity and return -EINVAL to let the caller be
aware of IOVAs to be pinned containing PFN not able to be returned in
"struct page *" array. So that, the caller will not consume the returned
pointer (e.g. test PageReserved()) and avoid error like "supervisor read
access in kernel mode".

Fixes: 34a255e676 ("vfio: Replace phys_pfn with pages for vfio_pin_pages()")
Cc: Sean Christopherson <seanjc@google.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
Reviewed-by: Sean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/r/20230519065843.10653-1-yan.y.zhao@intel.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2023-05-23 14:16:29 -06:00
..
fsl-mc vfio/fsl-mc: Use GFP_KERNEL_ACCOUNT for userspace persistent allocations 2023-01-23 11:26:30 -07:00
mdev vfio/mdev: Use sysfs_emit() to instead of sprintf() 2023-01-30 12:16:13 -07:00
pci vfio/pci: Add DVSEC PCI Extended Config Capability to user visible list. 2023-04-14 14:03:07 -06:00
platform vfio: platform: ignore missing reset if disabled at module init 2023-02-01 12:25:41 -07:00
Kconfig vfio: Support VFIO_NOIOMMU with iommufd 2023-02-03 15:45:23 -04:00
Makefile VFIO updates for v6.2-rc1 2022-12-15 13:12:15 -08:00
container.c VFIO updates for v6.3-rc1 2023-02-25 11:52:57 -08:00
group.c driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
iommufd.c vfio: Check the presence for iommufd callbacks in __vfio_register_dev() 2023-03-31 13:43:32 -03:00
iova_bitmap.c vfio/iova_bitmap: refactor iova_bitmap_set() to better handle page boundaries 2022-12-02 10:09:25 -07:00
vfio.h VFIO updates for v6.3-rc1 2023-02-25 11:52:57 -08:00
vfio_iommu_spapr_tce.c powerpc/iommu: Add iommu_ops to report capabilities and allow blocking domains 2023-03-15 00:51:46 +11:00
vfio_iommu_type1.c vfio/type1: check pfn valid before converting to struct page 2023-05-23 14:16:29 -06:00
vfio_main.c Driver core changes for 6.4-rc1 2023-04-27 11:53:57 -07:00
virqfd.c vfio: Use GFP_KERNEL_ACCOUNT for userspace persistent allocations 2023-01-23 11:26:29 -07:00