From: Jan Beulich Date: Tue, 12 Jun 2012 10:33:40 +0000 (+0100) Subject: x86_64: Do not execute sysret with a non-canonical return address X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~8322 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=6b091fa4457c6768c7fc505e2a42a5f32b83bc8d;p=xen.git x86_64: Do not execute sysret with a non-canonical return address Check for non-canonical guest RIP before attempting to execute sysret. If sysret is executed with a non-canonical value in RCX, Intel CPUs take the fault in ring0, but we will necessarily already have switched to the the user's stack pointer. This is a security vulnerability, XSA-7 / CVE-2012-0217. Signed-off-by: Jan Beulich Signed-off-by: Ian Campbell Signed-off-by: Ian Jackson Tested-by: Ian Campbell Acked-by: Keir Fraser Committed-by: Ian Jackson --- diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S index 3836260b9a..3204479503 100644 --- a/xen/arch/x86/x86_64/entry.S +++ b/xen/arch/x86/x86_64/entry.S @@ -40,6 +40,13 @@ restore_all_guest: testw $TRAP_syscall,4(%rsp) jz iret_exit_to_guest + /* Don't use SYSRET path if the return address is not canonical. */ + movq 8(%rsp),%rcx + sarq $47,%rcx + incl %ecx + cmpl $1,%ecx + ja .Lforce_iret + addq $8,%rsp popq %rcx # RIP popq %r11 # CS @@ -50,6 +57,10 @@ restore_all_guest: sysretq 1: sysretl +.Lforce_iret: + /* Mimic SYSRET behavior. */ + movq 8(%rsp),%rcx # RIP + movq 24(%rsp),%r11 # RFLAGS ALIGN /* No special register assumptions. */ iret_exit_to_guest: