Return-Path: Received: from mail-dm3nam03on0131.outbound.protection.outlook.com ([104.47.41.131]:48288 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032561AbeCAPjc (ORCPT ); Thu, 1 Mar 2018 10:39:32 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Dan Williams , Thomas Gleixner , Sasha Levin Subject: [added to the 4.1 stable tree] x86/kvm: Update spectre-v1 mitigation Date: Thu, 1 Mar 2018 15:27:48 +0000 Message-ID: <20180301152116.1486-499-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Dan Williams This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 085331dfc6bbe3501fb936e657331ca943827600 ] Commit 75f139aaf896 "KVM: x86: Add memory barrier on vmcs field lookup" added a raw 'asm("lfence");' to prevent a bounds check bypass of 'vmcs_field_to_offset_table'. The lfence can be avoided in this path by using the array_index_nospec() helper designed for these types of fixes. Signed-off-by: Dan Williams Signed-off-by: Thomas Gleixner Acked-by: Paolo Bonzini Cc: Andrew Honig Cc: kvm@vger.kernel.org Cc: Jim Mattson Link: https://lkml.kernel.org/r/151744959670.6342.3001723920950249067.stgit= @dwillia2-desk3.amr.corp.intel.com Signed-off-by: Sasha Levin --- arch/x86/kvm/vmx.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 6092e6c83de0..e8f34eaac2c8 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "kvm_cache_regs.h" #include "x86.h" =20 @@ -770,21 +771,18 @@ static const unsigned short vmcs_field_to_offset_tabl= e[] =3D { =20 static inline short vmcs_field_to_offset(unsigned long field) { - BUILD_BUG_ON(ARRAY_SIZE(vmcs_field_to_offset_table) > SHRT_MAX); + const size_t size =3D ARRAY_SIZE(vmcs_field_to_offset_table); + unsigned short offset; =20 - if (field >=3D ARRAY_SIZE(vmcs_field_to_offset_table)) + BUILD_BUG_ON(size > SHRT_MAX); + if (field >=3D size) return -ENOENT; =20 - /* - * FIXME: Mitigation for CVE-2017-5753. To be replaced with a - * generic mechanism. - */ - asm("lfence"); - - if (vmcs_field_to_offset_table[field] =3D=3D 0) + field =3D array_index_nospec(field, size); + offset =3D vmcs_field_to_offset_table[field]; + if (offset =3D=3D 0) return -ENOENT; - - return vmcs_field_to_offset_table[field]; + return offset; } =20 static inline struct vmcs12 *get_vmcs12(struct kvm_vcpu *vcpu) --=20 2.14.1