From: Yulei Zhang <yuleixzh...@tencent.com>

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

Signed-off-by: Chen Zhuo <sagazc...@tencent.com>
Signed-off-by: Yulei Zhang <yuleixzh...@tencent.com>
---
 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

Reply via email to