Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8129920imu; Tue, 4 Dec 2018 03:31:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/WgiZ8l59hnIyz8VD2n/uH5Q0hUJjgIeJ6+B2lqMPJIB9Nf2am6n2u/noKDkNXD5zSNQg7p X-Received: by 2002:a17:902:142:: with SMTP id 60mr20293273plb.330.1543923102328; Tue, 04 Dec 2018 03:31:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543923102; cv=none; d=google.com; s=arc-20160816; b=Fy7cZL4F2dbvlxzXB4uFchfbtNLbKOnTjdhxgZgZzoHAk+CUSEmB23H9roW0YP8Cmp 2at89OEcF3MaufzMPfUVahVZ5zmaG0nr5c3cIyT2vNUvPtlk+XKlCY7DLV4ffWg3Hq0R /jRoW1K7SoY2RDU7dE/lkjbSKKN2g0Foeya+ek0yiwcOkac2g9JBc1imJ7tvDtmefTD6 3usi86ODnK/ILGQeHGHD5TR01cc86OEqd8S+6M6dhUX9DSA1477YkZCVphhW0O6H/5xB NCGZlNbwytKsO704qpM74TGpKXFwDSUf+h7ou45radRxk4s34wORgbQcdpMVzQ1kg8AG xskg== 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=WSRRPyypWTa9Ac7NCtWcsmivjcEDvbF9U8IhHG41gcc=; b=Soe1+XfQNPrHiljE7/FuQNmZFpCqFWW2a20RSqqePzwbNMUy/ACI51xn7le/FFUbSo FaBtDXIn8jrLuurzGC/w5enbsMljs5JsrCyBC9wdmFasyc+HDabFDiiJvrX1diese6Md 4cKStT935l/NWlP0AqyedEeNmd6yG5Gjlaq/kVwWCIwTiuT8X5NHBzUPKeE7lCMfMpdt R+D2sGPBVTgPuD1LsnkYDwnxI3IKMq4iWk69O34itwDSniShen+LpGkJI1JXbBMuG5Xf /hyPG+R/Adlb8ESZtYJFr46mpnKW6XdDUbt3WurpXs+0ZvHw2E9M12HF9u2z8FNHiLwD RZhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="yGqzu05/"; 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 204si15649071pfu.273.2018.12.04.03.31.26; Tue, 04 Dec 2018 03:31:42 -0800 (PST) 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="yGqzu05/"; 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 S1727136AbeLDL3n (ORCPT + 99 others); Tue, 4 Dec 2018 06:29:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:41940 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726378AbeLDK5u (ORCPT ); Tue, 4 Dec 2018 05:57:50 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 47A4B20878; Tue, 4 Dec 2018 10:57:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921069; bh=ephEgpv4aN9JPKmp1LWZBBbtm4ucmuzRjunhbwSCG0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yGqzu05/+xvC6cCFnmOLnM5/7iDkdFuHR3J9fk+WM3E3h9Hjc7hEf/UFJgvPX0PdU IidXkCWRbvsqWETCQOaYgzoqlCWYmn4jA1ehSAli3EesJpzWAa7fOS7n4XZKuwJGs6 h0kvZf6xzPTMKTLkE5wnYszPMe/9vvs7dy/Jq+MQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wei Wu , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Wanpeng Li Subject: [PATCH 4.19 067/139] KVM: LAPIC: Fix pv ipis use-before-initialization Date: Tue, 4 Dec 2018 11:49:08 +0100 Message-Id: <20181204103652.803586868@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103649.950154335@linuxfoundation.org> References: <20181204103649.950154335@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wanpeng Li commit 38ab012f109caf10f471db1adf284e620dd8d701 upstream. Reported by syzkaller: BUG: unable to handle kernel NULL pointer dereference at 0000000000000014 PGD 800000040410c067 P4D 800000040410c067 PUD 40410d067 PMD 0 Oops: 0000 [#1] PREEMPT SMP PTI CPU: 3 PID: 2567 Comm: poc Tainted: G OE 4.19.0-rc5 #16 RIP: 0010:kvm_pv_send_ipi+0x94/0x350 [kvm] Call Trace: kvm_emulate_hypercall+0x3cc/0x700 [kvm] handle_vmcall+0xe/0x10 [kvm_intel] vmx_handle_exit+0xc1/0x11b0 [kvm_intel] vcpu_enter_guest+0x9fb/0x1910 [kvm] kvm_arch_vcpu_ioctl_run+0x35c/0x610 [kvm] kvm_vcpu_ioctl+0x3e9/0x6d0 [kvm] do_vfs_ioctl+0xa5/0x690 ksys_ioctl+0x6d/0x80 __x64_sys_ioctl+0x1a/0x20 do_syscall_64+0x83/0x6e0 entry_SYSCALL_64_after_hwframe+0x49/0xbe The reason is that the apic map has not yet been initialized, the testcase triggers pv_send_ipi interface by vmcall which results in kvm->arch.apic_map is dereferenced. This patch fixes it by checking whether or not apic map is NULL and bailing out immediately if that is the case. Fixes: 4180bf1b65 (KVM: X86: Implement "send IPI" hypercall) Reported-by: Wei Wu Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Wei Wu Signed-off-by: Wanpeng Li Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/lapic.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -571,6 +571,11 @@ int kvm_pv_send_ipi(struct kvm *kvm, uns rcu_read_lock(); map = rcu_dereference(kvm->arch.apic_map); + if (unlikely(!map)) { + count = -EOPNOTSUPP; + goto out; + } + if (min > map->max_apic_id) goto out; /* Bits above cluster_size are masked in the caller. */