Received: by 10.223.176.5 with SMTP id f5csp712316wra; Fri, 9 Feb 2018 06:05:36 -0800 (PST) X-Google-Smtp-Source: AH8x226N5oh772qWER4s9lzg1m1WrZQKPP2s65fdOmwbXIB28P9VYwwmWFxd2G2BfvtvuT3IYMvp X-Received: by 10.99.50.66 with SMTP id y63mr1649088pgy.207.1518185135984; Fri, 09 Feb 2018 06:05:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518185135; cv=none; d=google.com; s=arc-20160816; b=TsQPAyD5vh07/2/PXvp+3YVxjGCGQmVKNf+99RoD4FIHx7TSdJvv+uI2XzXYo9rgYX 6NHJYcEAhmsd68g2FpmfIGb8lKbrXptVmtY7A21CcbIYNGfniTL3wuaj0X+KopNzq+Cm cvYLXu5em8Xe61XpvW9fdYnFY3z+5NiLrJA+1+KX1UgYLeExbuO8nv3fWPjtDBHz5hpM nvI9n6ANJumSth6/sw5u2js/LVC4AD9gVUc39vXEgIL6k2o+1+1RHF+h4TgCgysSmE4v 5CgNAFjgExZHt/N+Av58VnxSa/DXjCqMCuN2fP3p9QljXvR/BNv4YeJv8AnQu0YVoUYs aoOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=+hOnHHypFOF+/U3VviiSNtRQqaZG/gvQttODkbHZnzo=; b=bRfm48zAxd2SelR0JxfrRYk1zv2SSH737hWHL4bbCKwmZfBVFSav7S5knseNDml1ib zd3YmOut1lMZmB+tMEggY5m8IxG748WhCjC95xs4aCWRV2ngbH/blERYjci7WJ3U0R45 u9paL40pVEsKitqjJLOQ7FWdKerlxXeydVZoSvPVnleWYV/t04Y/FAvdLxFpwxUq3Mvv gS/vxIKnum/lbDLPujQz5rsiq5SZbCcl2V9JPXJU1rXAmxEtDQFIEv3eHLEt9YXUaXE2 x2C/HvSqKzy0GZnrZ0lvwPjzbP9rc7ysS/8brfYqiWJbOKxO9EjCHs36RA7ZLMhzseNh 5yGg== ARC-Authentication-Results: i=1; mx.google.com; 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 y96-v6si319928plh.796.2018.02.09.06.05.21; Fri, 09 Feb 2018 06:05:35 -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; 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 S1753442AbeBIODQ (ORCPT + 99 others); Fri, 9 Feb 2018 09:03:16 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50864 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753277AbeBINni (ORCPT ); Fri, 9 Feb 2018 08:43:38 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 68DD51084; Fri, 9 Feb 2018 13:43:32 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Williams , Thomas Gleixner , Paolo Bonzini , Andrew Honig , kvm@vger.kernel.org, Jim Mattson , David Woodhouse Subject: [PATCH 4.9 71/92] x86/kvm: Update spectre-v1 mitigation Date: Fri, 9 Feb 2018 14:39:40 +0100 Message-Id: <20180209133936.369984467@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180209133931.211869118@linuxfoundation.org> References: <20180209133931.211869118@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams (cherry picked from 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: David Woodhouse Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "kvm_cache_regs.h" #include "x86.h" @@ -856,21 +857,18 @@ static const unsigned short vmcs_field_t 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 = ARRAY_SIZE(vmcs_field_to_offset_table); + unsigned short offset; - if (field >= ARRAY_SIZE(vmcs_field_to_offset_table)) + BUILD_BUG_ON(size > SHRT_MAX); + if (field >= size) return -ENOENT; - /* - * FIXME: Mitigation for CVE-2017-5753. To be replaced with a - * generic mechanism. - */ - asm("lfence"); - - if (vmcs_field_to_offset_table[field] == 0) + field = array_index_nospec(field, size); + offset = vmcs_field_to_offset_table[field]; + if (offset == 0) return -ENOENT; - - return vmcs_field_to_offset_table[field]; + return offset; } static inline struct vmcs12 *get_vmcs12(struct kvm_vcpu *vcpu)