From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Kees Cook <keescook@chromium.org>,
Robert Dinse <nanook@eskimo.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v2 7/8] KVM: x86: Bug the VM if the emulator generates a bogus exception vector
Date: Wed, 01 Jun 2022 10:31:49 +0200 [thread overview]
Message-ID: <87leugokcq.fsf@redhat.com> (raw)
In-Reply-To: <20220526210817.3428868-8-seanjc@google.com>
Sean Christopherson <seanjc@google.com> writes:
> Bug the VM if KVM's emulator attempts to inject a bogus exception vector.
> The guest is likely doomed even if KVM continues on, and propagating a
> bad vector to the rest of KVM runs the risk of breaking other assumptions
> in KVM and thus triggering a more egregious bug.
>
> All existing users of emulate_exception() have hardcoded vector numbers
> (__load_segment_descriptor() uses a few different vectors, but they're
> all hardcoded), and future users are likely to follow suit, i.e. the
> change to emulate_exception() is a glorified nop.
>
> As for the ctxt->exception.vector check in x86_emulate_insn(), the few
> known times the WARN has been triggered in the past is when the field was
> not set when synthesizing a fault, i.e. for all intents and purposes the
> check protects against consumption of uninitialized data.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/kvm/emulate.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index 70a8e0cd9fdc..2aa17462a9ac 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -624,7 +624,9 @@ static unsigned long seg_base(struct x86_emulate_ctxt *ctxt, int seg)
> static int emulate_exception(struct x86_emulate_ctxt *ctxt, int vec,
> u32 error, bool valid)
> {
> - WARN_ON(vec > 0x1f);
> + if (KVM_EMULATOR_BUG_ON(vec > 0x1f, ctxt))
> + return X86EMUL_UNHANDLEABLE;
> +
> ctxt->exception.vector = vec;
> ctxt->exception.error_code = error;
> ctxt->exception.error_code_valid = valid;
> @@ -5728,7 +5730,8 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
>
> done:
> if (rc == X86EMUL_PROPAGATE_FAULT) {
> - WARN_ON(ctxt->exception.vector > 0x1f);
> + if (KVM_EMULATOR_BUG_ON(ctxt->exception.vector > 0x1f, ctxt))
> + return EMULATION_FAILED;
> ctxt->have_exception = true;
> }
> if (rc == X86EMUL_INTERCEPTED)
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
--
Vitaly
next prev parent reply other threads:[~2022-06-01 8:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-26 21:08 [PATCH v2 0/8] KVM: x86: Emulator _regs fixes and cleanups Sean Christopherson
2022-05-26 21:08 ` [PATCH v2 1/8] KVM: x86: Grab regs_dirty in local 'unsigned long' Sean Christopherson
2022-05-26 21:08 ` [PATCH v2 2/8] KVM: x86: Harden _regs accesses to guard against buggy input Sean Christopherson
2022-05-26 21:08 ` [PATCH v2 3/8] KVM: x86: Omit VCPU_REGS_RIP from emulator's _regs array Sean Christopherson
2022-05-31 18:04 ` Kees Cook
2022-05-26 21:08 ` [PATCH v2 4/8] KVM: x86: Use 16-bit fields to track dirty/valid emulator GPRs Sean Christopherson
2022-05-26 21:08 ` [PATCH v2 5/8] KVM: x86: Reduce the number of emulator GPRs to '8' for 32-bit KVM Sean Christopherson
2022-05-31 18:04 ` Kees Cook
2022-05-26 21:08 ` [PATCH v2 6/8] KVM: x86: Bug the VM if the emulator accesses a non-existent GPR Sean Christopherson
2022-05-31 18:06 ` Kees Cook
2022-06-01 8:29 ` Vitaly Kuznetsov
2022-06-02 16:01 ` Sean Christopherson
2022-05-26 21:08 ` [PATCH v2 7/8] KVM: x86: Bug the VM if the emulator generates a bogus exception vector Sean Christopherson
2022-05-31 18:06 ` Kees Cook
2022-06-01 8:31 ` Vitaly Kuznetsov [this message]
2022-05-26 21:08 ` [PATCH v2 8/8] KVM: x86: Bug the VM on an out-of-bounds data read Sean Christopherson
2022-05-31 18:06 ` Kees Cook
2022-06-01 8:39 ` Vitaly Kuznetsov
2022-05-26 23:14 ` [PATCH v2 0/8] KVM: x86: Emulator _regs fixes and cleanups Robert Dinse
2022-06-08 12:23 ` Paolo Bonzini
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=87leugokcq.fsf@redhat.com \
--to=vkuznets@redhat.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=keescook@chromium.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nanook@eskimo.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=wanpengli@tencent.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