Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3701553ybv; Mon, 10 Feb 2020 05:00:01 -0800 (PST) X-Google-Smtp-Source: APXvYqwKCae32UQik2xBu8co8qVcdy2u9CejBJo43u96nvJMkjNG7SYYoERD1h3TicTh4/melPRh X-Received: by 2002:a9d:7086:: with SMTP id l6mr926440otj.294.1581339601233; Mon, 10 Feb 2020 05:00:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339601; cv=none; d=google.com; s=arc-20160816; b=0GfwFfjMFx0lGyxwr68g8kEYm5kEUQZwv05CW7ej09clpOIg9zWctV9uaJ/oCLGJsb Sz0zVYP9brue/7SsHQMO/ZE6foRsqhRAlwcTnKeBsb9ZArFu38dcMmhc/H/wro8aGQe2 aUNDAsQgt1ZYn0OzUYG0UlexGGCHeqPw9J7dtln3VnizzAWmaO1/q8cV4pPx+f/GxNVg Uhnjkz3xwQDAC8TgBcmisWlZX2I/IFphEB7xLPGKY346A3/tW8Sg1pMiLESXxWVCYICS QtE7L+Q2wn/IijkhIFt1VDk7Z3VqIpptCEdYOKEY4QDJG5hNGTuQZq0Kdsw3ca2I0z6z TShw== 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=Yiz6lUJb1QmmAMubAAj3SGnBsUmEpxCoW+auwdMbnpY=; b=LjStcm7FG+d1bpDtP+kpMjArclhYFJkw07rS4huTHhLztRR01ngqHg96zWNZLi6Odt gnyWllxPviLs/lYwGeeLniI4kMI1HpXPH79zNlxg1oj1vknmaM8VzR5L3i9RA+O/WIYS OkmmSQa5cB5sBQeVdt7AUtSqeH/lsMWxx40D4zF8sFzMn6AojrL8lGc+r6NBdQ8Zv703 4933t1KfPH5wCxGwaQLJc31HiyLyUnAu+8nuwNcCduIXAOVUP4Vso8n2br9AV0wkK0y5 /CN4RJv/HbiEkWDRynGS6HDG0hs9ONWiOPF9bqgUQ+qN8svzzEWytGiFzQ5VZwJzXHhs 47eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KGHCeGNs; 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 w17si146309oiw.127.2020.02.10.04.59.49; Mon, 10 Feb 2020 05:00:01 -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=KGHCeGNs; 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 S1730256AbgBJM7N (ORCPT + 99 others); Mon, 10 Feb 2020 07:59:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:42928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729924AbgBJMlM (ORCPT ); Mon, 10 Feb 2020 07:41:12 -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 CF9F220842; Mon, 10 Feb 2020 12:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338471; bh=Xg4iqm6V4qtq84XPRJTH35SoanajKEy1ZkNBZh07Ma8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KGHCeGNs7IWnPvlMNVCj9NOvmUBiHpk3GelEnKErv8+6/d4BlXJPHY7DNAa+QaYML gAwF+Ur5C4JFYtia1cDLr8pKRRmYmRbhzneYicpKd4O4lRghGb7KClPTwJrGuXadVu aGyylJWrDa5q8gv6N4qaKcb5Z2EU7+QlqekI/yVY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nick Finco , Marios Pomonis , Andrew Honig , Jim Mattson , Paolo Bonzini Subject: [PATCH 5.5 237/367] KVM: x86: Protect x86_decode_insn from Spectre-v1/L1TF attacks Date: Mon, 10 Feb 2020 04:32:30 -0800 Message-Id: <20200210122446.064541026@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: Marios Pomonis commit 3c9053a2cae7ba2ba73766a34cea41baa70f57f7 upstream. This fixes a Spectre-v1/L1TF vulnerability in x86_decode_insn(). kvm_emulate_instruction() (an ancestor of x86_decode_insn()) is an exported symbol, so KVM should treat it conservatively from a security perspective. Fixes: 045a282ca415 ("KVM: emulator: implement fninit, fnstsw, fnstcw") Signed-off-by: Nick Finco Signed-off-by: Marios Pomonis Reviewed-by: Andrew Honig Cc: stable@vger.kernel.org Reviewed-by: Jim Mattson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/emulate.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -5315,10 +5315,15 @@ done_prefixes: } break; case Escape: - if (ctxt->modrm > 0xbf) - opcode = opcode.u.esc->high[ctxt->modrm - 0xc0]; - else + if (ctxt->modrm > 0xbf) { + size_t size = ARRAY_SIZE(opcode.u.esc->high); + u32 index = array_index_nospec( + ctxt->modrm - 0xc0, size); + + opcode = opcode.u.esc->high[index]; + } else { opcode = opcode.u.esc->op[(ctxt->modrm >> 3) & 7]; + } break; case InstrDual: if ((ctxt->modrm >> 6) == 3)