From: "Jan Beulich" Subject: [PATCH v4 2/2] x86/hvm: clean up segment validation Date: Fri, 22 Nov 2013 14:21:18 +0000 Message-ID: <528F766E0200007800105E45@nat28.tlf.novell.com> References: <528DF45E.7050905@citrix.com> <20131121150355.GC89770@deinos.phlegethon.org> <528E219B.6060801@citrix.com> <20131121151308.GD89770@deinos.phlegethon.org> <20131121153231.GE89770@deinos.phlegethon.org> <528E5753.5020104@citrix.com> <528F53250200007800105C7C@nat28.tlf.novell.com> <20131122115453.GB86420@deinos.phlegethon.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part93A0434E.2__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Vjrbk-00064k-4w for xen-devel@lists.xenproject.org; Fri, 22 Nov 2013 14:21:20 +0000 In-Reply-To: <20131122115453.GB86420@deinos.phlegethon.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , keir@xen.org, David Binderman , Tim Deegan List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part93A0434E.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Use _SEGMENT_* instead of plain numbers where feasible. Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -2259,7 +2259,7 @@ static int hvm_load_segment_selector( desc =3D *pdesc; =20 /* Segment present in memory? */ - if ( !(desc.b & (1u<<15)) ) + if ( !(desc.b & _SEGMENT_P) ) { fault_type =3D TRAP_no_segment; goto unmap_and_fail; @@ -2277,7 +2277,7 @@ static int hvm_load_segment_selector( { case x86_seg_cs: /* Code segment? */ - if ( !(desc.b & (1u<<11)) ) + if ( !(desc.b & _SEGMENT_CODE) ) goto unmap_and_fail; /* Non-conforming segment: check DPL against RPL. */ if ( !(desc.b & _SEGMENT_EC) && (dpl !=3D rpl) ) @@ -2285,19 +2285,19 @@ static int hvm_load_segment_selector( break; case x86_seg_ss: /* Writable data segment? */ - if ( (desc.b & (5u<<9)) !=3D (1u<<9) ) + if ( (desc.b & (_SEGMENT_CODE|_SEGMENT_WR)) !=3D _SEGMENT_WR = ) goto unmap_and_fail; if ( (dpl !=3D cpl) || (dpl !=3D rpl) ) goto unmap_and_fail; break; case x86_seg_ldtr: /* LDT system segment? */ - if ( (desc.b & (15u<<8)) !=3D (2u<<8) ) + if ( (desc.b & _SEGMENT_TYPE) !=3D (2u<<8) ) goto unmap_and_fail; goto skip_accessed_flag; default: /* Readable code or data segment? */ - if ( (desc.b & (5u<<9)) =3D=3D (4u<<9) ) + if ( (desc.b & (_SEGMENT_CODE|_SEGMENT_WR)) =3D=3D _SEGMENT_CO= DE ) goto unmap_and_fail; /* * Data or non-conforming code segment: --=__Part93A0434E.2__= Content-Type: text/plain; name="x86-HVM-segment-validation-constants.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-HVM-segment-validation-constants.patch" x86/hvm: clean up segment validation=0A =0AUse _SEGMENT_* instead of = plain numbers where feasible.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/hvm/hvm.c=0A+++ b/xen/arch/x86/hvm/hvm.c=0A@= @ -2259,7 +2259,7 @@ static int hvm_load_segment_selector(=0A desc = =3D *pdesc;=0A =0A /* Segment present in memory? */=0A- if = ( !(desc.b & (1u<<15)) )=0A+ if ( !(desc.b & _SEGMENT_P) )=0A = {=0A fault_type =3D TRAP_no_segment;=0A goto = unmap_and_fail;=0A@@ -2277,7 +2277,7 @@ static int hvm_load_segment_selecto= r(=0A {=0A case x86_seg_cs:=0A /* Code = segment? */=0A- if ( !(desc.b & (1u<<11)) )=0A+ if ( = !(desc.b & _SEGMENT_CODE) )=0A goto unmap_and_fail;=0A = /* Non-conforming segment: check DPL against RPL. */=0A = if ( !(desc.b & _SEGMENT_EC) && (dpl !=3D rpl) )=0A@@ -2285,19 +2285,19 = @@ static int hvm_load_segment_selector(=0A break;=0A = case x86_seg_ss:=0A /* Writable data segment? */=0A- = if ( (desc.b & (5u<<9)) !=3D (1u<<9) )=0A+ if ( (desc.b & = (_SEGMENT_CODE|_SEGMENT_WR)) !=3D _SEGMENT_WR )=0A goto = unmap_and_fail;=0A if ( (dpl !=3D cpl) || (dpl !=3D rpl) )=0A = goto unmap_and_fail;=0A break;=0A case = x86_seg_ldtr:=0A /* LDT system segment? */=0A- if ( = (desc.b & (15u<<8)) !=3D (2u<<8) )=0A+ if ( (desc.b & _SEGMENT_T= YPE) !=3D (2u<<8) )=0A goto unmap_and_fail;=0A = goto skip_accessed_flag;=0A default:=0A /* Readable = code or data segment? */=0A- if ( (desc.b & (5u<<9)) =3D=3D = (4u<<9) )=0A+ if ( (desc.b & (_SEGMENT_CODE|_SEGMENT_WR)) = =3D=3D _SEGMENT_CODE )=0A goto unmap_and_fail;=0A = /*=0A * Data or non-conforming code segment:=0A --=__Part93A0434E.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part93A0434E.2__=--