Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3691352ybv; Mon, 10 Feb 2020 04:47:44 -0800 (PST) X-Google-Smtp-Source: APXvYqyiB49J9pecAJBk1lYbmNTpB2BG2qGwXVw0Zur5bLlzzn/7rEvFdZQ5Hzg2NNWzSqcawAeT X-Received: by 2002:a05:6830:12c3:: with SMTP id a3mr934993otq.341.1581338864239; Mon, 10 Feb 2020 04:47:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581338864; cv=none; d=google.com; s=arc-20160816; b=Z+Q48//jySILcOTAuB0yjyGPx+72AXwLJPaZzxk7uJadg0jf/vrCt6GeGyG3Hvul3p yy6Y67bpNfS6OiixrdJKqwuJXC1Jivm7pL+T1rjZo+yDtV8jMlWy598GJvoQoQLrDL6U PNhxYxIqxd0rl3GEfR9jtsQedlrUMLAPw/rtocNbl6R10W4CuYwR0TWYI2ikdGE2LbHp DEhJqjlo/fUe3QNlQ6QfSdKiICxry2IDntnbh97vdplxMmCuGafw18Z+sUmecvin4P+y R9HHpu7Zboy8/cqsi6EDvds7vo6X3X8daFaHLRfNLF0NkIoAK+Nr/wNQKJtAPeGH696A Wz5w== 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=VAQVZ55EMTDKyZNyRrc7SubfacpWRE6j9J3ebazZFaQ=; b=0ey40mqrMnERzfE5kjqNHthBAeteus3xqmVPpMOdOhXx4T7Q0OxKh0A8o5XfR6JNqe 4BeyXEKMZ1ZnHJWUu8d42auZdYcwMmflRaIOW9/i/s4Ob5SxB//WFnqlExR0doAVCnUJ sFs2bqkCbZk732qVXVqctY3Fp8tV0TlFXT8JIziWoeSzM2hWkgGXb38vYTsEsEFU35qR UjzFqg3lLh+QVbx8I8amoxjHwP6qfyCDVk544Ns0zmHttY1nS5aN6g4u4hhZsgthlluo VfK2yO8Joy5YJ4IIlhdwoXNy5dZntIMPWWVinRMcvUqFliS55N9potO55+ovYbZW7NtH LtWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="VpL/Wp2l"; 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 s20si157482otp.4.2020.02.10.04.47.31; Mon, 10 Feb 2020 04:47:44 -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="VpL/Wp2l"; 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 S1729098AbgBJMr2 (ORCPT + 99 others); Mon, 10 Feb 2020 07:47:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:45952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730178AbgBJMmM (ORCPT ); Mon, 10 Feb 2020 07:42: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 8D9CC2467C; Mon, 10 Feb 2020 12:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338531; bh=z8Bj/ZYhZcXRqYJUSCeKwABFvzo3UDEruzmyOlZ0WVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VpL/Wp2lynV/zFWg+jLpu0SIjlNRagqvSCYBjM8ZtxufMEX44QQBVel4QlDpkneYR xZh4hSnzT/PsxoGKb148MoFowfd0fOAH7a7v4xqcA4s8RvbB2ghOB6C0lt4X3BIJcg 3TIegDCoZyMNVa4V4voJwE412TNZBLrctwC12c9Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marios Pomonis , Nick Finco , Sean Christopherson , Andrew Honig , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.5 356/367] KVM: x86: Protect exit_reason from being used in Spectre-v1/L1TF attacks Date: Mon, 10 Feb 2020 04:34:29 -0800 Message-Id: <20200210122455.307475570@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 [ Upstream commit c926f2f7230b1a29e31914b51db680f8cbf3103f ] This fixes a Spectre-v1/L1TF vulnerability in vmx_handle_exit(). While exit_reason is set by the hardware and therefore should not be attacker-influenced, an unknown exit_reason could potentially be used to perform such an attack. Fixes: 55d2375e58a6 ("KVM: nVMX: Move nested code to dedicated files") Signed-off-by: Marios Pomonis Signed-off-by: Nick Finco Suggested-by: Sean Christopherson Reviewed-by: Andrew Honig Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/vmx/vmx.c | 55 +++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 83464a86ac405..78e01e2524bc3 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5904,34 +5904,39 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu) } } - if (exit_reason < kvm_vmx_max_exit_handlers - && kvm_vmx_exit_handlers[exit_reason]) { + if (exit_reason >= kvm_vmx_max_exit_handlers) + goto unexpected_vmexit; #ifdef CONFIG_RETPOLINE - if (exit_reason == EXIT_REASON_MSR_WRITE) - return kvm_emulate_wrmsr(vcpu); - else if (exit_reason == EXIT_REASON_PREEMPTION_TIMER) - return handle_preemption_timer(vcpu); - else if (exit_reason == EXIT_REASON_PENDING_INTERRUPT) - return handle_interrupt_window(vcpu); - else if (exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT) - return handle_external_interrupt(vcpu); - else if (exit_reason == EXIT_REASON_HLT) - return kvm_emulate_halt(vcpu); - else if (exit_reason == EXIT_REASON_EPT_MISCONFIG) - return handle_ept_misconfig(vcpu); + if (exit_reason == EXIT_REASON_MSR_WRITE) + return kvm_emulate_wrmsr(vcpu); + else if (exit_reason == EXIT_REASON_PREEMPTION_TIMER) + return handle_preemption_timer(vcpu); + else if (exit_reason == EXIT_REASON_PENDING_INTERRUPT) + return handle_interrupt_window(vcpu); + else if (exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT) + return handle_external_interrupt(vcpu); + else if (exit_reason == EXIT_REASON_HLT) + return kvm_emulate_halt(vcpu); + else if (exit_reason == EXIT_REASON_EPT_MISCONFIG) + return handle_ept_misconfig(vcpu); #endif - return kvm_vmx_exit_handlers[exit_reason](vcpu); - } else { - vcpu_unimpl(vcpu, "vmx: unexpected exit reason 0x%x\n", - exit_reason); - dump_vmcs(); - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; - vcpu->run->internal.suberror = + + exit_reason = array_index_nospec(exit_reason, + kvm_vmx_max_exit_handlers); + if (!kvm_vmx_exit_handlers[exit_reason]) + goto unexpected_vmexit; + + return kvm_vmx_exit_handlers[exit_reason](vcpu); + +unexpected_vmexit: + vcpu_unimpl(vcpu, "vmx: unexpected exit reason 0x%x\n", exit_reason); + dump_vmcs(); + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; + vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON; - vcpu->run->internal.ndata = 1; - vcpu->run->internal.data[0] = exit_reason; - return 0; - } + vcpu->run->internal.ndata = 1; + vcpu->run->internal.data[0] = exit_reason; + return 0; } /* -- 2.20.1