From: Marc Zyngier <m...@kernel.org>

Prevent the host from issuing arbitrary PC adjustments for protected
vCPUs.

Signed-off-by: Marc Zyngier <m...@kernel.org>
---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c 
b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index 40cbf45800b7..86dff0dc05f3 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -275,9 +275,22 @@ static void handle___pkvm_host_map_guest(struct 
kvm_cpu_context *host_ctxt)
 
 static void handle___kvm_adjust_pc(struct kvm_cpu_context *host_ctxt)
 {
-       DECLARE_REG(struct kvm_vcpu *, vcpu, host_ctxt, 1);
+       struct kvm_shadow_vcpu_state *shadow_state;
+       struct kvm_vcpu *vcpu;
+
+       vcpu = get_current_vcpu(host_ctxt, 1, &shadow_state);
+       if (!vcpu)
+               return;
+
+       if (shadow_state) {
+               /* This only applies to non-protected VMs */
+               if (shadow_state_is_protected(shadow_state))
+                       return;
+
+               vcpu = &shadow_state->shadow_vcpu;
+       }
 
-       __kvm_adjust_pc(kern_hyp_va(vcpu));
+       __kvm_adjust_pc(vcpu);
 }
 
 static void handle___kvm_flush_vm_context(struct kvm_cpu_context *host_ctxt)
-- 
2.36.1.124.g0e6072fb45-goog

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

Reply via email to