From: Sean Christopherson <seanjc@google.com>
To: Thomas Prescher <thomas.prescher@cyberus-technology.de>
Cc: Julian Stecklina <julian.stecklina@cyberus-technology.de>,
"x86@kernel.org" <x86@kernel.org>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"hpa@zytor.com" <hpa@zytor.com>,
"mingo@redhat.com" <mingo@redhat.com>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"bp@alien8.de" <bp@alien8.de>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] KVM: nVMX: fix CR4_READ_SHADOW when L0 updates CR4 during a signal
Date: Tue, 16 Apr 2024 08:17:40 -0700 [thread overview]
Message-ID: <Zh6WlOB8CS-By3DQ@google.com> (raw)
In-Reply-To: <ecb314c53c76bc6d2233a8b4d783a15297198ef8.camel@cyberus-technology.de>
On Tue, Apr 16, 2024, Thomas Prescher wrote:
> Hi Sean,
>
> On Tue, 2024-04-16 at 07:35 -0700, Sean Christopherson wrote:
> > On Tue, Apr 16, 2024, Julian Stecklina wrote:
> > > From: Thomas Prescher <thomas.prescher@cyberus-technology.de>
> > >
> > > This issue occurs when the kernel is interrupted by a signal while
> > > running a L2 guest. If the signal is meant to be delivered to the L0 VMM,
> > > and L0 updates CR4 for L1, i.e. when the VMM sets KVM_SYNC_X86_SREGS in
> > > kvm_run->kvm_dirty_regs, the kernel programs an incorrect read shadow
> > > value for L2's CR4.
> > >
> > > The result is that the guest can read a value for CR4 where bits from L1
> > > have leaked into L2.
> >
> > No, this is a userspace bug. If L2 is active when userspace stuffs
> > register state, then from KVM's perspective the incoming value is L2's
> > value. E.g. if userspace *wants* to update L2 CR4 for whatever reason,
> > this patch would result in L2 getting a stale value, i.e. the value of CR4
> > at the time of VM-Enter.
> >
> > And even if userspace wants to change L1, this patch is wrong, as KVM is
> > writing vmcs02.GUEST_CR4, i.e. is clobbering the L2 CR4 that was programmed
> > by L1, *and* is dropping the CR4 value that userspace wanted to stuff for
> > L1.
> >
> > To fix this, your userspace needs to either wait until L2 isn't active, or
> > force the vCPU out of L2 (which isn't easy, but it's doable if absolutely
> > necessary).
>
> What you say makes sense. Is there any way for
> userspace to detect whether L2 is currently active after
> returning from KVM_RUN? I couldn't find anything in the official
> documentation https://docs.kernel.org/virt/kvm/api.html
>
> Can you point me into the right direction?
Hmm, the only way to query that information is via KVM_GET_NESTED_STATE, which is
a bit unfortunate as that is a fairly "heavy" ioctl().
next prev parent reply other threads:[~2024-04-16 15:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-16 12:35 [PATCH 1/2] KVM: nVMX: fix CR4_READ_SHADOW when L0 updates CR4 during a signal Julian Stecklina
2024-04-16 12:35 ` [PATCH 2/2] KVM: nVMX: remove unnecessary CR4_READ_SHADOW write Julian Stecklina
2024-04-16 14:35 ` [PATCH 1/2] KVM: nVMX: fix CR4_READ_SHADOW when L0 updates CR4 during a signal Sean Christopherson
2024-04-16 15:08 ` Thomas Prescher
2024-04-16 15:17 ` Sean Christopherson [this message]
2024-04-16 17:31 ` Thomas Prescher
2024-04-16 18:07 ` Sean Christopherson
2024-04-17 13:05 ` Thomas Prescher
2024-04-17 16:11 ` Sean Christopherson
2024-04-17 16:28 ` Sean Christopherson
2024-04-18 13:48 ` Thomas Prescher
2024-04-18 18:28 ` Sean Christopherson
2024-05-08 13:27 ` Thomas Prescher
2024-04-18 13:46 ` Thomas Prescher
2024-04-18 18:36 ` 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=Zh6WlOB8CS-By3DQ@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=julian.stecklina@cyberus-technology.de \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=thomas.prescher@cyberus-technology.de \
--cc=x86@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