Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3790623ybi; Mon, 29 Jul 2019 12:41:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcbuiHOMqjZueMq0nw6mS9jpJm6mqo4b51yF9uVCHPrUoy8GI3LNvTIeWX050J0wC/R9cI X-Received: by 2002:aa7:98da:: with SMTP id e26mr38036411pfm.34.1564429261506; Mon, 29 Jul 2019 12:41:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429261; cv=none; d=google.com; s=arc-20160816; b=vC/3wuwlbvYM1urwQTK3wSNzaoaRIacqYU5EX9sPisN8o3UWQ66K+HxPitrHP8e5wv izBB8iQZ5EzP22P8OYIqpayaVQ6k1XznxSjHJ+43RkDOwW4F/WwoAm1GDGRgFOKfC0Hk fuHA6Ozoe+aOcnXzq26qp7DeMR/CZqumecV+UnEpXDN5vwvcxaUVTId/auDdvRN6LYVo gEasH0WMgiMoxQ3aWIODPdy8N3RkG3JSBex1n/hZEEnG3JsC65xXDZTlXzL2sMi890uV fi1Yvx8lb2KaIJwl72QbCWkeY/jO42Yue2l2OCQNfLiLCsD2h/pgbYb/xyRTASPgrIwI xhnA== 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=rnw+dt6AI1z8h6DLqm/kFjzmWAeiXDZOD3bSvkXPpqs=; b=dCJOny7Hk0nqNYGr18YaccSe4x87fbPQrZHLKuzafrqmu1R3fw433n/iRXHAy/tNB6 QGVVaF3r2KoKw7ESSoKpM/UeCaNyXqY3/H3ENN0mkYPMBGew9OnSgOih1wkMRoFeCg71 39BxOMQE7R4S//2Jtncfeqqx4FV9onMiW0krtO40OLID3vheb0SJTBE6YRFF6vRaO2oj 0SnZAL7uCcOcBVF4fO8iJ9Yin5ShQy56gerotFwavQ4xtOvuBDKAsOfotlwsvyxmkvjs yNeJVOSlPAC8upoI2NWXCsgp2gVv62SBYkjoqouzHmzzMmrevDTbrzo4OUku9qBPye/7 LpoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NAwncUoP; 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 e5si11389442pgl.536.2019.07.29.12.40.46; Mon, 29 Jul 2019 12:41:01 -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=NAwncUoP; 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 S1728561AbfG2TiP (ORCPT + 99 others); Mon, 29 Jul 2019 15:38:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:53146 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388136AbfG2TiL (ORCPT ); Mon, 29 Jul 2019 15:38:11 -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 11C0E206DD; Mon, 29 Jul 2019 19:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429090; bh=rzK8yFcGfbKCpoDsOUVJ4omD30vq1XPdn/iIvLzLvw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NAwncUoP3cJnIhnAcKy+uKBkNYlPGc7jVVQ1isK4SSkVuqAA67zQXLwEFudFxD2K2 qf9hXi00xDIdQNr/V2qszEc16IK4XASGEAmz9Hoft9HIFvA4Pk2xORw8YeijpD9+2b NbDpMlaDwoaZg7TM3jQe7J/d5/3jy538uQAuaVCw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kiszka , Liran Alon , Paolo Bonzini Subject: [PATCH 4.14 282/293] KVM: nVMX: do not use dangling shadow VMCS after guest reset Date: Mon, 29 Jul 2019 21:22:53 +0200 Message-Id: <20190729190845.859639288@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@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: Paolo Bonzini commit 88dddc11a8d6b09201b4db9d255b3394d9bc9e57 upstream. If a KVM guest is reset while running a nested guest, free_nested will disable the shadow VMCS execution control in the vmcs01. However, on the next KVM_RUN vmx_vcpu_run would nevertheless try to sync the VMCS12 to the shadow VMCS which has since been freed. This causes a vmptrld of a NULL pointer on my machime, but Jan reports the host to hang altogether. Let's see how much this trivial patch fixes. Reported-by: Jan Kiszka Cc: Liran Alon Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -7694,6 +7694,7 @@ static void vmx_disable_shadow_vmcs(stru { vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL, SECONDARY_EXEC_SHADOW_VMCS); vmcs_write64(VMCS_LINK_POINTER, -1ull); + vmx->nested.sync_shadow_vmcs = false; } static inline void nested_release_vmcs12(struct vcpu_vmx *vmx) @@ -7705,7 +7706,6 @@ static inline void nested_release_vmcs12 /* copy to memory all shadowed fields in case they were modified */ copy_shadow_to_vmcs12(vmx); - vmx->nested.sync_shadow_vmcs = false; vmx_disable_shadow_vmcs(vmx); } vmx->nested.posted_intr_nv = -1; @@ -7891,6 +7891,9 @@ static void copy_shadow_to_vmcs12(struct const unsigned long *fields = shadow_read_write_fields; const int num_fields = max_shadow_read_write_fields; + if (WARN_ON(!shadow_vmcs)) + return; + preempt_disable(); vmcs_load(shadow_vmcs); @@ -7938,6 +7941,9 @@ static void copy_vmcs12_to_shadow(struct u64 field_value = 0; struct vmcs *shadow_vmcs = vmx->vmcs01.shadow_vmcs; + if (WARN_ON(!shadow_vmcs)) + return; + vmcs_load(shadow_vmcs); for (q = 0; q < ARRAY_SIZE(fields); q++) {