public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfio/type1: check pfn valid before converting to struct page
@ 2023-05-16  9:30 Yan Zhao
  2023-05-16 11:50 ` Jason Gunthorpe
  2023-05-17 15:19 ` Sean Christopherson
  0 siblings, 2 replies; 6+ messages in thread
From: Yan Zhao @ 2023-05-16  9:30 UTC (permalink / raw)
  To: kvm, linux-kernel; +Cc: alex.williamson, kevin.tian, jgg, Yan Zhao

vfio_pin_page_external() can return a phys_pfn for vma with VM_PFNMAP,
e.g. for MMIO PFNs.

It's necessary to check if it's a valid pfn before calling pfn_to_page().

Fixes: 34a255e67615 ("vfio: Replace phys_pfn with pages for vfio_pin_pages()")
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
---
 drivers/vfio/vfio_iommu_type1.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 493c31de0edb..0620dbe5cca0 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -860,6 +860,11 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data,
 		if (ret)
 			goto pin_unwind;
 
+		if (!pfn_valid(phys_pfn)) {
+			ret = -EINVAL;
+			goto pin_unwind;
+		}
+
 		ret = vfio_add_to_pfn_list(dma, iova, phys_pfn);
 		if (ret) {
 			if (put_pfn(phys_pfn, dma->prot) && do_accounting)

base-commit: b3c98052d46948a8d65d2778c7f306ff38366aac
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-05-19  1:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-16  9:30 [PATCH] vfio/type1: check pfn valid before converting to struct page Yan Zhao
2023-05-16 11:50 ` Jason Gunthorpe
2023-05-17 15:19 ` Sean Christopherson
2023-05-18  0:52   ` Yan Zhao
2023-05-18 18:07     ` Sean Christopherson
2023-05-19  1:25       ` Yan Zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox