c519a21
Bugzilla: 1042081
c519a21
Upstream-status: 3.13 and sent for stable                                                                                                                                                                                                                                                               
c519a21
Delivered-To: jwboyer@gmail.com
c519a21
Received: by 10.76.104.107 with SMTP id gd11csp361402oab;
c519a21
        Thu, 12 Dec 2013 12:43:43 -0800 (PST)
c519a21
X-Received: by 10.68.241.134 with SMTP id wi6mr15423072pbc.44.1386881023599;
c519a21
        Thu, 12 Dec 2013 12:43:43 -0800 (PST)
c519a21
Return-Path: <linux-kernel-owner@vger.kernel.org>
c519a21
Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67])
c519a21
        by mx.google.com with ESMTP id w3si17375457pbh.89.2013.12.12.12.43.07
c519a21
        for <multiple recipients>;
c519a21
        Thu, 12 Dec 2013 12:43:43 -0800 (PST)
c519a21
Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67;
c519a21
Authentication-Results: mx.google.com;
c519a21
       spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mail=linux-kernel-owner@vger.kernel.org;
c519a21
       dkim=neutral (bad format) header.i=@gmail.com
c519a21
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
c519a21
	id S1752145Ab3LLUiu (ORCPT <rfc822;multinymous@gmail.com>
c519a21
	+ 99 others); Thu, 12 Dec 2013 15:38:50 -0500
c519a21
Received: from mail-ee0-f45.google.com ([74.125.83.45]:47138 "EHLO
c519a21
	mail-ee0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
c519a21
	with ESMTP id S1751902Ab3LLUhP (ORCPT
c519a21
	<rfc822;linux-kernel@vger.kernel.org>);
c519a21
	Thu, 12 Dec 2013 15:37:15 -0500
c519a21
Received: by mail-ee0-f45.google.com with SMTP id d49so478739eek.32
c519a21
        for <multiple recipients>; Thu, 12 Dec 2013 12:37:13 -0800 (PST)
c519a21
DKIM-Signature:	v=1; a=rsa-sha256; c=relaxed/relaxed;
c519a21
        d=gmail.com; s=20120113;
c519a21
        h=sender:from:to:cc:subject:date:message-id;
c519a21
        bh=Fa9qXXe9oER+jgB6WXA5v2LyR8O2Vaag7ZsOsv67MLg=;
c519a21
        b=WbBUzKN8o3OzB75st3w60z/rVczWaaxrvWc2URlwJwZ0lgqObvbXvAb3ophFJxsr/O
c519a21
         P3rEj33CGt5vFAmZWsrST8I4pVb7IPZYqmPuBklMhDmvegy2um2xEDCyIuI0oybwgple
c519a21
         n1dYPBTNqBhiiLgIUeKgEf88yU5dsAgKOZSTnkMYhDSy9pnGxRda4WtErJ+SHjvcMaX3
c519a21
         t2Vt97egJ2n+e+2BvnpS8xZ8biqp6/l3EzvdsL4W849fUUshAKva4Npu0T/D4E3JIp2O
c519a21
         3uY+geb/txJL2rOCacT3RljUb3+zAy2zhqGSjKR3AHePFNIX9RxfMi/vlPmTjO0vfmCP
c519a21
         H86Q==
c519a21
X-Received: by 10.14.2.73 with SMTP id 49mr10139590eee.15.1386880633625;
c519a21
        Thu, 12 Dec 2013 12:37:13 -0800 (PST)
c519a21
Received: from playground.com (net-2-35-202-54.cust.dsl.vodafone.it. [2.35.202.54])
c519a21
        by mx.google.com with ESMTPSA id o47sm70323739eem.21.2013.12.12.12.37.11
c519a21
        for <multiple recipients>
c519a21
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
c519a21
        Thu, 12 Dec 2013 12:37:12 -0800 (PST)
c519a21
From:	Paolo Bonzini <pbonzini@redhat.com>
c519a21
To:	linux-kernel@vger.kernel.org
c519a21
Cc:	gleb@redhat.com, kvm@vger.kernel.org, pmatouse@redhat.com,
c519a21
	Andy Honig <ahonig@google.com>, stable@vger.kernel.org
c519a21
Subject: [PATCH] KVM: x86: Fix potential divide by 0 in lapic (CVE-2013-6367)
c519a21
Date:	Thu, 12 Dec 2013 21:36:52 +0100
c519a21
Message-Id: <1386880614-23300-2-git-send-email-pbonzini@redhat.com>
c519a21
X-Mailer: git-send-email 1.8.3.1
c519a21
Sender:	linux-kernel-owner@vger.kernel.org
c519a21
Precedence: bulk
c519a21
List-ID: <linux-kernel.vger.kernel.org>
c519a21
X-Mailing-List:	linux-kernel@vger.kernel.org
c519a21
c519a21
From: Andy Honig <ahonig@google.com>
c519a21
c519a21
Under guest controllable circumstances apic_get_tmcct will execute a
c519a21
divide by zero and cause a crash.  If the guest cpuid support
c519a21
tsc deadline timers and performs the following sequence of requests
c519a21
the host will crash.
c519a21
- Set the mode to periodic
c519a21
- Set the TMICT to 0
c519a21
- Set the mode bits to 11 (neither periodic, nor one shot, nor tsc deadline)
c519a21
- Set the TMICT to non-zero.
c519a21
Then the lapic_timer.period will be 0, but the TMICT will not be.  If the
c519a21
guest then reads from the TMCCT then the host will perform a divide by 0.
c519a21
c519a21
This patch ensures that if the lapic_timer.period is 0, then the division
c519a21
does not occur.
c519a21
c519a21
Reported-by: Andrew Honig <ahonig@google.com>
c519a21
Cc: stable@vger.kernel.org
c519a21
Signed-off-by: Andrew Honig <ahonig@google.com>
c519a21
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
c519a21
---
c519a21
 arch/x86/kvm/lapic.c | 3 ++-
c519a21
 1 file changed, 2 insertions(+), 1 deletion(-)
c519a21
c519a21
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
c519a21
index 5439117d5c4c..89b52ec7d09c 100644
c519a21
--- a/arch/x86/kvm/lapic.c
c519a21
+++ b/arch/x86/kvm/lapic.c
c519a21
@@ -841,7 +841,8 @@ static u32 apic_get_tmcct(struct kvm_lapic *apic)
c519a21
 	ASSERT(apic != NULL);
c519a21
 
c519a21
 	/* if initial count is 0, current count should also be 0 */
c519a21
-	if (kvm_apic_get_reg(apic, APIC_TMICT) == 0)
c519a21
+	if (kvm_apic_get_reg(apic, APIC_TMICT) == 0 ||
c519a21
+		apic->lapic_timer.period == 0)
c519a21
 		return 0;
c519a21
 
c519a21
 	remaining = hrtimer_get_remaining(&apic->lapic_timer.timer);
c519a21
-- 
c519a21
1.8.3.1
c519a21
c519a21
--
c519a21
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
c519a21
the body of a message to majordomo@vger.kernel.org
c519a21
More majordomo info at  http://vger.kernel.org/majordomo-info.html
c519a21
Please read the FAQ at  http://www.tux.org/lkml/