Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3701427ybv; Mon, 10 Feb 2020 04:59:53 -0800 (PST) X-Google-Smtp-Source: APXvYqxUX7PF7M2TVGLhqhDuAxy8tuyRfb89VuIkV6m43+J90K9fNF3rwo8fEOzeejrXprGIaqjz X-Received: by 2002:a9d:1ca3:: with SMTP id l35mr945265ota.271.1581339593779; Mon, 10 Feb 2020 04:59:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339593; cv=none; d=google.com; s=arc-20160816; b=Rc9EJH5nQnBlu7fXmZSnSZSqMG83JAMNLe62WDEBYZtbtuSDm4gem43VemIppH2WQ1 3xy+eD54fGilcOAl/ucZkC2c1euN3saq8kcMD9jcbZtz/+uXjQwA5Pfr/OujMuVniAAm WPZFjinHF2Agd+yXZOmMmztbbJDg8+RwdHK7BQqO6lIePJaVbFR4j5QXc6Vvc7xLX9Lb ocAr325JpAKA9CNOBoj2HMYhX/f8eLifJJbLt7jfKAvup0ZGbLojABi32RtQ/HqJ1jaS CxO5vYtbTRKy27hNcRvyjRwEpoy15OZqvIN1QLiNlnFKUBV0aMy4we9R23gwwoVDJU7n 83/g== 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=543ITe53QzVIJIzDEjdFh7304OU449+8L5kDsxM4ZFk=; b=NYVS2O90tbXaNS/vWEOqTsjfJHP4feb6K7RFr8p//TT3kx2W8OfVrFQ/k5/9Gocxe9 DNGIujwcXO0ge4a19PDb5Kh2mzIlTMC4L4bqxa70NhXDCC9ygQSb1MvcZDiEyTROEz87 y8Op8Ev1Mv7ENNW8du4ago8Oi13ea54q/hDtuihGsf20C77DNCi8OXTFwfoB9GW0dPpQ 9VRSd+59tSlhyIjOmNZ2q8Gvd4vMMREXVQRGYKTg4Q2/H9uF/JhfLo+FG1Adr24eoJde l9jYFoxfMPfQOP9XRpy0SFCkZGwpmLQJI8td+AhweQmmGesd5yScZGBM9dhYUQNwWYSV F6ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="PN2pDhF/"; 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 f187si152722oia.218.2020.02.10.04.59.42; Mon, 10 Feb 2020 04:59:53 -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="PN2pDhF/"; 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 S1729737AbgBJM7h (ORCPT + 99 others); Mon, 10 Feb 2020 07:59:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:42750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729908AbgBJMlJ (ORCPT ); Mon, 10 Feb 2020 07:41:09 -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 5494020661; Mon, 10 Feb 2020 12:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338469; bh=Ly0IkmrgmVTdVI+OAkYsXZD7zF/l/VAyYRWTaSoG2EE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PN2pDhF/uvn8lmBzo8zK5uGOFKdRjzSKX0U9nqNtIEl52w7yhADAGniOw1LDiI4EL VX0Q601PsnO7T99vavJNhMHHVntcP3LEsPf0uapXp7WzDVdgL4MzG4celP6JHxe8J9 O7qDs2Fj27KMR7H1z++nfx+/RGVid0VgsVt0pS5g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nick Finco , Marios Pomonis , Andrew Honig , Paolo Bonzini Subject: [PATCH 5.5 232/367] KVM: x86: Protect kvm_hv_msr_[get|set]_crash_data() from Spectre-v1/L1TF attacks Date: Mon, 10 Feb 2020 04:32:25 -0800 Message-Id: <20200210122445.662471098@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 8618793750071d66028584a83ed0b4fa7eb4f607 upstream. This fixes Spectre-v1/L1TF vulnerabilities in kvm_hv_msr_get_crash_data() and kvm_hv_msr_set_crash_data(). These functions contain index computations that use the (attacker-controlled) MSR number. Fixes: e7d9513b60e8 ("kvm/x86: added hyper-v crash msrs into kvm hyperv context") Signed-off-by: Nick Finco Signed-off-by: Marios Pomonis Reviewed-by: Andrew Honig Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/hyperv.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -809,11 +809,12 @@ static int kvm_hv_msr_get_crash_data(str u32 index, u64 *pdata) { struct kvm_hv *hv = &vcpu->kvm->arch.hyperv; + size_t size = ARRAY_SIZE(hv->hv_crash_param); - if (WARN_ON_ONCE(index >= ARRAY_SIZE(hv->hv_crash_param))) + if (WARN_ON_ONCE(index >= size)) return -EINVAL; - *pdata = hv->hv_crash_param[index]; + *pdata = hv->hv_crash_param[array_index_nospec(index, size)]; return 0; } @@ -852,11 +853,12 @@ static int kvm_hv_msr_set_crash_data(str u32 index, u64 data) { struct kvm_hv *hv = &vcpu->kvm->arch.hyperv; + size_t size = ARRAY_SIZE(hv->hv_crash_param); - if (WARN_ON_ONCE(index >= ARRAY_SIZE(hv->hv_crash_param))) + if (WARN_ON_ONCE(index >= size)) return -EINVAL; - hv->hv_crash_param[index] = data; + hv->hv_crash_param[array_index_nospec(index, size)] = data; return 0; }