Signed-off-by: Suren Baghdasaryan <surenb@google.com>
if (!vma)
goto inval;
+ /* Only anonymous vmas are supported for now */
if (!vma_is_anonymous(vma))
goto inval;
if (userfaultfd_armed(vma))
goto inval;
- if (!vma_read_trylock(vma)) {
- count_vm_vma_lock_event(VMA_LOCK_ABORT);
+ if (!vma_read_trylock(vma))
+ goto inval;
+
+ /* Check since vm_start/vm_end might change before we lock the VMA */
+ if (unlikely(address < vma->vm_start || address >= vma->vm_end)) {
+ vma_read_unlock(vma);
goto inval;
}
return vma;
inval:
rcu_read_unlock();
+ count_vm_vma_lock_event(VMA_LOCK_ABORT);
return NULL;
}
#endif /* CONFIG_PER_VMA_LOCK */