]> www.infradead.org Git - users/hch/dma-mapping.git/commitdiff
KVM: arm64: Fix __pkvm_init_vcpu cptr_el2 error path
authorVincent Donnefort <vdonnefort@google.com>
Thu, 19 Sep 2024 11:05:00 +0000 (12:05 +0100)
committerMarc Zyngier <maz@kernel.org>
Tue, 1 Oct 2024 14:25:23 +0000 (15:25 +0100)
On an error, hyp_vcpu will be accessed while this memory has already
been relinquished to the host and unmapped from the hypervisor. Protect
the CPTR assignment with an early return.

Fixes: b5b9955617bc ("KVM: arm64: Eagerly restore host fpsimd/sve state in pKVM")
Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Link: https://lore.kernel.org/r/20240919110500.2345927-1-vdonnefort@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/hyp/nvhe/pkvm.c

index 187a5f4d56c0c61c5f46afa39383c5c6a3557e07..077d4098548d2c87abdd3931285d87798d63adb3 100644 (file)
@@ -574,12 +574,14 @@ int __pkvm_init_vcpu(pkvm_handle_t handle, struct kvm_vcpu *host_vcpu,
 unlock:
        hyp_spin_unlock(&vm_table_lock);
 
-       if (ret)
+       if (ret) {
                unmap_donated_memory(hyp_vcpu, sizeof(*hyp_vcpu));
+               return ret;
+       }
 
        hyp_vcpu->vcpu.arch.cptr_el2 = kvm_get_reset_cptr_el2(&hyp_vcpu->vcpu);
 
-       return ret;
+       return 0;
 }
 
 static void