kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: mlevitsk@redhat.com
To: Chao Gao <chao.gao@intel.com>
Cc: kvm@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>,
	Sean Christopherson <seanjc@google.com>,
	Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, Ingo Molnar <mingo@redhat.com>,
	 linux-kernel@vger.kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>
Subject: Re: [PATCH v4 3/4] x86: nVMX: check vmcs12->guest_ia32_debugctl value given by L2
Date: Fri, 16 May 2025 10:50:15 -0400	[thread overview]
Message-ID: <d9ea18ac1148c9596755c4df8548cdb8394f2ee0.camel@redhat.com> (raw)
In-Reply-To: <aCaxlS+juu1Rl7Mv@intel.com>

On Fri, 2025-05-16 at 11:31 +0800, Chao Gao wrote:
> On Wed, May 14, 2025 at 08:53:52PM -0400, Maxim Levitsky wrote:
> > Check the vmcs12 guest_ia32_debugctl value before loading it, to avoid L2
> > being able to load arbitrary values to hardware IA32_DEBUGCTL.
> > 
> > Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> > ---
> > arch/x86/kvm/vmx/nested.c | 4 ++++
> > arch/x86/kvm/vmx/vmx.c    | 2 +-
> > arch/x86/kvm/vmx/vmx.h    | 2 ++
> > 3 files changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> > index e073e3008b16..0bda6400e30a 100644
> > --- a/arch/x86/kvm/vmx/nested.c
> > +++ b/arch/x86/kvm/vmx/nested.c
> > @@ -3193,6 +3193,10 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu,
> > 	     CC((vmcs12->guest_bndcfgs & MSR_IA32_BNDCFGS_RSVD))))
> > 		return -EINVAL;
> > 
> > +	if ((vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS) &&
> > +	     CC(vmcs12->guest_ia32_debugctl & ~vmx_get_supported_debugctl(vcpu, false)))
> > +		return -EINVAL;
> > +
> 
> How about grouping this check with the one against DR7 a few lines above?

Good idea, will do.
> 
> > 	if (nested_check_guest_non_reg_state(vmcs12))
> > 		return -EINVAL;
> > 
> > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> > index 9953de0cb32a..9046ee2e9a04 100644
> > --- a/arch/x86/kvm/vmx/vmx.c
> > +++ b/arch/x86/kvm/vmx/vmx.c
> > @@ -2179,7 +2179,7 @@ static u64 nested_vmx_truncate_sysenter_addr(struct kvm_vcpu *vcpu,
> > 	return (unsigned long)data;
> > }
> > 
> > -static u64 vmx_get_supported_debugctl(struct kvm_vcpu *vcpu, bool host_initiated)
> > +u64 vmx_get_supported_debugctl(struct kvm_vcpu *vcpu, bool host_initiated)
> > {
> > 	u64 debugctl = 0;
> > 
> > diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
> > index 6d1e40ecc024..1b80479505d3 100644
> > --- a/arch/x86/kvm/vmx/vmx.h
> > +++ b/arch/x86/kvm/vmx/vmx.h
> > @@ -413,7 +413,9 @@ static inline void vmx_set_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr,
> > 		vmx_disable_intercept_for_msr(vcpu, msr, type);
> > }
> > 
> > +
> 
> stray newline.
> 
> > void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu);
> > +u64 vmx_get_supported_debugctl(struct kvm_vcpu *vcpu, bool host_initiated);
> > 
> > /*
> >  * Note, early Intel manuals have the write-low and read-high bitmap offsets
> > -- 
> > 2.46.0
> > 
> > 
> 

Best regards,
	Maxim Levitsky


  reply	other threads:[~2025-05-16 14:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-15  0:53 [PATCH v4 0/4] KVM: x86: allow DEBUGCTL.DEBUGCTLMSR_FREEZE_IN_SMM passthrough Maxim Levitsky
2025-05-15  0:53 ` [PATCH v4 1/4] KVM: x86: Convert vcpu_run()'s immediate exit param into a generic bitmap Maxim Levitsky
2025-05-15  0:53 ` [PATCH v4 2/4] KVM: x86: Drop kvm_x86_ops.set_dr6() in favor of a new KVM_RUN flag Maxim Levitsky
2025-05-16  6:49   ` Chao Gao
2025-05-16 13:07     ` Sean Christopherson
2025-05-15  0:53 ` [PATCH v4 3/4] x86: nVMX: check vmcs12->guest_ia32_debugctl value given by L2 Maxim Levitsky
2025-05-16  3:31   ` Chao Gao
2025-05-16 14:50     ` mlevitsk [this message]
2025-05-20 21:48       ` mlevitsk
2025-05-21  0:32         ` Chao Gao
2025-05-21 16:50           ` mlevitsk
2025-05-20 22:24   ` Sean Christopherson
2025-05-15  0:53 ` [PATCH v4 4/4] x86: KVM: VMX: preserve DEBUGCTLMSR_FREEZE_IN_SMM Maxim Levitsky
2025-05-16  3:39   ` Chao Gao
2025-05-16 14:49     ` mlevitsk
2025-05-20 22:57   ` Sean Christopherson
2025-05-21 20:43     ` mlevitsk

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=d9ea18ac1148c9596755c4df8548cdb8394f2ee0.camel@redhat.com \
    --to=mlevitsk@redhat.com \
    --cc=bp@alien8.de \
    --cc=chao.gao@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.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;
as well as URLs for NNTP newsgroup(s).