stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: VMX: mark unusable segment as nonpresent
@ 2013-06-28 10:17 Gleb Natapov
  2013-07-02  8:15 ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Gleb Natapov @ 2013-06-28 10:17 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, stable

Some userspaces do not preserve unusable property. Since usable
segment has to be present according to VMX spec we can use present
property to amend userspace bug by making unusable segment always
nonpresent. vmx_segment_access_rights() already marks nonpresent segment
as unusable.

Cc: stable@vger.kernel.org # 3.9+
Reported-by: Stefan Pietsch <stefan.pietsch@lsexperts.de>
Tested-by: Stefan Pietsch <stefan.pietsch@lsexperts.de>
Signed-off-by: Gleb Natapov <gleb@redhat.com>

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 260a919..5402c94 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3399,15 +3399,22 @@ static void vmx_get_segment(struct kvm_vcpu *vcpu,
 	var->limit = vmx_read_guest_seg_limit(vmx, seg);
 	var->selector = vmx_read_guest_seg_selector(vmx, seg);
 	ar = vmx_read_guest_seg_ar(vmx, seg);
+	var->unusable = (ar >> 16) & 1;
 	var->type = ar & 15;
 	var->s = (ar >> 4) & 1;
 	var->dpl = (ar >> 5) & 3;
-	var->present = (ar >> 7) & 1;
+	/*
+	 * Some userspaces do not preserve unusable property. Since usable
+	 * segment has to be present according to VMX spec we can use present
+	 * property to amend userspace bug by making unusable segment always
+	 * nonpresent. vmx_segment_access_rights() already marks nonpresent
+	 * segment as unusable.
+	 */
+	var->present = !var->unusable;
 	var->avl = (ar >> 12) & 1;
 	var->l = (ar >> 13) & 1;
 	var->db = (ar >> 14) & 1;
 	var->g = (ar >> 15) & 1;
-	var->unusable = (ar >> 16) & 1;
 }
 
 static u64 vmx_get_segment_base(struct kvm_vcpu *vcpu, int seg)
--
			Gleb.

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: VMX: mark unusable segment as nonpresent
  2013-06-28 10:17 [PATCH] KVM: VMX: mark unusable segment as nonpresent Gleb Natapov
@ 2013-07-02  8:15 ` Paolo Bonzini
  2013-07-02  8:18   ` Gleb Natapov
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2013-07-02  8:15 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: kvm, stable

Il 28/06/2013 12:17, Gleb Natapov ha scritto:
> Some userspaces do not preserve unusable property. Since usable
> segment has to be present according to VMX spec we can use present
> property to amend userspace bug by making unusable segment always
> nonpresent. vmx_segment_access_rights() already marks nonpresent segment
> as unusable.
> 
> Cc: stable@vger.kernel.org # 3.9+
> Reported-by: Stefan Pietsch <stefan.pietsch@lsexperts.de>
> Tested-by: Stefan Pietsch <stefan.pietsch@lsexperts.de>
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 260a919..5402c94 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -3399,15 +3399,22 @@ static void vmx_get_segment(struct kvm_vcpu *vcpu,
>  	var->limit = vmx_read_guest_seg_limit(vmx, seg);
>  	var->selector = vmx_read_guest_seg_selector(vmx, seg);
>  	ar = vmx_read_guest_seg_ar(vmx, seg);
> +	var->unusable = (ar >> 16) & 1;
>  	var->type = ar & 15;
>  	var->s = (ar >> 4) & 1;
>  	var->dpl = (ar >> 5) & 3;
> -	var->present = (ar >> 7) & 1;
> +	/*
> +	 * Some userspaces do not preserve unusable property. Since usable
> +	 * segment has to be present according to VMX spec we can use present
> +	 * property to amend userspace bug by making unusable segment always
> +	 * nonpresent. vmx_segment_access_rights() already marks nonpresent
> +	 * segment as unusable.
> +	 */
> +	var->present = !var->unusable;
>  	var->avl = (ar >> 12) & 1;
>  	var->l = (ar >> 13) & 1;
>  	var->db = (ar >> 14) & 1;
>  	var->g = (ar >> 15) & 1;
> -	var->unusable = (ar >> 16) & 1;
>  }
>  
>  static u64 vmx_get_segment_base(struct kvm_vcpu *vcpu, int seg)
> --
> 			Gleb.
> 

Looks good, but for now I'm leaving it out of the 3.11 pull request.
Applied to queue.

Paolo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: VMX: mark unusable segment as nonpresent
  2013-07-02  8:15 ` Paolo Bonzini
@ 2013-07-02  8:18   ` Gleb Natapov
  0 siblings, 0 replies; 3+ messages in thread
From: Gleb Natapov @ 2013-07-02  8:18 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, stable

On Tue, Jul 02, 2013 at 10:15:54AM +0200, Paolo Bonzini wrote:
> Il 28/06/2013 12:17, Gleb Natapov ha scritto:
> > Some userspaces do not preserve unusable property. Since usable
> > segment has to be present according to VMX spec we can use present
> > property to amend userspace bug by making unusable segment always
> > nonpresent. vmx_segment_access_rights() already marks nonpresent segment
> > as unusable.
> > 
> > Cc: stable@vger.kernel.org # 3.9+
> > Reported-by: Stefan Pietsch <stefan.pietsch@lsexperts.de>
> > Tested-by: Stefan Pietsch <stefan.pietsch@lsexperts.de>
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > 
> > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> > index 260a919..5402c94 100644
> > --- a/arch/x86/kvm/vmx.c
> > +++ b/arch/x86/kvm/vmx.c
> > @@ -3399,15 +3399,22 @@ static void vmx_get_segment(struct kvm_vcpu *vcpu,
> >  	var->limit = vmx_read_guest_seg_limit(vmx, seg);
> >  	var->selector = vmx_read_guest_seg_selector(vmx, seg);
> >  	ar = vmx_read_guest_seg_ar(vmx, seg);
> > +	var->unusable = (ar >> 16) & 1;
> >  	var->type = ar & 15;
> >  	var->s = (ar >> 4) & 1;
> >  	var->dpl = (ar >> 5) & 3;
> > -	var->present = (ar >> 7) & 1;
> > +	/*
> > +	 * Some userspaces do not preserve unusable property. Since usable
> > +	 * segment has to be present according to VMX spec we can use present
> > +	 * property to amend userspace bug by making unusable segment always
> > +	 * nonpresent. vmx_segment_access_rights() already marks nonpresent
> > +	 * segment as unusable.
> > +	 */
> > +	var->present = !var->unusable;
> >  	var->avl = (ar >> 12) & 1;
> >  	var->l = (ar >> 13) & 1;
> >  	var->db = (ar >> 14) & 1;
> >  	var->g = (ar >> 15) & 1;
> > -	var->unusable = (ar >> 16) & 1;
> >  }
> >  
> >  static u64 vmx_get_segment_base(struct kvm_vcpu *vcpu, int seg)
> > --
> > 			Gleb.
> > 
> 
> Looks good, but for now I'm leaving it out of the 3.11 pull request.
> Applied to queue.
> 
It affects people so lets target it to 3.10/3.9-stable.

--
			Gleb.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-07-02  8:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-28 10:17 [PATCH] KVM: VMX: mark unusable segment as nonpresent Gleb Natapov
2013-07-02  8:15 ` Paolo Bonzini
2013-07-02  8:18   ` Gleb Natapov

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).