public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: David Edmondson <dme@dme.org>
Cc: Aaron Lewis <aaronlewis@google.com>,
	Jim Mattson <jmattson@google.com>, kvm list <kvm@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] kvm: x86: Allow userspace to handle emulation errors
Date: Fri, 23 Apr 2021 17:37:53 +0000	[thread overview]
Message-ID: <YIMF8b2jD3b8IfPP@google.com> (raw)
In-Reply-To: <cunbla4ncdd.fsf@dme.org>

On Fri, Apr 23, 2021, David Edmondson wrote:
> On Friday, 2021-04-23 at 15:33:47 GMT, Sean Christopherson wrote:
> 
> > On Thu, Apr 22, 2021, David Edmondson wrote:
> >> Agreed. As Jim indicated in his other reply, there should be no new data
> >> leaked by not zeroing the bytes.
> >> 
> >> For now at least, this is not a performance critical path, so clearing
> >> the payload doesn't seem too onerous.
> >
> > I feel quite strongly that KVM should _not_ touch the unused bytes.
> 
> I'm fine with that, but...
> 
> > As Jim pointed out, a stream of 0x0 0x0 0x0 ... is not benign, it will
> > decode to one or more ADD instructions.  Arguably 0x90, 0xcc, or an
> > undending stream of prefixes would be more appropriate so that it's
> > less likely for userspace to decode a bogus instruction.
> 
> ...I don't understand this position. If the user-level instruction
> decoder starts interpreting bytes that the kernel did *not* indicate as
> valid (by setting insn_size to include them), it's broken.

Yes, so what's the point of clearing the unused bytes?  Doing so won't magically
fix a broken userspace.  That's why I argue that 0x90 or 0xcc would be more
appropriate; there's at least a non-zero chance that it will help userspace avoid
doing something completely broken.

On the other hand, userspace can guard against a broken _KVM_ by initializing
vcpu->run with a known pattern and logging if KVM exits to userspace with
seemingly bogus data.  Crushing the unused bytes to zero defeats userspace's
sanity check, e.g. if the actual memcpy() of the instruction bytes copies the
wrong number of bytes, then userspace's magic pattern will be lost and debugging
the KVM bug will be that much harder.

This is very much not a theoretical problem, I have debugged two separate KVM
bugs in the last few months where KVM completely failed to set
vcpu->run->exit_reason before exiting to userspace.  The exit_reason is a bit of
a special case because it's disturbingly easy for KVM to get confused over return
values and unintentionally exit to userspace, but it's not a big stretch to
imagine a bug where KVM provides incomplete data.

  reply	other threads:[~2021-04-23 17:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-21 12:28 [PATCH v2 1/2] kvm: x86: Allow userspace to handle emulation errors Aaron Lewis
2021-04-21 12:28 ` [PATCH v2 2/2] selftests: kvm: Allows " Aaron Lewis
2021-04-21 14:03 ` [PATCH v2 1/2] kvm: x86: Allow " David Edmondson
2021-04-21 16:24   ` Aaron Lewis
2021-04-21 17:10     ` David Edmondson
2021-04-21 19:01       ` Aaron Lewis
2021-04-22  8:07         ` David Edmondson
2021-04-23 15:33           ` Sean Christopherson
2021-04-23 17:23             ` David Edmondson
2021-04-23 17:37               ` Sean Christopherson [this message]
2021-04-23 17:55                 ` David Edmondson
2021-04-23 17:57                   ` Jim Mattson
2021-04-23 18:01                     ` Jim Mattson
2021-04-23 18:43                       ` Aaron Lewis
2021-04-22 12:57 ` Jim Mattson
2021-04-23  4:14   ` Aaron Lewis
2021-04-23 16:43     ` Jim Mattson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YIMF8b2jD3b8IfPP@google.com \
    --to=seanjc@google.com \
    --cc=aaronlewis@google.com \
    --cc=dme@dme.org \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox