From: "Jan Beulich" Subject: [RFC] x86: possible problem with guest_walk_tables() Date: Mon, 21 Mar 2011 11:45:22 +0000 Message-ID: <4D87486202000078000377F1@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org The PSE handling doesn't check bits 1...8 (or 1...9 for non-PAE guests) being zero, thus allowing bad (not 2Mb/4Mb aligned) large pages to be handled (afaict potentially allowing the guest to access foreign memory). Below is a possible fix, but unfortunately it doesn't work for GUEST_PAGING_LEVELS =3D=3D 2, since _PAGE_INVALID_BITS is zero there. Would defining _PAGE_INVALID_BITS to any bit mask between 0x80000000 and 0xfffff000 there be in conflict with anything? Jan --- a/xen/arch/x86/mm/guest_walk.c +++ b/xen/arch/x86/mm/guest_walk.c @@ -231,9 +231,15 @@ guest_walk_tables(struct vcpu *v, struct /* _PAGE_PSE_PAT not set: remove _PAGE_PAT from flags. */ flags &=3D ~_PAGE_PAT; =20 +#define GUEST_L2_GFN_ALIGN (1 << (GUEST_L2_PAGETABLE_SHIFT - \ + GUEST_L1_PAGETABLE_SHIFT)) + if ( gfn_x(start) & (GUEST_L2_GFN_ALIGN - 1) & ~0x1 ) + rc |=3D _PAGE_INVALID_BITS; + /* Increment the pfn by the right number of 4k pages. =20 - * The ~0x1 is to mask out the PAT bit mentioned above. */ - start =3D _gfn((gfn_x(start) & ~0x1) + guest_l1_table_offset(va));= + * Mask out PAT and invalid bits. */ + start =3D _gfn((gfn_x(start) & ~(GUEST_L2_GFN_ALIGN - 1)) + + guest_l1_table_offset(va)); gw->l1e =3D guest_l1e_from_gfn(start, flags); gw->l1mfn =3D _mfn(INVALID_MFN); }=20