On 12/15/21 15:05, Sean Christopherson wrote:
@@ -174,7 +174,7 @@ static int FNAME(cmpxchg_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
pfn = ((vaddr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
Isn't this code flat out wrong? vm_pgoff is usually the offset relative to the
file and has nothing to do with the pfn. I see that remap_pfn_range_notrack()
stuffs "vma->vm_pgoff = pfn", but that's a weird quirk of that particular usage
of VM_PFNMAP that I'm guessing happened to align with the original usage of this
mess. But unless there's magic I'm missing, vm_pgoff is not guaranteed to have
any relation to the pfn for any ol' VM_PFNMAP vma.
In other words, I suspect pfn and paddr are complete garbage, and adding the
access_ok() check masks that.
The answer to your question might be in the commit message of the original
commit that added this code:
bd53cb35a3e9 ("X86/KVM: Handle PFNs outside of kernel reach when touching GPTEs")
--
Thanks,
Tadeusz