From: Alexander Graf <graf@amazon.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
<kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Yuan Yao <yaoyuan0329os@gmail.com>
Subject: Re: [PATCH 1/4] KVM: x86: Protect userspace MSR filter with SRCU, and set atomically-ish
Date: Wed, 17 Mar 2021 20:29:44 +0100 [thread overview]
Message-ID: <08ac1383-27d0-e5f9-a618-b9e43dc5dc12@amazon.com> (raw)
In-Reply-To: <20210316184436.2544875-2-seanjc@google.com>
On 16.03.21 19:44, Sean Christopherson wrote:
>
> Fix a plethora of issues with MSR filtering by installing the resulting
> filter as an atomic bundle instead of updating the live filter one range
> at a time. The KVM_X86_SET_MSR_FILTER ioctl() isn't truly atomic, as
> the hardware MSR bitmaps won't be updated until the next VM-Enter, but
> the relevant software struct is atomically updated, which is what KVM
> really needs.
>
> Similar to the approach used for modifying memslots, make arch.msr_filter
> a SRCU-protected pointer, do all the work configuring the new filter
> outside of kvm->lock, and then acquire kvm->lock only when the new filter
> has been vetted and created. That way vCPU readers either see the old
> filter or the new filter in their entirety, not some half-baked state.
>
> Yuan Yao pointed out a use-after-free in ksm_msr_allowed() due to a
> TOCTOU bug, but that's just the tip of the iceberg...
>
> - Nothing is __rcu annotated, making it nigh impossible to audit the
> code for correctness.
> - kvm_add_msr_filter() has an unpaired smp_wmb(). Violation of kernel
> coding style aside, the lack of a smb_rmb() anywhere casts all code
> into doubt.
> - kvm_clear_msr_filter() has a double free TOCTOU bug, as it grabs
> count before taking the lock.
> - kvm_clear_msr_filter() also has memory leak due to the same TOCTOU bug.
>
> The entire approach of updating the live filter is also flawed. While
> installing a new filter is inherently racy if vCPUs are running, fixing
> the above issues also makes it trivial to ensure certain behavior is
> deterministic, e.g. KVM can provide deterministic behavior for MSRs with
> identical settings in the old and new filters. An atomic update of the
> filter also prevents KVM from getting into a half-baked state, e.g. if
> installing a filter fails, the existing approach would leave the filter
> in a half-baked state, having already committed whatever bits of the
> filter were already processed.
>
> [*] https://lkml.kernel.org/r/20210312083157.25403-1-yaoyuan0329os@gmail.com
>
> Fixes: 1a155254ff93 ("KVM: x86: Introduce MSR filtering")
> Cc: stable@vger.kernel.org
> Cc: Alexander Graf <graf@amazon.com>
> Reported-by: Yuan Yao <yaoyuan0329os@gmail.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
Thanks a lot Sean for cleaning up after me! I was trying to be a bit too
smart with the inband count as token unfortunately :)
Reviewed-by: Alexander Graf <graf@amazon.com>
Alex
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
next prev parent reply other threads:[~2021-03-17 19:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-16 18:44 [PATCH 0/4] KVM: x86: MSR filtering and related fixes Sean Christopherson
2021-03-16 18:44 ` [PATCH 1/4] KVM: x86: Protect userspace MSR filter with SRCU, and set atomically-ish Sean Christopherson
2021-03-17 13:15 ` Paolo Bonzini
2021-03-17 19:29 ` Alexander Graf [this message]
2021-03-16 18:44 ` [PATCH 2/4] KVM: nVMX: Handle dynamic MSR intercept toggling Sean Christopherson
2021-03-17 13:17 ` Paolo Bonzini
2021-03-17 16:50 ` Sean Christopherson
2021-03-17 17:22 ` Paolo Bonzini
2021-03-17 17:24 ` Sean Christopherson
2021-03-17 20:04 ` Sean Christopherson
2021-03-16 18:44 ` [PATCH 3/4] KVM: VMX: Macrofy the MSR bitmap getters and setters Sean Christopherson
2021-03-17 13:15 ` Paolo Bonzini
2021-03-17 16:39 ` Sean Christopherson
2021-03-16 18:44 ` [PATCH 4/4] KVM: nVMX: Clean up x2APIC MSR handling for L2 Sean Christopherson
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=08ac1383-27d0-e5f9-a618-b9e43dc5dc12@amazon.com \
--to=graf@amazon.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=yaoyuan0329os@gmail.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