From: Baoquan He <bhe@redhat.com>
To: linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com
Cc: dave.hansen@linux.intel.com, luto@kernel.org,
peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, hpa@zytor.com, x86@kernel.org,
keescook@chromium.org, thgarnie@google.com,
Baoquan He <bhe@redhat.com>
Subject: [PATCH v2 2/2] x86/mm/KASLR: Change the granularity of randomization to PUD size in 5-level
Date: Thu, 28 Feb 2019 08:35:22 +0800 [thread overview]
Message-ID: <20190228003522.9957-3-bhe@redhat.com> (raw)
In-Reply-To: <20190228003522.9957-1-bhe@redhat.com>
The current randomization granularity of 5-level is 512 GB. Improve
it to 1 GB. This can add more randomness to memory region KASLR in
5-level paging mode
Signed-off-by: Baoquan He <bhe@redhat.com>
---
arch/x86/mm/kaslr.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index 131e08a10a68..99ec75634613 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -204,10 +204,7 @@ void __init kernel_randomize_memory(void)
*/
entropy = remain_entropy / (ARRAY_SIZE(kaslr_regions) - i);
prandom_bytes_state(&rand_state, &rand, sizeof(rand));
- if (pgtable_l5_enabled())
- entropy = (rand % (entropy + 1)) & P4D_MASK;
- else
- entropy = (rand % (entropy + 1)) & PUD_MASK;
+ entropy = (rand % (entropy + 1)) & PUD_MASK;
vaddr += entropy;
*kaslr_regions[i].base = vaddr;
@@ -216,10 +213,7 @@ void __init kernel_randomize_memory(void)
* randomization alignment.
*/
vaddr += kaslr_regions[i].size_tb << TB_SHIFT;
- if (pgtable_l5_enabled())
- vaddr = round_up(vaddr + 1, P4D_SIZE);
- else
- vaddr = round_up(vaddr + 1, PUD_SIZE);
+ vaddr = round_up(vaddr + 1, PUD_SIZE);
remain_entropy -= entropy;
}
}
@@ -276,8 +270,8 @@ static void __meminit init_trampoline_pud(void)
* that area. In case KASLR disabled, the 1st PGD entry of the
* direct mapping is copied directly. If KASLR is enabled, only
* copy the 1st PUD entry where physical address 0 resides since
- * the granularity of randomization is PUD size in 4-level, and
- * P4D size in 5-level.
+ * the granularity of randomization is PUD size in both 4-level and
+ * 5-level.
*
* This consumes one low memory page in 4-level case, and extra one
* in 5-level.
--
2.17.2
next prev parent reply other threads:[~2019-02-28 0:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-28 0:35 [PATCH v2 0/2] x86/mm/KASLR: Change the granularity of randomization to PUD size in 5-level Baoquan He
2019-02-28 0:35 ` [PATCH v2 1/2] x86/mm/KASLR: Only build one PUD entry of area for real mode trampoline Baoquan He
2019-02-28 0:35 ` Baoquan He [this message]
2019-02-28 9:10 ` [PATCH v2 0/2] x86/mm/KASLR: Change the granularity of randomization to PUD size in 5-level Kirill A. Shutemov
2019-02-28 9:23 ` Baoquan He
2019-02-28 9:55 ` Kirill A. Shutemov
2019-02-28 10:04 ` Baoquan He
2019-02-28 10:30 ` Kirill A. Shutemov
2019-02-28 13:01 ` Baoquan He
2019-03-01 14:45 ` Baoquan He
2019-03-04 8:15 ` Kirill A. Shutemov
2019-03-04 8:52 ` Baoquan He
2019-02-28 9:29 ` [PATCH v3 " Baoquan He
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=20190228003522.9957-3-bhe@redhat.com \
--to=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=thgarnie@google.com \
--cc=x86@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.