Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2567252yba; Mon, 6 May 2019 08:06:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwIGC50Sck98Cj0iiiKP7vJ3kSIirNXY3ytoQ/AN/Ev1P+QWKpAAPjXHH8vX+mYaS32xdoQ X-Received: by 2002:a17:902:7689:: with SMTP id m9mr32544142pll.274.1557155211849; Mon, 06 May 2019 08:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557155211; cv=none; d=google.com; s=arc-20160816; b=qiwoCnqQI2KEPtnjh5c3T9sLTOXw7QbfwpD2S5cr6NunA8UNaelQK+7FJO9dDT1moe gVvuzmVFnMyFUzyWZ1V5Mo3l2TtEZ7PC9CMEEPfd1QnU49qyWuszbk1PavoMa2b0qjI7 JbAtk6ldKhZml7VXLcU2iAp6laIOujceGSV436orsW3qSvHn1pET0c3MwZGcwBm9OwTy Dx8ZW0dtv5VeJOuQXyVjOrnNhAVVpgVFodeyPAI0HKjc88T/RzxcDGfYmVdkqP1GOLFw ySJkZLBhCii/MmFB2qfeBaRLi/rMKTPEgk+RPM9BCJ5/eS4AGSMntCSsTCroBeNAFUXN dhMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VC0tWIGA+s8Avu230LxURMyhsPdFv6vJUvHFVUHNu80=; b=t235Pvo732llcePWFFxOu6K/ZIUKzNPWi09muqNenqSFOHXDQM5/HJakjhZ+rPDVAd MLSa63rlWha7rVv+4SvFqhxoQLnbsEuW8XyXLY9rno/S0/Wxjem1ZNZA3tXO+anS9lUg n+ql80QOSSTkPMsQ6dP0VsdnujSxthfF7/rJO+BXc7JMVtDf9xNv5lxGvSrM9QNtTpOd dao5zWf5o4shdAIzLamUSn2v17/PWL+V8AkJSiPoNrVrX/xQmrTyK1PwKIpKNg72yswr nEZA+dgOiOtcOJTGzMNKI0MAbwRT7hVby3INXLb+dtpDvIOUgF7Bmx4QzUw2VWz26mru IWsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eEex5zye; 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.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d185si9078537pfa.182.2019.05.06.08.06.30; Mon, 06 May 2019 08:06:51 -0700 (PDT) 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; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eEex5zye; 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.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727723AbfEFOjD (ORCPT + 99 others); Mon, 6 May 2019 10:39:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:60192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726439AbfEFOix (ORCPT ); Mon, 6 May 2019 10:38:53 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E8CDE214AF; Mon, 6 May 2019 14:38:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153532; bh=BKhbmqv6L6lntJ0v+ab+H4zgl/rxM7OzeccCAY5BKTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eEex5zyep3Il6EmGrJerD3x3YUsVqB/uxJDGZUwpf7ZNqrWaB95d6XCU5tfbBbC9/ uSdE2zkMpa0NYYh8vD1MtVM2PvdHZagMxn5Phty9bvDWmV7lJXRSvAwxOp9un2VLyl zFhVqysVoluJUZIBB5PS5ecUW56Egc0sQqwFLO7E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+f7e65445a40d3e0e4ebf@syzkaller.appspotmail.com, Sean Christopherson , Konrad Rzeszutek Wilk , Paolo Bonzini Subject: [PATCH 5.0 103/122] KVM: lapic: Check for in-kernel LAPIC before deferencing apic pointer Date: Mon, 6 May 2019 16:32:41 +0200 Message-Id: <20190506143103.965452572@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit b904cb8dff824b79233e82c078837627ebd52717 upstream. ...to avoid dereferencing a null pointer when querying the per-vCPU timer advance. Fixes: 39497d7660d98 ("KVM: lapic: Track lapic timer advance per vCPU") Reported-by: syzbot+f7e65445a40d3e0e4ebf@syzkaller.appspotmail.com Signed-off-by: Sean Christopherson Reviewed-by: Konrad Rzeszutek Wilk Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/lapic.c | 3 --- arch/x86/kvm/x86.c | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1504,9 +1504,6 @@ void wait_lapic_expire(struct kvm_vcpu * u32 timer_advance_ns = apic->lapic_timer.timer_advance_ns; u64 guest_tsc, tsc_deadline, ns; - if (!lapic_in_kernel(vcpu)) - return; - if (apic->lapic_timer.expired_tscdeadline == 0) return; --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7886,7 +7886,8 @@ static int vcpu_enter_guest(struct kvm_v } trace_kvm_entry(vcpu->vcpu_id); - if (vcpu->arch.apic->lapic_timer.timer_advance_ns) + if (lapic_in_kernel(vcpu) && + vcpu->arch.apic->lapic_timer.timer_advance_ns) wait_lapic_expire(vcpu); guest_enter_irqoff();