All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Garnier <thgarnie@google.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
	Kees Cook <keescook@chromium.org>,
	Thomas Garnier <thgarnie@google.com>,
	Yinghai Lu <yinghai@kernel.org>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	Pavel Machek <pavel@ucw.cz>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	linux-pm@vger.kernel.org, kernel-hardening@lists.openwall.com
Subject: [PATCH v1 1/2] x86/power/64: Support unaligned addresses for temporary mapping
Date: Mon,  1 Aug 2016 10:07:59 -0700	[thread overview]
Message-ID: <1470071280-78706-2-git-send-email-thgarnie@google.com> (raw)
In-Reply-To: <1470071280-78706-1-git-send-email-thgarnie@google.com>

Correctly setup the temporary mapping for hibernation. Previous
implementation assumed the address was aligned on the PGD level. With
KASLR memory randomization enabled, the address is randomized on the PUD
level. This change supports unaligned address up to PMD.

Signed-off-by: Thomas Garnier <thgarnie@google.com>
---
 arch/x86/mm/ident_map.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/arch/x86/mm/ident_map.c b/arch/x86/mm/ident_map.c
index ec21796..ea1ebf1 100644
--- a/arch/x86/mm/ident_map.c
+++ b/arch/x86/mm/ident_map.c
@@ -3,15 +3,16 @@
  * included by both the compressed kernel and the regular kernel.
  */
 
