Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1071765ybl; Thu, 12 Dec 2019 09:12:22 -0800 (PST) X-Google-Smtp-Source: APXvYqzoVQaFtoQAYJ6odrI9jnbT5D91rnxwyeF9aymXhYSQAx+f+/e/oUBl6Eo/TjC+tCH+M+O/ X-Received: by 2002:aca:cc87:: with SMTP id c129mr5512362oig.13.1576170742197; Thu, 12 Dec 2019 09:12:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576170742; cv=none; d=google.com; s=arc-20160816; b=w6LQjFnD1qdN6OQZ0QQF0HNqvCaSgJVgwa8+kjkfUfuMAMovV6qlOB7kVLL5ipC9Hm B3LWJFfgaGZ6L1El12GH9S4j50h2ZW6c61TadXnW7JPQ6lDwwWcngNRSHq6khGNsBbyz tgGCc7mnBfsGrV9lclKEj0RswQ80rITwFz+qAK2APGTf29EMxrZ2AqRUQ5vIZPGyPjlm 2dziKDsyh7Cua+A6XBgyCRGHcBuKMhYW4T/5h1Tm9Q6hUMby4Hneo2qzSCRFF5GlhBPS okbT3k4B2SU2Vt123VlJ33UoPiMfe5XhNMczHwt2t/F304Cc+Wvd/w38Ef2ot48i6E3+ e+jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=O8i/P7PW2Hmf7if5w9WzMo01jNRINdPJBRjB9gK59EQ=; b=I7PifW4Aha7elguVUCzEU2ikG0wv7Gb72uJzz4OiLsyLF0Xqy5gLi3FF3EaECYbsMz MDkSfGFV6Hvbml951hkYVXmWkXR/cTgYbv7xImUjez5afR/ZAVRWFyULY/41YwhHwc3c TvGorBiS30Kjcn+BHMTZcDoORopOeySXZT6BagCzlCCQ74HVt3zmh8F+Lh2wpEhwQ1rt TFRqZAssSrCZ9VHLTtUaOzedch+kwU9Az2m2jZSVNpbB/4kUUnrquVoQDPy3WCaB62Al i2rE+i2JodmKt5WD3zO9xRlcYYOwUAkcTWiCthDI/WwgnlBPS/HpaddNu1tsE5/CxIU8 Qqqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KwSUHEkK; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o3si3261448oie.9.2019.12.12.09.11.55; Thu, 12 Dec 2019 09:12:22 -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=@google.com header.s=20161025 header.b=KwSUHEkK; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730051AbfLLRL0 (ORCPT + 99 others); Thu, 12 Dec 2019 12:11:26 -0500 Received: from mail-qv1-f68.google.com ([209.85.219.68]:33951 "EHLO mail-qv1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730014AbfLLRL0 (ORCPT ); Thu, 12 Dec 2019 12:11:26 -0500 Received: by mail-qv1-f68.google.com with SMTP id o18so1255897qvf.1 for ; Thu, 12 Dec 2019 09:11:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=O8i/P7PW2Hmf7if5w9WzMo01jNRINdPJBRjB9gK59EQ=; b=KwSUHEkKFnQJl6ziISrvsigGagqLvOmVERDG6DUYWMqZR+pR+SlGTc4CfEoM4oKLga 5znnUebLqUXbHjT5ebLhMIGPf5Rq4o1M2fI9H1eLh0llknAWtN2bOGIfcD9HkfGQTw/K It0FKvAouyzEKkl6ZmqP+ELrCB69SXBTK+T5sYtzPxGwIBPt9EH71nss5ZPd7+UwtSNG 1IpNsZnrk4f1B2KtLPOKkILRTAVLpOdV8vs8pYsGYJQ3aR1nHpiYppyu45qEfGZ83hxW M5QI2jQ3BhnLPS8nbx/NTKSKXakHPBAzSXWBqdjrhlW581Rdw0rvowt/bvyC7HHQz9zA BFKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=O8i/P7PW2Hmf7if5w9WzMo01jNRINdPJBRjB9gK59EQ=; b=a2oKHGmXY9sKUJ/x8En98kuccx06YosvzEKoQCBWSMFvET7bWUTmJnY/lIz1vFNz46 5SswFqXFGLvKMtGQhCYszhBu3PjlaOaSGJ5e4MzeNP0VwLOqkVbzKH099lRp45xjXCZc OmzibsowWZRgs1vJjF6bPlLx0XW9gBPsMs3xbJOsbDTN2Trz+Bf3SXyjav3Q4YajZ+1j U5XrjrThrQY68nQXPytq803RBzSXfLRy3Uk3WaniDI67/Hc0gWStuHphwBq1kpJnku2n SB4lPErvoGdZS1jgTPPgmDSXHkyNbCfXBSuPc7lDsPyCfSCXcBqyKLWAyedG8QPTOCZl YOkA== X-Gm-Message-State: APjAAAX4YlDHo3Uc+5U2zQNoxT1ncAlj05nFLS/g4RTBLqO2OcWXhIDo PxNK6Ld5d1dSReNTlPj8pmhoCmr0p7fnrrCXRankYg== X-Received: by 2002:ad4:4b08:: with SMTP id r8mr9321668qvw.250.1576170684921; Thu, 12 Dec 2019 09:11:24 -0800 (PST) MIME-Version: 1.0 References: <20191211204753.242298-1-pomonis@google.com> <20191211204753.242298-3-pomonis@google.com> <87eex9c20c.fsf@vitty.brq.redhat.com> In-Reply-To: <87eex9c20c.fsf@vitty.brq.redhat.com> From: Marios Pomonis Date: Thu, 12 Dec 2019 09:11:14 -0800 Message-ID: Subject: Re: [PATCH v2 02/13] KVM: x86: Protect kvm_hv_msr_[get|set]_crash_data() from Spectre-v1/L1TF attacks To: Vitaly Kuznetsov Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Nick Finco , Andrew Honig , stable@vger.kernel.org, Paolo Bonzini , rkrcmar@redhat.com, Sean Christopherson , Wanpeng Li , Jim Mattson , Joerg Roedel 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 On Thu, Dec 12, 2019 at 1:43 AM Vitaly Kuznetsov wrote: > > Marios Pomonis writes: > > > 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. > > Just to educate myself, > > in both cases 'index' is equal to 'msr - HV_X64_MSR_CRASH_P0' where > 'msr' is constrained: > case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4: > .... > > and moreover, kvm_hv_{get,set}_msr_common() is only being called for a > narrow set of MSRs. How can an atacker overcome these limitations? > This attack scenario relies on speculative execution. Practically, one could train the branch predictors involved to speculatively execute this path even if the adversary-supplied MSR number does not fall into the legitimate range. The adversary-supplied MSR number however is going to be used when -speculatively- computing the index of the array thus allowing an attacker to load normally illegitimate memory values in the L1 cache. > > > > Fixes: commit 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 > > --- > > arch/x86/kvm/hyperv.c | 10 ++++++---- > > 1 file changed, 6 insertions(+), 4 deletions(-) > > > > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > > index 23ff65504d7e..26408434b9bc 100644 > > --- a/arch/x86/kvm/hyperv.c > > +++ b/arch/x86/kvm/hyperv.c > > @@ -809,11 +809,12 @@ static int kvm_hv_msr_get_crash_data(struct kvm_vcpu *vcpu, > > 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(struct kvm_vcpu *vcpu, > > 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; > > } > > -- > Vitaly > -- Marios Pomonis Software Engineer, Security GCP Platform Security US-KIR-6THC