From: "Jan Beulich" Subject: [PATCH] x86-64: don't crash Xen upon direct pv guest access to GDT/LDT mapping area Date: Mon, 29 Nov 2010 11:15:48 +0000 Message-ID: <4CF399740200007800024A2B@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part28059A74.0__=" Return-path: 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 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. --=__Part28059A74.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline handle_gdt_ldt_mapping_fault() is intended to deal with indirect accesses (i.e. those caused by descriptor loads) to the GDT/LDT mapping area only. While for 32-bit segment limits indeed prevent the function being entered for direct accesses (i.e. a #GP fault will be raised even before the address translation gets done, on 64-bit even user mode accesses would lead to control reaching the BUG_ON() at the beginning of that function. Fortunately the fix is simple: Since the guest kernel runs in ring 3, any guest direct access will have the "user mode" bit set, whereas descriptor loads always do the translations to access the actual descriptors as kernel mode ones. Signed-off-by: Jan Beulich --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1236,7 +1236,7 @@ static int fixup_page_fault(unsigned lon =20 if ( unlikely(IN_HYPERVISOR_RANGE(addr)) ) { - if ( !(regs->error_code & PFEC_reserved_bit) && + if ( !(regs->error_code & (PFEC_user_mode | PFEC_reserved_bit)) = && (addr >=3D GDT_LDT_VIRT_START) && (addr < GDT_LDT_VIRT_END) = ) return handle_gdt_ldt_mapping_fault( addr - GDT_LDT_VIRT_START, regs); --=__Part28059A74.0__= Content-Type: text/plain; name="x86_64-gdt-ldt-fault-filter.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86_64-gdt-ldt-fault-filter.patch" handle_gdt_ldt_mapping_fault() is intended to deal with indirect=0Aaccesses= (i.e. those caused by descriptor loads) to the GDT/LDT=0Amapping area = only. While for 32-bit segment limits indeed prevent the=0Afunction being = entered for direct accesses (i.e. a #GP fault will be=0Araised even before = the address translation gets done, on 64-bit even=0Auser mode accesses = would lead to control reaching the BUG_ON() at the=0Abeginning of that = function.=0A=0AFortunately the fix is simple: Since the guest kernel runs = in ring 3,=0Aany guest direct access will have the "user mode" bit set, = whereas=0Adescriptor loads always do the translations to access the = actual=0Adescriptors as kernel mode ones.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/x86/traps.c=0A+++ b/xen/arch/x86/= traps.c=0A@@ -1236,7 +1236,7 @@ static int fixup_page_fault(unsigned = lon=0A =0A if ( unlikely(IN_HYPERVISOR_RANGE(addr)) )=0A {=0A- = if ( !(regs->error_code & PFEC_reserved_bit) &&=0A+ if ( = !(regs->error_code & (PFEC_user_mode | PFEC_reserved_bit)) &&=0A = (addr >=3D GDT_LDT_VIRT_START) && (addr < GDT_LDT_VIRT_END) )=0A = return handle_gdt_ldt_mapping_fault(=0A addr - = GDT_LDT_VIRT_START, regs);=0A --=__Part28059A74.0__= 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.xensource.com http://lists.xensource.com/xen-devel --=__Part28059A74.0__=--