KVM: VMX: Check cpl before emulating debug register access
PATCH 1/1 KVM: VMX: Check cpl before emulating debug register access
Debug registers may only be accessed from cpl 0. Unfortunately, vmx will code to emulate the instruction even though it was issued from guest userspace, possibly leading to an unexpected trap later.
Signed-off-by Avi Kivity <[email protected]>
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/vmx.c | 2 ++ arch/x86/kvm/x86.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 0 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -621,6 +621,7 @@ void kvm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr);void kvm_queue_exception_e (struct kvm_vcpu *vcpu,unsigned nr,u32 error_code);void kvm_inject_page_fault (struct kvm_vcpu *vcpu,unsigned long cr2,u32 error_code); +bool kvm_require_cpl (struct kvm_vcpu *vcpu,int required_cpl);int kvm_pic_set_irq (void *opaque,int irq,int level);
arch/x86/kvm/vmx.c +2 -0
@@ -2931,6 +2931,8 @@ static int handle_dr(struct kvm_vcpu *vcpu)unsigned long val;int dr, reg; +if (!kvm_require_cpl (vcpu,0 )) +return 1 ; dr =vmcs_readl (GUEST_DR7 );if (dr &DR7_GD ) {/*
arch/x86/kvm/x86.c +13 -0
@@ -223,6 +223,19 @@ void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code)EXPORT_SYMBOL_GPL (kvm_queue_exception_e);/* +* Checks if cpl <= required_cpl; if true, return true. Otherwise queue +* a #GP and return false. +*/ +bool kvm_require_cpl (struct kvm_vcpu *vcpu,int required_cpl) +{ +if (kvm_x86_ops->get_cpl (vcpu) <= required_cpl) +return true; +kvm_queue_exception_e (vcpu,GP_VECTOR ,0 ); +return false; +} +EXPORT_SYMBOL_GPL (kvm_require_cpl); + +/* * Load the pae pdptrs. Return true is they are all valid. */ int load_pdptrs (struct kvm_vcpu *vcpu,unsigned long cr3)
Signature · 1 line
1.6.4.1
Marcelo Tosatti
AppliedQuoted 6 lines · Avi Kivity
Debug registers may only be accessed from cpl 0. Unfortunately, vmx will code to emulate the instruction even though it was issued from guest userspace, possibly leading to an unexpected trap later.
Signed-off-by Avi Kivity <[email protected]>
Applied, thanks.