All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: disable pv eoi if guest gives a wrong address
@ 2021-11-05  2:13 Li RongQing
  2021-11-05  9:08 ` Vitaly Kuznetsov
  0 siblings, 1 reply; 4+ messages in thread
From: Li RongQing @ 2021-11-05  2:13 UTC (permalink / raw)
  To: kvm, pbonzini, seanjc, vkuznets, lirongqing

disable pv eoi if guest gives a wrong address, this can reduces
the attacked possibility for a malicious guest, and can avoid
unnecessary write/read pv eoi memory

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 arch/x86/kvm/lapic.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index b1de23e..0f37a8d 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -2853,6 +2853,7 @@ int kvm_lapic_enable_pv_eoi(struct kvm_vcpu *vcpu, u64 data, unsigned long len)
 	u64 addr = data & ~KVM_MSR_ENABLED;
 	struct gfn_to_hva_cache *ghc = &vcpu->arch.pv_eoi.data;
 	unsigned long new_len;
+	int ret;
 
 	if (!IS_ALIGNED(addr, 4))
 		return 1;
@@ -2866,7 +2867,13 @@ int kvm_lapic_enable_pv_eoi(struct kvm_vcpu *vcpu, u64 data, unsigned long len)
 	else
 		new_len = len;
 
-	return kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, addr, new_len);
+	ret = kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, addr, new_len);
+
+	if (ret && (vcpu->arch.pv_eoi.msr_val & KVM_MSR_ENABLED)) {
+		vcpu->arch.pv_eoi.msr_val &= ~KVM_MSR_ENABLED;
+		pr_warn_once("Disabled PV EOI during wrong address\n");
+	}
+	return ret;
 }
 
 int kvm_apic_accept_events(struct kvm_vcpu *vcpu)
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-05 10:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05  2:13 [PATCH] KVM: x86: disable pv eoi if guest gives a wrong address Li RongQing
2021-11-05  9:08 ` Vitaly Kuznetsov
2021-11-05  9:51   ` 答复: " Li,Rongqing
2021-11-05 10:17     ` Vitaly Kuznetsov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.