Re: [PATCH RESEND] KVM: x86/mmu: fix UAF in paging_update_accessed_dirty_bits

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1/24/22 10:29, Sean Christopherson wrote:
On Mon, Jan 24, 2022, Paolo Bonzini wrote:
On 1/24/22 18:26, Tadeusz Struk wrote:
Syzbot reported an use-after-free bug in update_accessed_dirty_bits().
Fix this by checking if the memremap'ed pointer is still valid.
access_ok only checks that the pointer is in the userspace range.  Is this
correct?  And if so, what are the exact circumstances in which access_ok
returns a non-NULL but also non-userspace address?
I "objected" to this patch in its initial posting[*].  AFAICT adding access_ok()
is just masking a more egregious bug where interpretation of vm_pgoff as a PFN
base is flat out wrong except for select backing stores that use VM_PFNMAP.  In
other words, the vm_pgoff hack works for the /dev/mem use case, but it is wrong
in general.


The issue here is not related to /dev/mem, but binder allocated memory, which is
yet another special mapping use case. In this case the condition

if (!vma || !(vma->vm_flags & VM_PFNMAP))

doesn't cover this special mappings. Adding the access_ok() was my something
that fixed the use-after-free issue for me, and since I didn't have anything
better I thought I will send an RFC to start some discussion.
After some more debugging I came up with the bellow.
Will that be more acceptable?


diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h
index 5b5bdac97c7b..0f03e5401a98 100644
--- a/arch/x86/kvm/mmu/paging_tmpl.h
+++ b/arch/x86/kvm/mmu/paging_tmpl.h
@@ -167,7 +167,7 @@ static int FNAME(cmpxchg_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,

                mmap_read_lock(current->mm);
                vma = find_vma_intersection(current->mm, vaddr, vaddr + PAGE_SIZE);
-               if (!vma || !(vma->vm_flags & VM_PFNMAP)) {
+               if (!vma || !(vma->vm_flags & VM_MIXEDMAP)) {
                        mmap_read_unlock(current->mm);
                        return -EFAULT;
                }

--
Thanks,
Tadeusz



[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux