From: Sean Christopherson <seanjc@google.com>
To: Michal Luczaj <mhal@rbox.co>
Cc: pbonzini@redhat.com, kvm@vger.kernel.org, shuah@kernel.org
Subject: Re: [PATCH 0/2] sync_regs() TOCTOU issues
Date: Tue, 15 Aug 2023 11:15:39 -0700 [thread overview]
Message-ID: <ZNvAy4lsMsSeuvgq@google.com> (raw)
In-Reply-To: <428bed16-f407-4e90-9bbe-e3eaa8b5fdec@rbox.co>
On Tue, Aug 15, 2023, Michal Luczaj wrote:
> On 8/15/23 17:40, Sean Christopherson wrote:
> > On Tue, Aug 15, 2023, Michal Luczaj wrote:
> >>> @@ -115,6 +116,7 @@ static void *race_events_exc(void *arg)
> >>> for (;;) {
> >>> WRITE_ONCE(run->kvm_dirty_regs, KVM_SYNC_X86_EVENTS);
> >>> WRITE_ONCE(events->flags, 0);
> >>> + WRITE_ONCE(events->exception.nr, GP_VECTOR);
> >>> WRITE_ONCE(events->exception.pending, 1);
> >>> WRITE_ONCE(events->exception.nr, 255);
> >>
> >> Here you're setting events->exception.nr twice. Is it deliberate?
> >
> > Heh, yes and no. It's partly leftover from a brief attempt to gracefully eat the
> > fault in the guest.
> >
> > However, unless there's magic I'm missing, race_events_exc() needs to set a "good"
> > vector in every iteration, otherwise only the first iteration will be able to hit
> > the "check good, consume bad" scenario.
>
> I think I understand what you mean. I see things slightly different: because
>
> if (events->flags & KVM_VCPUEVENT_VALID_PAYLOAD) {
> ...
> } else {
> events->exception.pending = 0;
> events->exception_has_payload = 0;
> }
>
> zeroes exception.pending on every iteration, even though exception.nr may
> already be > 31, KVM does not necessary return -EINVAL at
>
> if ((events->exception.injected || events->exception.pending) &&
> (events->exception.nr > 31 || events->exception.nr == NMI_VECTOR))
> return -EINVAL;
>
> It would if the racer set exception.pending before this check, but if it does it
> after the check, then KVM goes
>
> vcpu->arch.exception.pending = events->exception.pending;
> vcpu->arch.exception.vector = events->exception.nr;
>
> which later triggers the WARN. That said, if I you think setting and re-setting
> exception.nr is more efficient (as in: racy), I'm all for it.
My goal isn't to make it easier to hit the *known* TOCTOU, it's to make the test
more valuable after that known bug has been fixed. I.e. I don't want to rely on
KVM to update kvm_run (which was arguably a bug even if there weren't a TOCTOU
issue). It's kinda silly, because realistically this test is likely only ever
going to find TOCTOU bugs, but so long as the test can consistently the known bug,
my preference is to make it as "generic" as possible from a coverage perspective.
next prev parent reply other threads:[~2023-08-15 18:16 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 0:12 [PATCH 0/2] sync_regs() TOCTOU issues Michal Luczaj
2023-07-28 0:12 ` [PATCH 1/2] KVM: x86: Fix KVM_CAP_SYNC_REGS's " Michal Luczaj
2023-07-31 23:49 ` Sean Christopherson
2023-08-01 12:37 ` Michal Luczaj
2023-08-02 19:18 ` Sean Christopherson
2023-08-03 0:13 ` Michal Luczaj
2023-08-03 17:48 ` Paolo Bonzini
2023-08-03 21:15 ` Michal Luczaj
2023-08-04 9:53 ` Paolo Bonzini
2023-08-04 17:50 ` Michal Luczaj
2023-08-14 22:29 ` Michal Luczaj
2023-07-28 0:12 ` [PATCH 2/2] KVM: selftests: Extend x86's sync_regs_test to check for races Michal Luczaj
2023-08-02 21:07 ` Sean Christopherson
2023-08-03 0:44 ` Michal Luczaj
2023-08-03 16:41 ` Sean Christopherson
2023-08-03 21:14 ` Michal Luczaj
2023-08-08 23:11 ` Sean Christopherson
2023-08-02 21:11 ` [PATCH 0/2] sync_regs() TOCTOU issues Sean Christopherson
2023-08-15 0:48 ` Sean Christopherson
2023-08-15 7:37 ` Michal Luczaj
2023-08-15 15:40 ` Sean Christopherson
2023-08-15 17:49 ` Michal Luczaj
2023-08-15 18:15 ` Sean Christopherson [this message]
2023-08-15 18:38 ` Michal Luczaj
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=ZNvAy4lsMsSeuvgq@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=mhal@rbox.co \
--cc=pbonzini@redhat.com \
--cc=shuah@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.