Skip to content

Commit 157dbc4

Browse files
Sebastian Ottoupton
authored andcommitted
KVM: arm64: Fix uninitialized memcache pointer in user_mem_abort()
Commit fce886a ("KVM: arm64: Plumb the pKVM MMU in KVM") made the initialization of the local memcache variable in user_mem_abort() conditional, leaving a codepath where it is used uninitialized via kvm_pgtable_stage2_map(). This can fail on any path that requires a stage-2 allocation without transition via a permission fault or dirty logging. Fix this by making sure that memcache is always valid. Fixes: fce886a ("KVM: arm64: Plumb the pKVM MMU in KVM") Signed-off-by: Sebastian Ott <sebott@redhat.com> Reviewed-by: Marc Zyngier <maz@kernel.org> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/kvmarm/3f5db4c7-ccce-fb95-595c-692fa7aad227@redhat.com/ Link: https://lore.kernel.org/r/20250505173148.33900-1-sebott@redhat.com Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent b443265 commit 157dbc4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

arch/arm64/kvm/mmu.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,11 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
15011501
return -EFAULT;
15021502
}
15031503

1504+
if (!is_protected_kvm_enabled())
1505+
memcache = &vcpu->arch.mmu_page_cache;
1506+
else
1507+
memcache = &vcpu->arch.pkvm_memcache;
1508+
15041509
/*
15051510
* Permission faults just need to update the existing leaf entry,
15061511
* and so normally don't require allocations from the memcache. The
@@ -1510,13 +1515,11 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
15101515
if (!fault_is_perm || (logging_active && write_fault)) {
15111516
int min_pages = kvm_mmu_cache_min_pages(vcpu->arch.hw_mmu);
15121517

1513-
if (!is_protected_kvm_enabled()) {
1514-
memcache = &vcpu->arch.mmu_page_cache;
1518+
if (!is_protected_kvm_enabled())
15151519
ret = kvm_mmu_topup_memory_cache(memcache, min_pages);
1516-
} else {
1517-
memcache = &vcpu->arch.pkvm_memcache;
1520+
else
15181521
ret = topup_hyp_memcache(memcache, min_pages);
1519-
}
1522+
15201523
if (ret)
15211524
return ret;
15221525
}

0 commit comments

Comments
 (0)