Vulnerability: The KVM subsystem in the Linux kernel through 4.2.6, and Xen 4.3.x through 4.6.x, allows guest OS users to cause a denial of service (host OS panic or hang) by triggering many #DB (aka Debug) exceptions, related to svm.c.
Vulnerability ID: CVE-2015-8104
CWE: CWE-399
Severity score: 6.9
Project: https://github.com/torvalds/linux
Published: 2015-11-16
File: arch/x86/kvm/svm.c
Commit message: KVM: svm: unconditionally intercept #DB

This is needed to avoid the possibility that the guest triggers
an infinite stream of #DB exceptions (CVE-2015-8104).

VMX is not affected: because it does not save DR6 in the VMCS,
it already intercepts #DB unconditionally.

Reported-by: Jan Beulich <jbeulich@suse.com>
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Commit author: Paolo Bonzini

Vulnerable version (before fix):
 static void init_vmcb(struct vcpu_svm *svm) 	set_exception_intercept(svm, UD_VECTOR); 	set_exception_intercept(svm, MC_VECTOR); 	set_exception_intercept(svm, AC_VECTOR);  	set_intercept(svm, INTERCEPT_INTR); 	set_intercept(svm, INTERCEPT_NMI); static void svm_set_segment(struct kvm_vcpu *vcpu, 	mark_dirty(svm->vmcb, VMCB_SEG); }  static void update_db_bp_intercept(struct kvm_vcpu *vcpu) { 	struct vcpu_svm *svm = to_svm(vcpu);  	clr_exception_intercept(svm, DB_VECTOR); 	clr_exception_intercept(svm, BP_VECTOR);  	if (svm->nmi_singlestep) 		set_exception_intercept(svm, DB_VECTOR);  	if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) { 		if (vcpu->guest_debug & 		    (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP)) 			set_exception_intercept(svm, DB_VECTOR); 		if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) 			set_exception_intercept(svm, BP_VECTOR); 	} else static int db_interception(struct vcpu_svm *svm) 		if (!(svm->vcpu.guest_debug & KVM_GUESTDBG_SINGLESTEP)) 			svm->vmcb->save.rflags &= 				~(X86_EFLAGS_TF | X86_EFLAGS_RF); 		update_db_bp_intercept(&svm->vcpu); 	}  	if (svm->vcpu.guest_debug & static void enable_nmi_window(struct kvm_vcpu *vcpu) 	 */ 	svm->nmi_singlestep = true; 	svm->vmcb->save.rflags |= (X86_EFLAGS_TF | X86_EFLAGS_RF); 	update_db_bp_intercept(vcpu); }  static int svm_set_tss_addr(struct kvm *kvm, unsigned int addr) static struct kvm_x86_ops svm_x86_ops = { 	.vcpu_load = svm_vcpu_load, 	.vcpu_put = svm_vcpu_put,  	.update_db_bp_intercept = update_db_bp_intercept, 	.get_msr = svm_get_msr, 	.set_msr = svm_set_msr, 	.get_segment_base = svm_get_segment_base,

Fixed version (after fix):
 static void init_vmcb(struct vcpu_svm *svm) 	set_exception_intercept(svm, UD_VECTOR); 	set_exception_intercept(svm, MC_VECTOR); 	set_exception_intercept(svm, AC_VECTOR); 	set_exception_intercept(svm, DB_VECTOR);  	set_intercept(svm, INTERCEPT_INTR); 	set_intercept(svm, INTERCEPT_NMI); static void svm_set_segment(struct kvm_vcpu *vcpu, 	mark_dirty(svm->vmcb, VMCB_SEG); }  static void update_bp_intercept(struct kvm_vcpu *vcpu) { 	struct vcpu_svm *svm = to_svm(vcpu);  	clr_exception_intercept(svm, BP_VECTOR);  	if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) { 		if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) 			set_exception_intercept(svm, BP_VECTOR); 	} else static int db_interception(struct vcpu_svm *svm) 		if (!(svm->vcpu.guest_debug & KVM_GUESTDBG_SINGLESTEP)) 			svm->vmcb->save.rflags &= 				~(X86_EFLAGS_TF | X86_EFLAGS_RF); 	}  	if (svm->vcpu.guest_debug & static void enable_nmi_window(struct kvm_vcpu *vcpu) 	 */ 	svm->nmi_singlestep = true; 	svm->vmcb->save.rflags |= (X86_EFLAGS_TF | X86_EFLAGS_RF); }  static int svm_set_tss_addr(struct kvm *kvm, unsigned int addr) static struct kvm_x86_ops svm_x86_ops = { 	.vcpu_load = svm_vcpu_load, 	.vcpu_put = svm_vcpu_put,  	.update_db_bp_intercept = update_bp_intercept, 	.get_msr = svm_get_msr, 	.set_msr = svm_set_msr, 	.get_segment_base = svm_get_segment_base,

Patch:
patch: @@ -1020,6 +1020,7 @@ static void init_vmcb(struct vcpu_svm *svm)
 	set_exception_intercept(svm, UD_VECTOR);
 	set_exception_intercept(svm, MC_VECTOR);
 	set_exception_intercept(svm, AC_VECTOR);
+	set_exception_intercept(svm, DB_VECTOR);
 
 	set_intercept(svm, INTERCEPT_INTR);
 	set_intercept(svm, INTERCEPT_NMI);
@@ -1554,20 +1555,13 @@ static void svm_set_segment(struct kvm_vcpu *vcpu,
 	mark_dirty(svm->vmcb, VMCB_SEG);
 }
 
-static void update_db_bp_intercept(struct kvm_vcpu *vcpu)
+static void update_bp_intercept(struct kvm_vcpu *vcpu)
 {
 	struct vcpu_svm *svm = to_svm(vcpu);
 
-	clr_exception_intercept(svm, DB_VECTOR);
 	clr_exception_intercept(svm, BP_VECTOR);
 
-	if (svm->nmi_singlestep)
-		set_exception_intercept(svm, DB_VECTOR);
-
 	if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) {
-		if (vcpu->guest_debug &
-		    (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))
-			set_exception_intercept(svm, DB_VECTOR);
 		if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
 			set_exception_intercept(svm, BP_VECTOR);
 	} else
@@ -1673,7 +1667,6 @@ static int db_interception(struct vcpu_svm *svm)
 		if (!(svm->vcpu.guest_debug & KVM_GUESTDBG_SINGLESTEP))
 			svm->vmcb->save.rflags &=
 				~(X86_EFLAGS_TF | X86_EFLAGS_RF);
-		update_db_bp_intercept(&svm->vcpu);
 	}
 
 	if (svm->vcpu.guest_debug &
@@ -3661,7 +3654,6 @@ static void enable_nmi_window(struct kvm_vcpu *vcpu)
 	 */
 	svm->nmi_singlestep = true;
 	svm->vmcb->save.rflags |= (X86_EFLAGS_TF | X86_EFLAGS_RF);
-	update_db_bp_intercept(vcpu);
 }
 
 static int svm_set_tss_addr(struct kvm *kvm, unsigned int addr)
@@ -4287,7 +4279,7 @@ static struct kvm_x86_ops svm_x86_ops = {
 	.vcpu_load = svm_vcpu_load,
 	.vcpu_put = svm_vcpu_put,
 
-	.update_db_bp_intercept = update_db_bp_intercept,
+	.update_db_bp_intercept = update_bp_intercept,
 	.get_msr = svm_get_msr,
 	.set_msr = svm_set_msr,
 	.get_segment_base = svm_get_segment_base,
path: arch/x86/kvm/svm.c