Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3381244ybp; Sun, 6 Oct 2019 10:40:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzftU3a38uJr0+a91uqPow6RtNSRCelZCfjuHBqJalqAkbe45YjKG5WDVd5TkBj37S9hIHT X-Received: by 2002:a17:906:b316:: with SMTP id n22mr20380400ejz.54.1570383651637; Sun, 06 Oct 2019 10:40:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383651; cv=none; d=google.com; s=arc-20160816; b=KX+0XsdP+4asnpuynRyewLnMzD80rbAlY/tI14AXpo53hJePqqQ8tVqdm7zIG7bLji /pVqjVR1zxLOTLTvU8pnOoUhXf9BZs2nOmarL0LpTt1azRU09LBqM6r1DDUkyzKb9bPw Jzi3uMpC9OhXy+FZ7huRYO2Fc+scTemQRDQ6tMA0/ljH55v6WEmE+G+T+Wg5BspGXbQz 7RwFfp5zlG9Q4BCmVHYR7TIlep8Di3NRSHN+8dy7/0sp355NeoDnUm4D2RCiZbFWKOTk ypH4KkrWHzgrDJvFk5yh3APNxnLyY1GgStDCo7zqvYh2/IqPnzDm7XY88iHdIiWWju2j ZdNw== 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=+AWiEUVYyZDZOIcCm6AZ8X6z4+kXlENOt68VTIFeGX0=; b=MSDUmFxTG2yOoeQhzKsqIEYO0xWhGLYeRinXFAXOVS5yOm5zvM851ZWNhlUm5D9RCf 3sD0q/efAB/+xetwseKrSuCAQCbef6tJhYwd8JjN+n1XZVbiPMR9NiLFmrGmZ6JHoQcB TXxNIyMRBo29hXbZBwDO4ziw3pOkUKQtAF1evUIegQyY363Q88AusBpcK38OCXpVez2c ogoxGTNEi0qWJfoxcrQ/sm4ibtM4hTru7d7CXZdzB+akAZjCsCB+n7ipXFSEFEspJdX3 9++BqPbeR0CNIu0A+KGLr/HShZ71eq5mWIrRT39dPPv0G33r9I6KYWuTLaujAzn2xTc7 iHuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PFNEX33T; 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 m12si7417200edc.50.2019.10.06.10.40.27; Sun, 06 Oct 2019 10:40: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=PFNEX33T; 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 S1730015AbfJFRjD (ORCPT + 99 others); Sun, 6 Oct 2019 13:39:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:38442 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730707AbfJFRjB (ORCPT ); Sun, 6 Oct 2019 13:39:01 -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 3F2D12087E; Sun, 6 Oct 2019 17:39:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383540; bh=ccq2Zvw7Cswo0qu9PcmFIXaAvuTiz0QRI1+smMgNg/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PFNEX33TbloRFZULNlaVhPloTrKS9l5XLSBToNrRU+ZlFwrpt2qnlPC1xyHxlAa9z 75FX7QCKPhPJKLqWqkFo3qhv6deO4e+ci/koUS0g+07mcXk2UFWbDvurXEuODvPYZO +I4wsa4w8gV1DSKpP+fV1AEomGqbDWU2WbG4AaxY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+dff25ee91f0c7d5c1695@syzkaller.appspotmail.com, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Wanpeng Li , Vitaly Kuznetsov Subject: [PATCH 5.2 135/137] KVM: hyperv: Fix Direct Synthetic timers assert an interrupt w/o lapic_in_kernel Date: Sun, 6 Oct 2019 19:21:59 +0200 Message-Id: <20191006171220.642085179@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171209.403038733@linuxfoundation.org> References: <20191006171209.403038733@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: Wanpeng Li commit a073d7e3ad687a7ef32b65affe80faa7ce89bf92 upstream. Reported by syzkaller: kasan: GPF could be caused by NULL-ptr deref or user memory access general protection fault: 0000 [#1] PREEMPT SMP KASAN RIP: 0010:__apic_accept_irq+0x46/0x740 arch/x86/kvm/lapic.c:1029 Call Trace: kvm_apic_set_irq+0xb4/0x140 arch/x86/kvm/lapic.c:558 stimer_notify_direct arch/x86/kvm/hyperv.c:648 [inline] stimer_expiration arch/x86/kvm/hyperv.c:659 [inline] kvm_hv_process_stimers+0x594/0x1650 arch/x86/kvm/hyperv.c:686 vcpu_enter_guest+0x2b2a/0x54b0 arch/x86/kvm/x86.c:7896 vcpu_run+0x393/0xd40 arch/x86/kvm/x86.c:8152 kvm_arch_vcpu_ioctl_run+0x636/0x900 arch/x86/kvm/x86.c:8360 kvm_vcpu_ioctl+0x6cf/0xaf0 arch/x86/kvm/../../../virt/kvm/kvm_main.c:2765 The testcase programs HV_X64_MSR_STIMERn_CONFIG/HV_X64_MSR_STIMERn_COUNT, in addition, there is no lapic in the kernel, the counters value are small enough in order that kvm_hv_process_stimers() inject this already-expired timer interrupt into the guest through lapic in the kernel which triggers the NULL deferencing. This patch fixes it by don't advertise direct mode synthetic timers and discarding the inject when lapic is not in kernel. syzkaller source: https://syzkaller.appspot.com/x/repro.c?x=1752fe0a600000 Reported-by: syzbot+dff25ee91f0c7d5c1695@syzkaller.appspotmail.com Cc: Paolo Bonzini Cc: Radim Krčmář Signed-off-by: Wanpeng Li Reviewed-by: Vitaly Kuznetsov Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/hyperv.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -645,7 +645,9 @@ static int stimer_notify_direct(struct k .vector = stimer->config.apic_vector }; - return !kvm_apic_set_irq(vcpu, &irq, NULL); + if (lapic_in_kernel(vcpu)) + return !kvm_apic_set_irq(vcpu, &irq, NULL); + return 0; } static void stimer_expiration(struct kvm_vcpu_hv_stimer *stimer) @@ -1854,7 +1856,13 @@ int kvm_vcpu_ioctl_get_hv_cpuid(struct k ent->edx |= HV_FEATURE_FREQUENCY_MSRS_AVAILABLE; ent->edx |= HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE; - ent->edx |= HV_STIMER_DIRECT_MODE_AVAILABLE; + + /* + * Direct Synthetic timers only make sense with in-kernel + * LAPIC + */ + if (lapic_in_kernel(vcpu)) + ent->edx |= HV_STIMER_DIRECT_MODE_AVAILABLE; break;