From patchwork Sat Jan 27 07:56:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10187369 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1E0C360385 for ; Sat, 27 Jan 2018 08:06:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DD9D28C0C for ; Sat, 27 Jan 2018 08:06:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00A4028CBD; Sat, 27 Jan 2018 08:06:51 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 041B928C0C for ; Sat, 27 Jan 2018 08:06:50 +0000 (UTC) Received: (qmail 21972 invoked by uid 550); 27 Jan 2018 08:05:26 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 21898 invoked from network); 27 Jan 2018 08:05:25 -0000 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,421,1511856000"; d="scan'208";a="29879288" From: Dan Williams To: tglx@linutronix.de Cc: linux-arch@vger.kernel.org, kernel-hardening@lists.openwall.com, Andrew Honig , gregkh@linuxfoundation.org, Paolo Bonzini , alan@linux.intel.com, torvalds@linux-foundation.org, Jim Mattson Date: Fri, 26 Jan 2018 23:56:07 -0800 Message-ID: <151703976714.26578.17488222459772354305.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <151703971300.26578.1185595719337719486.stgit@dwillia2-desk3.amr.corp.intel.com> References: <151703971300.26578.1185595719337719486.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 Subject: [kernel-hardening] [PATCH v5 10/12] kvm, x86: update spectre-v1 mitigation X-Virus-Scanned: ClamAV using ClamSMTP 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'. We can save an lfence in this path and just use the common 'array_idx' helper designed for these types of fixes. Cc: Andrew Honig Cc: Jim Mattson Acked-by: Paolo Bonzini Signed-off-by: Dan Williams --- arch/x86/kvm/vmx.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 924589c53422..5345e68cc506 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "kvm_cache_regs.h" #include "x86.h" @@ -883,13 +884,18 @@ static const unsigned short vmcs_field_to_offset_table[] = { 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 sz = ARRAY_SIZE(vmcs_field_to_offset_table); + unsigned short offset; - if (field >= ARRAY_SIZE(vmcs_field_to_offset_table) || - vmcs_field_to_offset_table[field] == 0) + BUILD_BUG_ON(sz > SHRT_MAX); + if (field >= sz) return -ENOENT; - return vmcs_field_to_offset_table[field]; + field = array_idx(field, sz); + offset = vmcs_field_to_offset_table[field]; + if (offset == 0) + return -ENOENT; + return offset; } static inline struct vmcs12 *get_vmcs12(struct kvm_vcpu *vcpu)