From patchwork Fri Nov 30 17:28:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10706937 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9722213AD for ; Fri, 30 Nov 2018 17:53:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 825F22F6FC for ; Fri, 30 Nov 2018 17:53:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 730B12F749; Fri, 30 Nov 2018 17:53:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C6102F6FC for ; Fri, 30 Nov 2018 17:53:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725832AbeLAFDb (ORCPT ); Sat, 1 Dec 2018 00:03:31 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:59428 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725749AbeLAFDa (ORCPT ); Sat, 1 Dec 2018 00:03:30 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wAUHmwlc188297; Fri, 30 Nov 2018 17:53:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=lgat+Muk8vtpQQoh525kSrCD6F198nQIAtMvCfleHXc=; b=UHbrqDPdspIbGKdOE7E9ZYp2BJ345viC6GupbCsKiAzrrc6dT3m8n7oEt8jAqYk5MZE5 ASgdAEJ3upVf8lZSEQHNeTgAAd+MWtgbOv3lvFdCXGgLH1ItDVWKdhoXwW2wvBpEiNtz m2avfAh3QRK3QfeURN2Vnwc3/E73I9OmpaRkS4RlRnT3kE/gBLuVtdNZgWh8o/OVw0/i jmG/VvPyqMSSj3Z7x17Pwk5iuPjpCpPTNAoEr7MXnGxtEjJoyBVZa0IwRSdbxHKb5tB6 jrejO6+MWc5+J3ekRqcuq2KFzTdoWfheybIF9ryztCQ+W5TUiOPUM/7vdlaquTFlxr11 4Q== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2p2jf0pwmb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 Nov 2018 17:53:16 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wAUHrFgP019442 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 Nov 2018 17:53:15 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wAUHrEI2029581; Fri, 30 Nov 2018 17:53:14 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 30 Nov 2018 09:53:14 -0800 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: jmattson@google.com, pbonzini@redhat.com, rkrcmar@redhat.com Subject: [PATCH] KVM nVMX: MSRs should not be stored if VM-entry fails during or after loading guest state Date: Fri, 30 Nov 2018 12:28:58 -0500 Message-Id: <20181130172858.6821-1-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.9.5 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9093 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=822 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811300152 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If a bit-pattern for the MSR-store address is so chosen that the address is 16-bit aligned and is less than the processor's physical width, but is a junk, VMENTRY ultimately fails even though we pass the checks in check_vmentry_prereqs(). In such a case, the high bit in "exit reason" will be set, denoting a VM-entry failure. But since we call nested_vmx_store_msr() in nested_vmx_vmexit() without checking the "exit reason", we may end up storing the MSRs at an undefined location in memory thereby clobbering something else. This patch fixes the problem by calling nested_vmx_store_msr() only when "exit reason" is not VM-entry failure. Reported-by: Krish Sadhukhan Suggested-by: Jim Mattson Signed-off-by: Krish Sadhukhan Reviewed-by: Darren Kenny --- arch/x86/kvm/vmx.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 4555077..aecd461 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -13827,6 +13827,12 @@ static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, * L2 to IDT_VECTORING_INFO_FIELD. */ vmcs12_save_pending_event(vcpu, vmcs12); + + if (nested_vmx_store_msr(vcpu, + vmcs12->vm_exit_msr_store_addr, + vmcs12->vm_exit_msr_store_count)) + nested_vmx_abort(vcpu, + VMX_ABORT_SAVE_GUEST_MSR_FAIL); } /* @@ -14159,10 +14165,6 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason, * immutable. */ nested_flush_cached_shadow_vmcs12(vcpu, vmcs12); - - if (nested_vmx_store_msr(vcpu, vmcs12->vm_exit_msr_store_addr, - vmcs12->vm_exit_msr_store_count)) - nested_vmx_abort(vcpu, VMX_ABORT_SAVE_GUEST_MSR_FAIL); } else { /* * The only expected VM-instruction error is "VM entry with