Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp7050ybe; Thu, 12 Sep 2019 14:34:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxG/ZFf2V4i/A/L+yjVjviTeor9g2AEzVBUMEdwnrMieZyYmrcKhUohr/+jGkT3h0fBeaAB X-Received: by 2002:a17:906:3406:: with SMTP id c6mr36493760ejb.89.1568324041605; Thu, 12 Sep 2019 14:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568324041; cv=none; d=google.com; s=arc-20160816; b=d8zSSud6JEOaDxRQMQ4nHTVQkuuZjNaIdFJj8/aT/61p7ZsenWsulB+0BQs4jfOKLb ARjLrNhNl/2rOXJgyL6jqAhmx2XhAwEfXmghVow9luvqrEhYmwoChuh8W5xrM/X2Z4A9 qFbg/6f2xCIs8GgZPJg1bWgTvM2HwNFbsGPi+P2x055B+KL1hQUcXkPre+Nj1ccu7ec2 ussLV11I3jiEozGhoqGdGfgFQxinq8HAezjZ+6fDZ1gT3zXzWZYUjWwRMC22XYrYD0wm C9Q1FDFryVx0RUZXzHt4issxU7s6LGSfB0bju2m8VIDTlX2g7A7zy1mIMvphlsmPHOPW s6+w== 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=RhA03o75OD+ZBFEfqmjtglWrooCHou7fbqnvxWxZk30=; b=ryorb1UrDiCJT9FeI0G4aW1FYdnexyT4B3uTGaeYJz9Y7HegHdUCwr6QClfmHeVQXz Nm6ZZvyAPzGTsMY/sXuJCwVxzmAwvXchIRyPwKvUXIeZOLtLDQltrpL9IQaOB8Z3IkM+ b/Eis1M4PJxGMMMhF5JihxDHARHvKAAOQ7tLZdppKEyPWjrzJ8RUEH8O5f9r1o4/nvo4 EDhw90ppuD2qFMQooMS2m5lwSU/7PvHYcLug3qd842V5iwKQknI2cUr3Mj3Ve9eX8vRl +DmbKHZmHHL4NwGzVuta1PPxhxWLQSWKrXUeHO3rvX2gKFyjXG6mxYnIyuysgsd/fS0D lvHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mMbKQJiQ; 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 y17si9948474edt.101.2019.09.12.14.33.37; Thu, 12 Sep 2019 14:34:01 -0700 (PDT) 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=mMbKQJiQ; 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 S1732694AbfILQUO (ORCPT + 99 others); Thu, 12 Sep 2019 12:20:14 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:39433 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725972AbfILQUO (ORCPT ); Thu, 12 Sep 2019 12:20:14 -0400 Received: by mail-io1-f68.google.com with SMTP id d25so56181968iob.6 for ; Thu, 12 Sep 2019 09:20:13 -0700 (PDT) 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=RhA03o75OD+ZBFEfqmjtglWrooCHou7fbqnvxWxZk30=; b=mMbKQJiQ8dHwiBHDUMZjEOtXWB+eG6G3k5OhltVLFE3NeUONbujHOlTYC9H+xlzRmb ZiuOllEOLE8EqHWvTbcAWitUK4ulO+qlQiZ0htati68Ioj90GRTmIL+402eQdfJbIlQQ frp8KRMon+iiuSVOyvlX91bjMR2pJyJ5YX74FIY+dismzjklDKJZO4NctWV/JHsn0o8+ 0FxAlxm+s0Cn6gEcfC3zTdxtK9+gRgQL+6Wm7ZW1vRuFzH5cSiejaflP7J5TZzuX/tmE X5/t2LU4tLYCOxubUz68dAl/XyV1EYCekSLyyEPbkVBzYuXzU+dygA4xEm0URPuvILmq mGAQ== 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=RhA03o75OD+ZBFEfqmjtglWrooCHou7fbqnvxWxZk30=; b=ktEXsD3+df5fOyj/2XaSTjgN7SMAK0n5PevJL/vkeZTRTxfY/dXlSr1kq8rxYWA5tE I9NZf9u9Bi6DhHHPghRZD5IaRj/h7SupucDbIfeBVhYnNS1La8h61M+TDYxcPX1+UW3Z L3V2eIsYCtCqHToMsoIFGD4UiKqu9rRDeyV103+ga1MGxqWg27ODSGzaoqESvAKmThwL JcFvyiCDXRnF4AUt33MU+Q1JNqlZVTQ4kTPe0lEmwZT8uKwcrrM9Yn518I3Jlsn3umlE rxQxVeYAFqLgDby3PGHY2rdcjRv/kclW1bo//bxLUFihoMEaCqZkbHEiKWKT7wsL2PsW WhEw== X-Gm-Message-State: APjAAAVRekx/iApkqKdbAMEzfMRvNBllJz+0pRo8HSMCkAKO747tXmv3 lCRnyio17Rv+2EbfB1pJcQFqKKy+nDYqjjRqmEt4EA== X-Received: by 2002:a6b:1606:: with SMTP id 6mr471368iow.108.1568305213072; Thu, 12 Sep 2019 09:20:13 -0700 (PDT) MIME-Version: 1.0 References: <20190912041817.23984-1-huangfq.daxian@gmail.com> <87tv9hew2k.fsf@vitty.brq.redhat.com> In-Reply-To: <87tv9hew2k.fsf@vitty.brq.redhat.com> From: Jim Mattson Date: Thu, 12 Sep 2019 09:20:01 -0700 Message-ID: Subject: Re: [PATCH] KVM: x86: work around leak of uninitialized stack contents To: Vitaly Kuznetsov Cc: Fuqian Huang , Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Sean Christopherson , Wanpeng Li , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , "the arch/x86 maintainers" , kvm list , LKML 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, Sep 12, 2019 at 1:51 AM Vitaly Kuznetsov wrote: > > Fuqian Huang writes: > > > Emulation of VMPTRST can incorrectly inject a page fault > > when passed an operand that points to an MMIO address. > > The page fault will use uninitialized kernel stack memory > > as the CR2 and error code. > > > > The right behavior would be to abort the VM with a KVM_EXIT_INTERNAL_ERROR > > exit to userspace; > > Hm, why so? KVM_EXIT_INTERNAL_ERROR is basically an error in KVM, this > is not a proper reaction to a userspace-induced condition (or ever). This *is* an error in KVM. KVM should properly emulate the quadword store to the emulated device. Doing anything else is just wrong. KVM_INTERNAL_ERROR is basically a cop-out for things that are hard. > I also looked at VMPTRST's description in Intel's manual and I can't > find and explicit limitation like "this must be normal memory". We're > just supposed to inject #PF "If a page fault occurs in accessing the > memory destination operand." > > In case it seems to be too cumbersome to handle VMPTRST to MMIO and we > think that nobody should be doing that I'd rather prefer injecting #GP. That is not the architected behavior at all. Now you're just making things up! > Please tell me what I'm missing :-) > > > however, it is not an easy fix, so for now just ensure > > that the error code and CR2 are zero. > > > > Signed-off-by: Fuqian Huang > > --- > > arch/x86/kvm/x86.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 290c3c3efb87..7f442d710858 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -5312,6 +5312,7 @@ int kvm_write_guest_virt_system(struct kvm_vcpu *vcpu, gva_t addr, void *val, > > /* kvm_write_guest_virt_system can pull in tons of pages. */ > > vcpu->arch.l1tf_flush_l1d = true; > > > > + memset(exception, 0, sizeof(*exception)); > > return kvm_write_guest_virt_helper(addr, val, bytes, vcpu, > > PFERR_WRITE_MASK, exception); > > } > > -- > Vitaly