-static void ident_pmd_init(unsigned long pmd_flag, pmd_t *pmd_page,
+static void ident_pmd_init(struct x86_mapping_info *info, pmd_t *pmd_page,
 			   unsigned long addr, unsigned long end)
 {
-	addr &= PMD_MASK;
-	for (; addr < end; addr += PMD_SIZE) {
-		pmd_t *pmd = pmd_page + pmd_index(addr);
+	int off = info->kernel_mapping ? pmd_index(__PAGE_OFFSET) : 0;
+
+	for (addr &= PMD_MASK; addr < end; addr += PMD_SIZE) {
+		pmd_t *pmd = pmd_page + pmd_index(addr) + off;
 
 		if (!pmd_present(*pmd))
-			set_pmd(pmd, __pmd(addr | pmd_flag));
+			set_pmd(pmd, __pmd(addr | info->pmd_flag));
 	}
 }
 
@@ -19,9 +20,10 @@ static int ident_pud_init(struct x86_mapping_info *info, pud_t *pud_page,
 			  unsigned long addr, unsigned long end)
 {
 	unsigned long next;
+	int off = info->kernel_mapping ? pud_index(__PAGE_OFFSET) : 0;
 
 	for (; addr < end; addr = next) {
-		pud_t *pud = pud_page + pud_index(addr);
+		pud_t *pud = pud_page + pud_index(addr) + off;
 		pmd_t *pmd;
 
 		next = (addr & PUD_MASK) + PUD_SIZE;
@@ -30,13 +32,13 @@ static int ident_pud_init(struct x86_mapping_info *info, pud_t *pud_page,
 
 		if (pud_present(*pud)) {
 			pmd = pmd_offset(pud, 0);
-			ident_pmd_init(info->pmd_flag, pmd, addr, next);
+			ident_pmd_init(info, pmd, addr, next);
 			continue;
 		}
 		pmd = (pmd_t *)info->alloc_pgt_page(info->context);
 		if (!pmd)
 			return -ENOMEM;
-		ident_pmd_init(info->pmd_flag, pmd, addr, next);
+		ident_pmd_init(info, pmd, addr, next);
 		set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE));
 	}
 
-- 
2.8.0.rc3.226.g39d4020

WARNING: multiple messages have this Message-ID (diff)
From: Thomas Garnier <thgarnie@google.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
	Kees Cook <keescook@chromium.org>,
	Thomas Garnier <thgarnie@google.com>,
	Yinghai Lu <yinghai@kernel.org>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	Pavel Machek <pavel@ucw.cz>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	linux-pm@vger.kernel.org, kernel-hardening@lists.openwall.com
Subject: [kernel-hardening] [PATCH v1 1/2] x86/power/64: Support unaligned addresses for temporary mapping
Date: Mon,  1 Aug 2016 10:07:59 -0700	[thread overview]
Message-ID: <1470071280-78706-2-git-send-email-thgarnie@google.com> (raw)
In-Reply-To: <1470071280-78706-1-git-send-email-thgarnie@google.com>

Correctly setup the temporary mapping for hibernation. Previous
implementation assumed the address was aligned on the PGD level. With
KASLR memory randomization enabled, the address is randomized on the PUD
level. This change supports unaligned address up to PMD.

Signed-off-by: Thomas Garnier <thgarnie@google.com>
---
 arch/x86/mm/ident_map.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/arch/x86/mm/ident_map.c b/arch/x86/mm/ident_map.c
index ec21796..ea1ebf1 100644
--- a/arch/x86/mm/ident_map.c
+++ b/arch/x86/mm/ident_map.c
@@ -3,15 +3,16 @@
  * included by both the compressed kernel and the regular kernel.
  */
 
-static void ident_pmd_init(unsigned long pmd_flag, pmd_t *pmd_page,
+static void ident_pmd_init(struct x86_mapping_info *info, pmd_t *pmd_page,
 			   unsigned long addr, unsigned long end)
 {
-	addr &= PMD_MASK;
-	for (; addr < end; addr += PMD_SIZE) {
-		pmd_t *pmd = pmd_page + pmd_index(addr);
+	int off = info->kernel_mapping ? pmd_index(__PAGE_OFFSET) : 0;
+
+	for (addr &= PMD_MASK; addr < end; addr += PMD_SIZE) {
+		pmd_t *pmd = pmd_page + pmd_index(addr) + off;
 
 		if (!pmd_present(*pmd))
-			set_pmd(pmd, __pmd(addr | pmd_flag));
+			set_pmd(pmd, __pmd(addr | info->pmd_flag));
 	}
 }
 
@@ -19,9 +20,10 @@ static int ident_pud_init(struct x86_mapping_info *info, pud_t *pud_page,
 			  unsigned long addr, unsigned long end)
 {
 	unsigned long next;
+	int off = info->kernel_mapping ? pud_index(__PAGE_OFFSET) : 0;
 
 	for (; addr < end; addr = next) {
-		pud_t *pud = pud_page + pud_index(addr);
+		pud_t *pud = pud_page + pud_index(addr) + off;
 		pmd_t *pmd;
 
 		next = (addr & PUD_MASK) + PUD_SIZE;
@@ -30,13 +32,13 @@ static int ident_pud_init(struct x86_mapping_info *info, pud_t *pud_page,
 
 		if (pud_present(*pud)) {
 			pmd = pmd_offset(pud, 0);
-			ident_pmd_init(info->pmd_flag, pmd, addr, next);
+			ident_pmd_init(info, pmd, addr, next);
 			continue;
 		}
 		pmd = (pmd_t *)info->alloc_pgt_page(info->context);
 		if (!pmd)
 			return -ENOMEM;
-		ident_pmd_init(info->pmd_flag, pmd, addr, next);
+		ident_pmd_init(info, pmd, addr, next);
 		set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE));
 	}
 
-- 
2.8.0.rc3.226.g39d4020

  reply	other threads:[~2016-08-01 17:09 UTC|newest]

Thread overview: 70+ 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 ` [kernel-hardening] " Thomas Garnier
2016-08-01 17:07 ` Thomas Garnier [this message]
2016-08-01 17:07   ` [kernel-hardening] [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  0:36     ` [kernel-hardening] " Rafael J. Wysocki
2016-08-02 18:01     ` Yinghai Lu
2016-08-02 18:01       ` [kernel-hardening] " Yinghai Lu
2016-08-02 18:01       ` Yinghai Lu
2016-08-02 17:36   ` Yinghai Lu
2016-08-02 17:36     ` [kernel-hardening] " Yinghai Lu
2016-08-02 17:36     ` Yinghai Lu
2016-08-02 17:48     ` Thomas Garnier
2016-08-02 17:48       ` [kernel-hardening] " Thomas Garnier
2016-08-02 17:48       ` Thomas Garnier
2016-08-02 19:55       ` Yinghai Lu
2016-08-02 19:55         ` [kernel-hardening] " Yinghai Lu
2016-08-02 19:55         ` Yinghai Lu
2016-08-03 15:29         ` Thomas Garnier
2016-08-03 15:29           ` [kernel-hardening] " Thomas Garnier
2016-08-03 15:29           ` Thomas Garnier
2016-08-03 18:23         ` [PATCH v2] " Yinghai Lu
2016-08-03 18:23           ` [kernel-hardening] " Yinghai Lu
2016-08-03 21:28           ` Rafael J. Wysocki
2016-08-03 21:28             ` [kernel-hardening] " Rafael J. Wysocki
2016-08-07  1:03             ` Rafael J. Wysocki
2016-08-07  1:03               ` [kernel-hardening] " Rafael J. Wysocki
2016-08-07  4:53               ` Yinghai Lu
2016-08-07  4:53                 ` [kernel-hardening] " Yinghai Lu
2016-08-07  4:53                 ` Yinghai Lu
2016-08-07 23:23                 ` Rafael J. Wysocki
2016-08-07 23:23                   ` [kernel-hardening] " Rafael J. Wysocki
2016-08-07 23:23                   ` Rafael J. Wysocki
2016-08-08  7:06                   ` Yinghai Lu
2016-08-08  7:06                     ` [kernel-hardening] " Yinghai Lu
2016-08-08  7:06                     ` Yinghai Lu
2016-08-08  7:23                     ` Yinghai Lu
2016-08-08  7:23                       ` [kernel-hardening] " Yinghai Lu
2016-08-08  7:23                       ` Yinghai Lu
2016-08-08 13:16                       ` Rafael J. Wysocki
2016-08-08 13:16                         ` [kernel-hardening] " Rafael J. Wysocki
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-01 17:08   ` [kernel-hardening] " Thomas Garnier
2016-08-02  0:38   ` Rafael J. Wysocki
2016-08-02  0:38     ` [kernel-hardening] " Rafael J. Wysocki
2016-08-02 14:34     ` Thomas Garnier
2016-08-02 14:34       ` [kernel-hardening] " Thomas Garnier
2016-08-02 20:47       ` Rafael J. Wysocki
2016-08-02 20:47         ` [kernel-hardening] " Rafael J. Wysocki
2016-08-02 20:59         ` Thomas Garnier
2016-08-02 20:59           ` [kernel-hardening] " Thomas Garnier
2016-08-02 21:08           ` Rafael J. Wysocki
2016-08-02 21:08             ` [kernel-hardening] " Rafael J. Wysocki
2016-08-02 23:19             ` [PATCH] x86/power/64: Do not refer to __PAGE_OFFSET from assembly code Rafael J. Wysocki
2016-08-02 23:19               ` [kernel-hardening] " Rafael J. Wysocki
2016-08-05 10:37               ` Pavel Machek
2016-08-05 10:37                 ` [kernel-hardening] " Pavel Machek
2016-08-05 14:44                 ` Rafael J. Wysocki
2016-08-05 14:44                   ` [kernel-hardening] " Rafael J. Wysocki
2016-08-05 15:21                   ` Thomas Garnier
2016-08-05 15:21                     ` [kernel-hardening] " Thomas Garnier
2016-08-05 23:12                     ` Rafael J. Wysocki
2016-08-05 23:12                       ` [kernel-hardening] " Rafael J. Wysocki
2016-08-06 19:41                       ` Pavel Machek
2016-08-06 19:41                         ` [kernel-hardening] " 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-01 23:48   ` [kernel-hardening] " Rafael J. Wysocki
2016-08-02  0:47   ` Rafael J. Wysocki
2016-08-02  0:47     ` [kernel-hardening] " 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=1470071280-78706-2-git-send-email-thgarnie@google.com \
    --to=thgarnie@google.com \
    --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=rjw@rjwysocki.net \
    --cc=tglx@linutronix.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.