Skip to contentSkip to conversation

KVM: arm64: Fix __pkvm_init_vcpu cptr_el2 error path

PATCH Applied Vincent Donnefort 2 participants 2 messages Sep 19, 2024 – Oct 1, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 KVM: arm64: Fix __pkvm_init_vcpu cptr_el2 error path

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")

---

Changes since v1:

- Keep CPTR set outside of the vm_table_lock.
- Collect Reviewed-by

arch/arm64/kvm/hyp/nvhe/pkvm.c +4 -2
index 187a5f4d56c0..077d4098548d 100644
@@ -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

base-commit: 98f7e32f20d28ec452afb208f9cffc08448a2652

Signature · 1 line
2.46.0.662.g92d0881bb0-goog
maintainer Applied
#1 lore raw
Quoted 5 lines · Vincent Donnefort

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.

Applied to fixes, thanks!

[1/1] KVM: arm64: Fix __pkvm_init_vcpu cptr_el2 error path

      commit: 78fee4198bb4d29cf82c457086d07e009955a682

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.