public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: "Radim Krčmář" <rkrcmar@redhat.com>,
	"KVM list" <kvm@vger.kernel.org>,
	"Steve Rutherford" <srutherford@google.com>
Subject: Re: How bad is KVM_EXIT_INTERNAL_ERROR?
Date: Thu, 22 Dec 2016 04:05:57 -0500 (EST)	[thread overview]
Message-ID: <1296104553.5042148.1482397557580.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <CACT4Y+a2zj0h+L+_75OEveXm0c4xnpUeLoTDkuUA16oyXgkCBg@mail.gmail.com>



----- Original Message -----
> From: "Dmitry Vyukov" <dvyukov@google.com>
> To: "Paolo Bonzini" <pbonzini@redhat.com>
> Cc: "Radim Krčmář" <rkrcmar@redhat.com>, "KVM list" <kvm@vger.kernel.org>, "Steve Rutherford"
> <srutherford@google.com>
> Sent: Wednesday, December 21, 2016 8:05:15 PM
> Subject: Re: How bad is KVM_EXIT_INTERNAL_ERROR?
> 
> On Wed, Dec 21, 2016 at 2:26 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> >
> >
> > On 21/12/2016 12:06, Dmitry Vyukov wrote:
> >> On Wed, Dec 21, 2016 at 12:00 PM, Paolo Bonzini <pbonzini@redhat.com>
> >> wrote:
> >>>
> >>>
> >>> On 21/12/2016 10:41, Dmitry Vyukov wrote:
> >>>> Hello,
> >>>>
> >>>> I am getting some KVM_EXIT_INTERNAL_ERROR/KVM_INTERNAL_ERROR_EMULATION
> >>>> while fuzzing KVM. Does it indicate a bug in kvm code?
> >>>
> >>> No, it just indicates something that isn't implemented.  Other
> >>> KVM_EXIT_INTERNAL_ERROR cases indicate a bug in the userspace code.
> >>
> >> Something is not implemented where? You mean host userspace (VMM)?
> >
> > No, in KVM's instruction emulator.
> 
> You mean that KVM_INTERNAL_ERROR_EMULATION means that something is not
> implemented in KVM's instruction emulator, right?
> 
> What about other error codes? You said that they indicate a bug in the
> userspace code. What userspace code?

For example setting processor state (KVM_SET_SREGS) to something that
makes no sense.

> > KVM_INTERNAL_ERROR_EMULATION only kills the whole VM at CPL=0.  At CPL=3
> > or in a nested VM it would be translated to an undefined opcode
> > exception, exactly for this reason.
> >
> > Feel free to send one or two examples, they should be easy to analyze.
> > But I suspect it's just a combination of executing garbage instructions
> > with garbage processor state.  If so, an unprivileged guest that can
> > trigger KVM_INTERNAL_ERROR_EMULATION in a kernel most likely has gotten
> > arbitrary code execution already.
> 
> What's the simplest way to verify that the error was triggered by
> CPL=0 code? Do KVM_GET_SREGS and check value code segment?

CPL is actually SS.DPL, so that's what you would have to check.  But
really the only case of KVM_INTERNAL_ERROR_EMULATION that fuzzing can
produce is probably this one:

        if (!is_guest_mode(vcpu) && kvm_x86_ops->get_cpl(vcpu) == 0) {
                vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
                vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
                vcpu->run->internal.ndata = 0;
                r = EMULATE_FAIL;
        }
        kvm_queue_exception(vcpu, UD_VECTOR);

There are other cases of KVM_INTERNAL_ERROR_EMULATION corresponding to
hardware task switching.  Neither Linux nor Windows provide userspace with
means to trigger those, but nested virtualization probably could on AMD.

Paolo

  reply	other threads:[~2016-12-22  9:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-21  9:41 How bad is KVM_EXIT_INTERNAL_ERROR? Dmitry Vyukov
2016-12-21 11:00 ` Paolo Bonzini
2016-12-21 11:06   ` Dmitry Vyukov
2016-12-21 13:26     ` Paolo Bonzini
2016-12-21 19:05       ` Dmitry Vyukov
2016-12-22  9:05         ` Paolo Bonzini [this message]
2016-12-22 10:44           ` Dmitry Vyukov

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=1296104553.5042148.1482397557580.JavaMail.zimbra@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=dvyukov@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=rkrcmar@redhat.com \
    --cc=srutherford@google.com \
    /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