Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3700946ybv; Mon, 10 Feb 2020 04:59:19 -0800 (PST) X-Google-Smtp-Source: APXvYqxZ9eEDlOb21twoguuyA+oMz1cjvR/FmU1XjDGrnSDzc5CjpOw4lL4Zy3KDCya2vZs2TOS0 X-Received: by 2002:aca:c08b:: with SMTP id q133mr709661oif.46.1581339558967; Mon, 10 Feb 2020 04:59:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339558; cv=none; d=google.com; s=arc-20160816; b=sidDHrGIYiu3zLAmHiVgiQRmP+blD875JjtMDMHgwDxzFD1Ati939yrl8d1b0MI1g1 iVf+zWMPbFEfTXjNg+3bShXHX0ib6IbxEv3+aDFaZOp2xTId+GZ0Q+fLL5kvkC5lGctK qmhk8Gj6CFIYQQ9t5xkupRwkGU7VmezfNeptGxIIFYIekpZAjCmsYVxAu4pwyLIYXPFv 3MBMMCAFMG3GxHJ1t3gikxYHsnkXOnu0QM+bzVVch790ATWe6Kz1pJ9P06aJ+3v38eg1 6Mkrd9BV7gD7QlJvdhaI/GIAasr2BsT4Zq+yfx4mxJr3oblUVgzr2NNtzS/85INsfpZb m4Ew== 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=+uFa8ZmveBd3IAubJw/LOkB4x4Nx3ApHvBoqIzCNNkU=; b=I+chdu0P3GfNnx598Mrw56y1nRNCv1eKmHNM1qNxO3PTz7P+cNucdvmIL8cwEywxhi zSSNKgJ5+WWJeuWGPovYiHjkjqidquoO4t4gKbaR1/gR4IX5irG+BZ2n38N5gNvDwdxx k7rIrDnG07ZNeywV2a+qvDxidRxdMDPv0+7X39ofzF+B8tf5OV7U1AtbgPjqCIyTlOnm pzyPvV+gpveGxrNcbdfSlUsxjKjQtyh541yvt0KgC13NoxRVQnVfBVnGYgl2+vd3wiPu Fs5r+ZBp+PMsBYCR1L7R/SJkblmO2C7L+HUTERGAMXpniovAGqCIZb2bV0QtDFS3aUBy gWNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=d9Z+fqyR; 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 q5si152280otc.104.2020.02.10.04.59.06; Mon, 10 Feb 2020 04:59:18 -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=d9Z+fqyR; 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 S1730324AbgBJM7F (ORCPT + 99 others); Mon, 10 Feb 2020 07:59:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:42996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729930AbgBJMlN (ORCPT ); Mon, 10 Feb 2020 07:41:13 -0500 Received: from localhost (unknown [209.37.97.194]) (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 D8472208C4; Mon, 10 Feb 2020 12:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338472; bh=vhRLEy4HV1cqmwL8Bqv3oRFy3zqH/RFeZ1xgFRoe5+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d9Z+fqyRVFlw/8uRt0J3GosygYvQM+beUELeBY5N2QnqFXWzQKXxGkGd0vK+ImrED 94DrV/N4/Wnz0fDFlf90IP2BPFmccvJdn0KYDrg9hgC8lPNTaOaOrs4AHK9p2imubY x+IbEUbGelVbg4P16BLn7s3dKe9T5yBz+9ccwnhQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.5 239/367] KVM: x86: Fix potential put_fpu() w/o load_fpu() on MPX platform Date: Mon, 10 Feb 2020 04:32:32 -0800 Message-Id: <20200210122446.247266760@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@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 f958bd2314d117f8c29f4821401bc1925bc2e5ef upstream. Unlike most state managed by XSAVE, MPX is initialized to zero on INIT. Because INITs are usually recognized in the context of a VCPU_RUN call, kvm_vcpu_reset() puts the guest's FPU so that the FPU state is resident in memory, zeros the MPX state, and reloads FPU state to hardware. But, in the unlikely event that an INIT is recognized during kvm_arch_vcpu_ioctl_get_mpstate() via kvm_apic_accept_events(), kvm_vcpu_reset() will call kvm_put_guest_fpu() without a preceding kvm_load_guest_fpu() and corrupt the guest's FPU state (and possibly userspace's FPU state as well). Given that MPX is being removed from the kernel[*], fix the bug with the simple-but-ugly approach of loading the guest's FPU during KVM_GET_MP_STATE. [*] See commit f240652b6032b ("x86/mpx: Remove MPX APIs"). Fixes: f775b13eedee2 ("x86,kvm: move qemu/guest FPU switching out to vcpu_run") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8724,6 +8724,8 @@ int kvm_arch_vcpu_ioctl_get_mpstate(stru struct kvm_mp_state *mp_state) { vcpu_load(vcpu); + if (kvm_mpx_supported()) + kvm_load_guest_fpu(vcpu); kvm_apic_accept_events(vcpu); if (vcpu->arch.mp_state == KVM_MP_STATE_HALTED && @@ -8732,6 +8734,8 @@ int kvm_arch_vcpu_ioctl_get_mpstate(stru else mp_state->mp_state = vcpu->arch.mp_state; + if (kvm_mpx_supported()) + kvm_put_guest_fpu(vcpu); vcpu_put(vcpu); return 0; }