Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1109834ybl; Thu, 12 Dec 2019 09:46:13 -0800 (PST) X-Google-Smtp-Source: APXvYqyDLd6GbaSTNH/OX2GHnGo7cwwcjdnL3TNP88esD+lUMkG7G86w4jvfMRfYO5QDETOe8cnR X-Received: by 2002:aca:7244:: with SMTP id p65mr5524480oic.50.1576172773195; Thu, 12 Dec 2019 09:46:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576172773; cv=none; d=google.com; s=arc-20160816; b=OFT03ADdy+xno93Kp0GCqboNadEUg9JCxB9fAXLNxPYCUAuljV4Mebzw/eIynbLrLv RD7VfmNUhVs39rvomMN/yhw+mbUwGsyp1XqIuW+gmzCkf8xiQdMZ+E0A0V35u93/eg24 J/7OrppClef7OjYyyDkcZpWYuIzFDD5MUxDze6qzsCXviQ5/rnoQgWaF14AA2DzB3ayG lrtwrregqLulPrZSfWGwp3Fs1JRR6+PteH2gakzVNLhfrUUCqPwAxyVoOvkVKZx2H205 tGkYgjIG+NUsUUFy1gy0Jmg3rxYNqEY0tLTbyWLa0pOuSaybVhFEnnKwuwSwyCUyMeJs k2/A== 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=NZUkuLltWHAaMt9PiF7re5SLQkc/j51hQPwRCUKb9Mw=; b=WaIuQktL4cNtT8akZLQeXMrcX6ajMsxeZuVZSf+UyfuO7y5J/OmB6DN79r3vdZ8Nwg vk8PSR4yvKxjUIf7uviygGpJAQjS0U8ENTj7MP9HcJqx4kIY3VAjRgh2IobU9IJsN8NJ sAEOdRFVe4W8OP2KO7RPaTiq47tLe1M/2y7MPOkKF1R9xu47ZV7pDQh1miTVS323AOK3 N13XKRlxBqmZ0ywI0Nf0X10BJgDhZd7N6fCSV4CpOb7pPXNc97gtxs+ovfSvUjfVStjw iTH8rNNCuFU6tUmZc6USoWsGY3cc2IXGgeWDBsK7oaV8d6QZBAt5RKlc1x0KNB4++6qs 8xVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Zcvq/j0d"; 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 h9si3383925oia.97.2019.12.12.09.45.59; Thu, 12 Dec 2019 09:46:13 -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="Zcvq/j0d"; 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 S1730265AbfLLRot (ORCPT + 99 others); Thu, 12 Dec 2019 12:44:49 -0500 Received: from mail-io1-f65.google.com ([209.85.166.65]:45251 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730108AbfLLRos (ORCPT ); Thu, 12 Dec 2019 12:44:48 -0500 Received: by mail-io1-f65.google.com with SMTP id i11so3652057ioi.12 for ; Thu, 12 Dec 2019 09:44:48 -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=NZUkuLltWHAaMt9PiF7re5SLQkc/j51hQPwRCUKb9Mw=; b=Zcvq/j0dfcg82cX+jYcHpmIcVtvtDsWFmkRO4oumpHMJBzVvRQUTs/a+SdZiryhxTt 0zzz71YUxyr6JKp3Riotyq8Nacg2OvjaTqLG9Xqfu8ia62nzd/Ez5/pkR3q4gWDBR7Tp MuspoypVdYRvucBFx3gOeBzKWoabO1APnY27Go0vENPxdx97lvA1Zgo/hY0hCMr4DvbY gE4cuFY4cECLbNUHNggMwvoACSoA/V5htVau63pTIHbubNesuuoU3LRh/Of0K3M089hd /NTiWoftyfnBxI2qXB9ksSS6YIk1Y2idkO86qwlw55yX03BbTg0sUea3Q/llueiJXMZD cqaA== 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=NZUkuLltWHAaMt9PiF7re5SLQkc/j51hQPwRCUKb9Mw=; b=VFJo4aqEXTMS6BOXveQ0aYw9gUpDqoOkm1ot1yhrQYz67EUDsM23nAr2ofoSXPyUfb K0iruVWXKQu19iPJFGM3TMfbV5tYRhdwIQQoPMYck/RntVUch2xTd/ihOKJOt9KDeoG2 R8dAe4NMzzCPb7vCxJeLyj1d0OWepXMD4dXJ8Nd8bcWMd913A+wFs7HbyHVrgbGQl3dO +UalS95+sSarY1tuVg0qFF1LLiwJ5Pk2Wy+UI8OfTKJbQWEH8O9F7vvizgEUhw7Nz7hq uQhXvIkVmbFwf8rMHOof3+QzF68Qs3GnfUOBArru80Tnbraq3xUikE05G+fOJ9u491HQ w92g== X-Gm-Message-State: APjAAAU+5vjqKSeQnlUImy5YMcVIWYiP4V2gm/xhMTYPmgoLwxSi1NKN q2qr2PACwAsF0V3dSpv8umPnllh/Id5Cz3eK0pq2ZQ== X-Received: by 2002:a5d:8cda:: with SMTP id k26mr4127162iot.26.1576172687645; Thu, 12 Dec 2019 09:44:47 -0800 (PST) MIME-Version: 1.0 References: <20191211204753.242298-1-pomonis@google.com> <20191211204753.242298-3-pomonis@google.com> <314f6d96-b75f-e159-d94d-1d30a5140e40@de.ibm.com> In-Reply-To: <314f6d96-b75f-e159-d94d-1d30a5140e40@de.ibm.com> From: Jim Mattson Date: Thu, 12 Dec 2019 09:44:36 -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: Christian Borntraeger Cc: Marios Pomonis , Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "the arch/x86 maintainers" , kvm list , LKML , Nick Finco , Andrew Honig , stable@vger.kernel.org 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 9:31 AM Christian Borntraeger wrote: > > > > On 11.12.19 21:47, Marios Pomonis wrote: > > 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: 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; > > The fact that we do a WARN_ON_ONCE here, should actually tell that index is not > user controllable. Otherwise this would indicate the possibility to trigger a > kernel warning from a malicious user space. So > a: we do not need this change > or > b: we must also fix the WARN_ON_ONCE That isn't quite true. The issue is *speculative* execution down this path. The call site does constrain the *actual* value of index: case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4: return kvm_hv_msr_get_crash_data(...); However, it is possible to train the branch predictor to go down this path using valid indices and subsequently pass what would be an invalid index. The CPU will speculatively follow this path and may pull interesting data into the cache before it realizes its mistake and corrects.