From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Garnier Subject: [PATCH v1 2/2] x86/power/64: Fix __PAGE_OFFSET usage on restore Date: Mon, 1 Aug 2016 10:08:00 -0700 Message-ID: <1470071280-78706-3-git-send-email-thgarnie@google.com> References: <1470071280-78706-1-git-send-email-thgarnie@google.com> Return-path: In-Reply-To: <1470071280-78706-1-git-send-email-thgarnie@google.com> Sender: linux-kernel-owner@vger.kernel.org To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Kees Cook , Thomas Garnier , Yinghai Lu , "Rafael J . Wysocki" , Pavel Machek Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, kernel-hardening@lists.openwall.com List-Id: linux-pm@vger.kernel.org When KASLR memory randomization is used, __PAGE_OFFSET is a global variable changed during boot. The assembly code was using the variable as an immediate value to calculate the cr3 physical address. The physical address was incorrect resulting to a GP fault. Signed-off-by: Thomas Garnier --- arch/x86/power/hibernate_asm_64.S | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/power/hibernate_asm_64.S b/arch/x86/power/hibernate_asm_64.S index 8eee0e9..8db4905 100644 --- a/arch/x86/power/hibernate_asm_64.S +++ b/arch/x86/power/hibernate_asm_64.S @@ -23,6 +23,16 @@ #include #include +/* + * A global variable holds the page_offset when KASLR memory randomization + * is enabled. + */ +#ifdef CONFIG_RANDOMIZE_MEMORY +#define __PAGE_OFFSET_REF __PAGE_OFFSET +#else +#define __PAGE_OFFSET_REF $__PAGE_OFFSET +#endif + ENTRY(swsusp_arch_suspend) movq $saved_context, %rax movq %rsp, pt_regs_sp(%rax) @@ -72,7 +82,7 @@ ENTRY(restore_image) /* code below has been relocated to a safe page */ ENTRY(core_restore_code) /* switch to temporary page tables */ - movq $__PAGE_OFFSET, %rcx + movq __PAGE_OFFSET_REF, %rcx subq %rcx, %rax movq %rax, %cr3 /* flush TLB */ -- 2.8.0.rc3.226.g39d4020