[PATCH 25/35] mm, x86, dmem: fix estimation of reserved page for vaddr_get_pfn()

From: yulei . kernel
Date: Thu Oct 08 2020 - 03:55:52 EST


From: Yulei Zhang <yuleixzhang@xxxxxxxxxxx>

Fix estimation of reserved page for vaddr_get_pfn() and
check 'ret' before checking writable permission

Signed-off-by: Chen Zhuo <sagazchen@xxxxxxxxxxx>
Signed-off-by: Yulei Zhang <yuleixzhang@xxxxxxxxxxx>
---
drivers/vfio/vfio_iommu_type1.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 5fbf0c1f7433..257a8cab0a77 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -471,6 +471,10 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,
if (ret == -EAGAIN)
goto retry;

+ if (!ret && (prot & IOMMU_WRITE) &&
+ !(vma->vm_flags & VM_WRITE))
+ ret = -EFAULT;
+
if (!ret && !is_invalid_reserved_pfn(*pfn))
ret = -EFAULT;
}
--
2.28.0