Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13957603pxu; Mon, 4 Jan 2021 08:59:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4pTir5weJdPqmtYyEmhpvrpMfgR+2V/ViroSIBUxBt0tFRy7sZZdXEGGVJ/pgHOs4dEE1 X-Received: by 2002:a17:906:b2d1:: with SMTP id cf17mr68718652ejb.281.1609779573492; Mon, 04 Jan 2021 08:59:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609779573; cv=none; d=google.com; s=arc-20160816; b=RkHAOXxkKcEt+2/PjK2C5u0/y4px4P9Xv1w8HYQ9g5rEw6vEaPdBftBTThwEr7mOvR 5Q+cpYvbwzTrBzFF3XuP2lfw9z+CGacoa7PlmdXvGKC1LAYIGw3oSNxBPXPnC3LuN0p7 iOBeLYX9ge4qc2KNua+YnGymSa35/0aOIpXJFUkeApPhNgrNLMpuyNwDtqiw8+VKjx/g 4XVdzPEDtBpaaUikOu73GD2xfWLkLiaeHZ7pCHXJExPfGOsD1Ku0F2UgePM/dvMomWqq ybf7m/vws5AeeIe6b9iGpCuGDMLDDQ8rUWx+e49F7nbfc0uPS2IqsOGJmfZ2k1uRko4R u+hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GHt27wUbEAmDfU7I+gc5weLN9Mgn96jFTZVcZ31ar5Q=; b=eOH/kSnJcExq9Vl5hgrwl+wvbefkbV4mVJAvXXNnpXL/tXfepioQ2Vj1JIKf61hzRv LYcsgz7//kapVnPC67G5Bz+tN/RPc9OXxo/EjWyMfMXvNHuS1ZRqMcgVk70mrOiyQErd XlPb0h00VwqYscUbIY/vaAXdIFs9sjsTi6v2+NM6vmjmjvOBpVBQOujl0UgKJm+5TtUp mTBWhiUKRZoMkf6/q6VNVATHtPdtdZ2lQsR3rrh9TzFG8+r5wnmwYfTFghsrAg2229F7 pToD6dngEOmMayqUmMeo8B3B0gmp5Db5hKLpXpa9hsWrjA2TMWlUqE/AyZvYFAsemCj/ Fe8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=U9aVQZM0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u21si32286939edx.350.2021.01.04.08.59.09; Mon, 04 Jan 2021 08:59:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=U9aVQZM0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729581AbhADQI1 (ORCPT + 99 others); Mon, 4 Jan 2021 11:08:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:38974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728620AbhADQBp (ORCPT ); Mon, 4 Jan 2021 11:01:45 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 71F3422515; Mon, 4 Jan 2021 16:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609776064; bh=krZ3AKzCCtzMuA9mGz3d3t2EqXtdL9ffVCFMkS0wWsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U9aVQZM08Ml94gl6HUURbJRdiWYIkYuDMBmbe0CQg71AIBZoHg3/qWQD/7SNLeWSa UVr5dR4bStBWJi8c2Jzw3MFv83RpaAj2Jz2++HZ7z37P74WomHvS34lAbhqoEMGzWL yRBf78eLqHa+qxJcYm6luocPYMX8Za9XmxwCYAv4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhiyi Guo , Paolo Bonzini , Sasha Levin , "Dr . David Alan Gilbert" , Laszlo Ersek Subject: [PATCH 5.4 13/47] KVM: SVM: relax conditions for allowing MSR_IA32_SPEC_CTRL accesses Date: Mon, 4 Jan 2021 16:57:12 +0100 Message-Id: <20210104155706.388304028@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210104155705.740576914@linuxfoundation.org> References: <20210104155705.740576914@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Bonzini [ Upstream commit df7e8818926eb4712b67421442acf7d568fe2645 ] Userspace that does not know about the AMD_IBRS bit might still allow the guest to protect itself with MSR_IA32_SPEC_CTRL using the Intel SPEC_CTRL bit. However, svm.c disallows this and will cause a #GP in the guest when writing to the MSR. Fix this by loosening the test and allowing the Intel CPUID bit, and in fact allow the AMD_STIBP bit as well since it allows writing to MSR_IA32_SPEC_CTRL too. Reported-by: Zhiyi Guo Analyzed-by: Dr. David Alan Gilbert Analyzed-by: Laszlo Ersek Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/svm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 72bf1d8175ac2..ca746006ac040 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -4233,6 +4233,8 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) break; case MSR_IA32_SPEC_CTRL: if (!msr_info->host_initiated && + !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL) && + !guest_cpuid_has(vcpu, X86_FEATURE_AMD_STIBP) && !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS) && !guest_cpuid_has(vcpu, X86_FEATURE_AMD_SSBD)) return 1; @@ -4318,6 +4320,8 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) break; case MSR_IA32_SPEC_CTRL: if (!msr->host_initiated && + !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL) && + !guest_cpuid_has(vcpu, X86_FEATURE_AMD_STIBP) && !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS) && !guest_cpuid_has(vcpu, X86_FEATURE_AMD_SSBD)) return 1; -- 2.27.0