From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: the arch/x86 maintainers <x86@kernel.org>,
Linux PM list <linux-pm@vger.kernel.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
Thomas Garnier <thgarnie@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
Kees Cook <keescook@chromium.org>,
Yinghai Lu <yinghai@kernel.org>, Pavel Machek <pavel@ucw.cz>,
LKML <linux-kernel@vger.kernel.org>,
kernel-hardening@lists.openwall.com
Subject: [PATCH] x86/power/64: Do not refer to __PAGE_OFFSET from assembly code
Date: Wed, 03 Aug 2016 01:19:26 +0200 [thread overview]
Message-ID: <2464745.UmGP58NeXC@vostro.rjw.lan> (raw)
In-Reply-To: <CAJZ5v0hiZwugdV6OjA7hAHAv5jhjgJM1vPAW-RHUHud0F=5KsQ@mail.gmail.com>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
When CONFIG_RANDOMIZE_MEMORY is set on x86-64, __PAGE_OFFSET becomes
a variable and using it as a symbol in the image memory restoration
assembly code under core_restore_code is not correct any more.
To avoid that problem, modify set_up_temporary_mappings() to compute
the physical address of the temporary page tables and store it in
temp_level4_pgt, so that the value of that variable is ready to be
written into CR3. Then, the assembly code doesn't have to worry
about converting that value into a physical address and things work
regardless of whether or not CONFIG_RANDOMIZE_MEMORY is set.
Reported-and-tested-by: Thomas Garnier <thgarnie@google.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
I'm going to queue this up, so if there are any objections/concerns about it,
please let me know ASAP.
Thanks,
Rafael
---
arch/x86/power/hibernate_64.c | 18 +++++++++---------
arch/x86/power/hibernate_asm_64.S | 2 --
2 files changed, 9 insertions(+), 11 deletions(-)
Index: linux-pm/arch/x86/power/hibernate_asm_64.S
===================================================================
--- linux-pm.orig/arch/x86/power/hibernate_asm_64.S
+++ linux-pm/arch/x86/power/hibernate_asm_64.S
@@ -72,8 +72,6 @@ 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
- subq %rcx, %rax
movq %rax, %cr3
/* flush TLB */
movq %rbx, %rcx
Index: linux-pm/arch/x86/power/hibernate_64.c
===================================================================
--- linux-pm.orig/arch/x86/power/hibernate_64.c
+++ linux-pm/arch/x86/power/hibernate_64.c
@@ -37,11 +37,11 @@ unsigned long jump_address_phys;
*/
unsigned long restore_cr3 __visible;
-pgd_t *temp_level4_pgt __visible;
+unsigned long temp_level4_pgt __visible;
unsigned long relocated_restore_code __visible;
-static int set_up_temporary_text_mapping(void)
+static int set_up_temporary_text_mapping(pgd_t *pgd)
{
pmd_t *pmd;
pud_t *pud;
@@ -71,7 +71,7 @@ static int set_up_temporary_text_mapping
__pmd((jump_address_phys & PMD_MASK) | __PAGE_KERNEL_LARGE_EXEC));
set_pud(pud + pud_index(restore_jump_address),
__pud(__pa(pmd) | _KERNPG_TABLE));
- set_pgd(temp_level4_pgt + pgd_index(restore_jump_address),
+ set_pgd(pgd + pgd_index(restore_jump_address),
__pgd(__pa(pud) | _KERNPG_TABLE));
return 0;
@@ -90,15 +90,16 @@ static int set_up_temporary_mappings(voi
.kernel_mapping = true,
};
unsigned long mstart, mend;
+ pgd_t *pgd;
int result;
int i;
- temp_level4_pgt = (pgd_t *)get_safe_page(GFP_ATOMIC);
- if (!temp_level4_pgt)
+ pgd = (pgd_t *)get_safe_page(GFP_ATOMIC);
+ if (!pgd)
return -ENOMEM;
/* Prepare a temporary mapping for the kernel text */
- result = set_up_temporary_text_mapping();
+ result = set_up_temporary_text_mapping(pgd);
if (result)
return result;
@@ -107,13 +108,12 @@ static int set_up_temporary_mappings(voi
mstart = pfn_mapped[i].start << PAGE_SHIFT;
mend = pfn_mapped[i].end << PAGE_SHIFT;
- result = kernel_ident_mapping_init(&info, temp_level4_pgt,
- mstart, mend);
-
+ result = kernel_ident_mapping_init(&info, pgd, mstart, mend);
if (result)
return result;
}
+ temp_level4_pgt = (unsigned long)pgd - __PAGE_OFFSET;
return 0;
}
next prev parent reply other threads:[~2016-08-02 23:14 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-01 17:07 [PATCH v1 0/2] x86/power/64: Make KASLR memory randomization compatible with hibernation Thomas Garnier
2016-08-01 17:07 ` [PATCH v1 1/2] x86/power/64: Support unaligned addresses for temporary mapping Thomas Garnier
2016-08-02 0:36 ` Rafael J. Wysocki
2016-08-02 18:01 ` Yinghai Lu
2016-08-02 17:36 ` Yinghai Lu
2016-08-02 17:48 ` Thomas Garnier
2016-08-02 19:55 ` Yinghai Lu
2016-08-03 15:29 ` Thomas Garnier
2016-08-03 18:23 ` [PATCH v2] " Yinghai Lu
2016-08-03 21:28 ` Rafael J. Wysocki
2016-08-07 1:03 ` Rafael J. Wysocki
2016-08-07 4:53 ` Yinghai Lu
2016-08-07 23:23 ` Rafael J. Wysocki
2016-08-08 7:06 ` Yinghai Lu
2016-08-08 7:23 ` Yinghai Lu
2016-08-08 13:16 ` Rafael J. Wysocki
2016-08-01 17:08 ` [PATCH v1 2/2] x86/power/64: Fix __PAGE_OFFSET usage on restore Thomas Garnier
2016-08-02 0:38 ` Rafael J. Wysocki
2016-08-02 14:34 ` Thomas Garnier
2016-08-02 20:47 ` Rafael J. Wysocki
2016-08-02 20:59 ` Thomas Garnier
2016-08-02 21:08 ` Rafael J. Wysocki
2016-08-02 23:19 ` Rafael J. Wysocki [this message]
2016-08-05 10:37 ` [PATCH] x86/power/64: Do not refer to __PAGE_OFFSET from assembly code Pavel Machek
2016-08-05 14:44 ` Rafael J. Wysocki
2016-08-05 15:21 ` Thomas Garnier
2016-08-05 23:12 ` Rafael J. Wysocki
2016-08-06 19:41 ` Pavel Machek
2016-08-01 23:48 ` [PATCH v1 0/2] x86/power/64: Make KASLR memory randomization compatible with hibernation Rafael J. Wysocki
2016-08-02 0:47 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2464745.UmGP58NeXC@vostro.rjw.lan \
--to=rjw@rjwysocki.net \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pavel@ucw.cz \
--cc=rafael@kernel.org \
--cc=tglx@linutronix.de \
--cc=thgarnie@google.com \
--cc=x86@kernel.org \
--cc=yinghai@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome