From: Nadav Amit Date: Thu, 18 Sep 2014 19:39:43 +0000 (+0300) Subject: KVM: x86: emulating descriptor load misses long-mode case X-Git-Tag: v3.12.38~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9638450cced05855cbb366fc6dd0792375a6611;p=thirdparty%2Fkernel%2Fstable.git KVM: x86: emulating descriptor load misses long-mode case commit 040c8dc8a5afa7364bb8bb5b1b76c30007d6be14 upstream. In 64-bit mode a #GP should be delivered to the guest "if the code segment descriptor pointed to by the selector in the 64-bit gate doesn't have the L-bit set and the D-bit clear." - Intel SDM "Interrupt 13—General Protection Exception (#GP)". This patch fixes the behavior of CS loading emulation code. Although the comment says that segment loading is not supported in long mode, this function is executed in long mode, so the fix is necassary. Signed-off-by: Nadav Amit Signed-off-by: Paolo Bonzini Signed-off-by: Jiri Slaby --- diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 987fdb379df64..d28104924255d 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -1533,6 +1533,15 @@ static int load_segment_descriptor(struct x86_emulate_ctxt *ctxt, if (rpl > cpl || dpl != cpl) goto exception; } + /* in long-mode d/b must be clear if l is set */ + if (seg_desc.d && seg_desc.l) { + u64 efer = 0; + + ctxt->ops->get_msr(ctxt, MSR_EFER, &efer); + if (efer & EFER_LMA) + goto exception; + } + /* CS(RPL) <- CPL */ selector = (selector & 0xfffc) | cpl; break;