Skip to content

Commit 8c2e8ac

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Check for kvm_vma_mte_allowed in the critical section
On page fault, we find about the VMA that backs the page fault early on, and quickly release the mmap_read_lock. However, using the VMA pointer after the critical section is pretty dangerous, as a teardown may happen in the meantime and the VMA be long gone. Move the sampling of the MTE permission early, and NULL-ify the VMA pointer after that, just to be on the safe side. Signed-off-by: Marc Zyngier <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent e86fc1a commit 8c2e8ac

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/arm64/kvm/mmu.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
12181218
{
12191219
int ret = 0;
12201220
bool write_fault, writable, force_pte = false;
1221-
bool exec_fault;
1221+
bool exec_fault, mte_allowed;
12221222
bool device = false;
12231223
unsigned long mmu_seq;
12241224
struct kvm *kvm = vcpu->kvm;
@@ -1309,6 +1309,10 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
13091309
fault_ipa &= ~(vma_pagesize - 1);
13101310

13111311
gfn = fault_ipa >> PAGE_SHIFT;
1312+
mte_allowed = kvm_vma_mte_allowed(vma);
1313+
1314+
/* Don't use the VMA after the unlock -- it may have vanished */
1315+
vma = NULL;
13121316

13131317
/*
13141318
* Read mmu_invalidate_seq so that KVM can detect if the results of
@@ -1379,7 +1383,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
13791383

13801384
if (fault_status != ESR_ELx_FSC_PERM && !device && kvm_has_mte(kvm)) {
13811385
/* Check the VMM hasn't introduced a new disallowed VMA */
1382-
if (kvm_vma_mte_allowed(vma)) {
1386+
if (mte_allowed) {
13831387
sanitise_mte_tags(kvm, pfn, vma_pagesize);
13841388
} else {
13851389
ret = -EFAULT;

0 commit comments

Comments
 (0)