Skip to content
Permalink
Browse files
vfio/type1: Use follow_pte()
follow_pfn() doesn't make sure that we're using the correct page
protections, get the pte with follow_pte() so that we can test
protections and get the pfn from the pte.

Fixes: 5cbf326 ("vfio/type1: Fix VA->PA translation for PFNMAP VMAs in vaddr_get_pfn()")
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
  • Loading branch information
awilliam authored and intel-lab-lkp committed Feb 12, 2021
1 parent 76adb20 commit d1aea3bcf226e5225e706acb7df2f4c68ea8858a
Showing 1 changed file with 12 additions and 2 deletions.
@@ -463,9 +463,11 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm,
unsigned long vaddr, unsigned long *pfn,
bool write_fault)
{
pte_t *ptep;
spinlock_t *ptl;
int ret;

ret = follow_pfn(vma, vaddr, pfn);
ret = follow_pte(vma->vm_mm, vaddr, NULL, &ptep, NULL, &ptl);
if (ret) {
bool unlocked = false;

@@ -479,9 +481,17 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm,
if (ret)
return ret;

ret = follow_pfn(vma, vaddr, pfn);
ret = follow_pte(vma->vm_mm, vaddr, NULL, &ptep, NULL, &ptl);
if (ret)
return ret;
}

if (write_fault && !pte_write(*ptep))
ret = -EFAULT;
else
*pfn = pte_pfn(*ptep);

pte_unmap_unlock(ptep, ptl);
return ret;
}

0 comments on commit d1aea3b

Please sign in to comment.