From: Baoquan He <bhe@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: yinghai@kernel.org, keescook@chromium.org, hpa@zytor.com,
mingo@redhat.com, bp@alien8.de, vgoyal@redhat.com,
luto@kernel.org, lasse.collin@tukaani.org,
akpm@linux-foundation.org, dyoung@redhat.com,
Baoquan He <bhe@redhat.com>
Subject: [PATCH v4 20/20] x86, kaslr: Use KERNEL_IMAGE_SIZE as the offset max for kernel virtual randomization
Date: Tue, 22 Mar 2016 15:32:17 +0800 [thread overview]
Message-ID: <1458631937-14593-21-git-send-email-bhe@redhat.com> (raw)
In-Reply-To: <1458631937-14593-1-git-send-email-bhe@redhat.com>
The old code uses CONFIG_RANDOM_OFFSET_MAX to get the offset max for kernel
virtual randomization, and CONFIG_RANDOM_OFFSET_MAX is a configurable value
within the scope of [512M, 1G] on x86_64. Currently CONFIG_RANDOM_OFFSET_MAX
always defaults to 1G, and seems no obvious benefit to make it configurable.
So Kees suggested we should set KERNEL_IMAGE_SIZE 1G if RANDOMIZE_BASE is
on, and use KERNEL_IMAGE_SIZE as offset max.
In this patch just do as Kees suggested. And with this change
CONFIG_RANDOM_OFFSET_MAX is not needed any more, so clean it up now.
Signed-off-by: Baoquan He <bhe@redhat.com>
---
v3->v4:
Added in v4.
arch/x86/Kconfig | 57 +++++++++++++-----------------------
arch/x86/boot/compressed/aslr.c | 7 ++---
arch/x86/include/asm/page_64_types.h | 5 ++--
arch/x86/mm/init_32.c | 3 --
4 files changed, 26 insertions(+), 46 deletions(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index b105105..fbe0bb0 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1908,51 +1908,36 @@ config RANDOMIZE_BASE
depends on RELOCATABLE
default n
---help---
- Randomizes the physical and virtual address at which the
- kernel image is decompressed, as a security feature that
- deters exploit attempts relying on knowledge of the location
- of kernel internals.
+ Randomizes the physical address at which the kernel image
+ is decompressed and the virtual address where the kernel
+ image is mapped, as a secrurity feature that deters exploit
+ attempts relying on knowledge of the location of kernel
+ internals.
+
+ The kernel physical address can be randomized from 16M to
+ 64T at most. The kernel virtual address will be offset
+ by up to KERNEL_IMAGE_SIZE. On 32-bit KERNEL_IMAGE_SIZE is
+ 512MiB. while on 64-bit this is limited by how the kernel
+ fixmap page table is positioned, so this cannot be larger
+ than 1GiB currently. Without RANDOMIZE_BASE there is a 512MiB
+ to 1.5GiB split between kernel and modules. When RANDOMIZE_BASE
+ is enabled, the modules area will shrink to compensate, up
+ to a 1GiB to 1GiB split, KERNEL_IMAGE_SIZE changes from 512MiB
+ to 1GiB.
Entropy is generated using the RDRAND instruction if it is
supported. If RDTSC is supported, it is used as well. If
neither RDRAND nor RDTSC are supported, then randomness is
read from the i8254 timer.
- The kernel will be offset by up to RANDOMIZE_BASE_MAX_OFFSET,
- and aligned according to PHYSICAL_ALIGN. Since the kernel is
- built using 2GiB addressing, and PHYSICAL_ALGIN must be at a
- minimum of 2MiB, only 10 bits of entropy is theoretically
- possible. At best, due to page table layouts, 64-bit can use
- 9 bits of entropy and 32-bit uses 8 bits.
+ Since the kernel is built using 2GiB addressing, and
+ PHYSICAL_ALGIN must be at a minimum of 2MiB, only 10 bits of
+ entropy is theoretically possible. At best, due to page table
+ layouts, 64-bit can use 9 bits of entropy and 32-bit uses 8
+ bits.
If unsure, say N.
-config RANDOMIZE_BASE_MAX_OFFSET
- hex "Maximum kASLR offset allowed" if EXPERT
- depends on RANDOMIZE_BASE
- range 0x0 0x20000000 if X86_32
- default "0x20000000" if X86_32
- range 0x0 0x40000000 if X86_64
- default "0x40000000" if X86_64
- ---help---
- The lesser of RANDOMIZE_BASE_MAX_OFFSET and available physical
- memory is used to determine the maximal offset in bytes that will
- be applied to the kernel when kernel Address Space Layout
- Randomization (kASLR) is active. This must be a multiple of
- PHYSICAL_ALIGN.
-
- On 32-bit this is limited to 512MiB by page table layouts. The
- default is 512MiB.
-
- On 64-bit this is limited by how the kernel fixmap page table is
- positioned, so this cannot be larger than 1GiB currently. Without
- RANDOMIZE_BASE, there is a 512MiB to 1.5GiB split between kernel
- and modules. When RANDOMIZE_BASE_MAX_OFFSET is above 512MiB, the
- modules area will shrink to compensate, up to the current maximum
- 1GiB to 1GiB split. The default is 1GiB.
-
- If unsure, leave at the default value.
-
# Relocation on x86 needs some additional build support
config X86_NEED_RELOCS
def_bool y
diff --git a/arch/x86/boot/compressed/aslr.c b/arch/x86/boot/compressed/aslr.c
index d072ca7..737643c 100644
--- a/arch/x86/boot/compressed/aslr.c
+++ b/arch/x86/boot/compressed/aslr.c
@@ -428,11 +428,10 @@ static unsigned long find_random_virt_offset(unsigned long minimum,
minimum = ALIGN(minimum, CONFIG_PHYSICAL_ALIGN);
if (image_size <= CONFIG_PHYSICAL_ALIGN)
- slot_num = (CONFIG_RANDOMIZE_BASE_MAX_OFFSET - minimum) /
+ slot_num = (KERNEL_IMAGE_SIZE - minimum) /
CONFIG_PHYSICAL_ALIGN;
else
- slot_num = (CONFIG_RANDOMIZE_BASE_MAX_OFFSET -
- minimum - image_size) /
+ slot_num = (KERNEL_IMAGE_SIZE - minimum - image_size) /
CONFIG_PHYSICAL_ALIGN + 1;
random = get_random_long() % slot_num;
@@ -487,7 +486,7 @@ void choose_kernel_location(unsigned char *input,
/*
* Get a random address between LOAD_PHYSICAL_ADDR and
- * CONFIG_RANDOMIZE_BASE_MAX_OFFSET
+ * KERNEL_IMAGE_SIZE
*/
random = find_random_virt_offset(LOAD_PHYSICAL_ADDR, output_size);
*virt_offset = (unsigned char *)random;
diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
index 4928cf0..8775bec 100644
--- a/arch/x86/include/asm/page_64_types.h
+++ b/arch/x86/include/asm/page_64_types.h
@@ -48,9 +48,8 @@
* kernel page table mapping, reducing the size of the modules area.
*/
#define KERNEL_IMAGE_SIZE_DEFAULT (512 * 1024 * 1024)
-#if defined(CONFIG_RANDOMIZE_BASE) && \
- CONFIG_RANDOMIZE_BASE_MAX_OFFSET > KERNEL_IMAGE_SIZE_DEFAULT
-#define KERNEL_IMAGE_SIZE CONFIG_RANDOMIZE_BASE_MAX_OFFSET
+#if defined(CONFIG_RANDOMIZE_BASE)
+#define KERNEL_IMAGE_SIZE (1024 * 1024 * 1024)
#else
#define KERNEL_IMAGE_SIZE KERNEL_IMAGE_SIZE_DEFAULT
#endif
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index 2ebfbaf..c5ae958 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -807,9 +807,6 @@ void __init mem_init(void)
BUILD_BUG_ON(VMALLOC_START >= VMALLOC_END);
#undef high_memory
#undef __FIXADDR_TOP
-#ifdef CONFIG_RANDOMIZE_BASE
- BUILD_BUG_ON(CONFIG_RANDOMIZE_BASE_MAX_OFFSET > KERNEL_IMAGE_SIZE);
-#endif
#ifdef CONFIG_HIGHMEM
BUG_ON(PKMAP_BASE + LAST_PKMAP*PAGE_SIZE > FIXADDR_START);
--
2.5.0
next prev parent reply other threads:[~2016-03-22 7:34 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-22 7:31 [PATCH v4 00/20] x86, boot: kaslr cleanup and 64bit kaslr support Baoquan He
2016-03-22 7:31 ` [PATCH v4 01/20] x86, kaslr: Remove not needed parameter for choose_kernel_location Baoquan He
2016-03-22 7:31 ` [PATCH v4 02/20] x86, kaslr: Fix a bug that relocation can not be handled when kernel is loaded above 2G Baoquan He
2016-03-22 7:32 ` [PATCH v4 03/20] x86, boot: Move compressed kernel to end of buffer before decompressing Baoquan He
2016-03-22 7:32 ` [PATCH v4 04/20] x86, boot: Move z_extract_offset calculation to header.S Baoquan He
2016-03-22 7:32 ` [PATCH v4 05/20] x86, kaskr: Update the description for decompressor worst case Baoquan He
2016-03-22 7:32 ` [PATCH v4 06/20] x86, boot: Fix run_size calculation Baoquan He
2016-03-22 20:51 ` Kees Cook
2016-03-22 7:32 ` [PATCH v4 07/20] x86, kaslr: Clean up useless code related to run_size Baoquan He
2016-03-22 20:52 ` Kees Cook
2016-03-22 7:32 ` [PATCH v4 08/20] x86, kaslr: Get correct max_addr for relocs pointer Baoquan He
2016-03-22 20:52 ` Kees Cook
2016-03-22 7:32 ` [PATCH v4 09/20] x86, kaslr: Consolidate mem_avoid array filling Baoquan He
2016-03-22 7:32 ` [PATCH v4 10/20] x86, boot: Split kernel_ident_mapping_init to another file Baoquan He
2016-03-22 7:32 ` [PATCH v4 11/20] x86, 64bit: Set ident_mapping for kaslr Baoquan He
2016-04-13 10:05 ` Ingo Molnar
2016-03-22 7:32 ` [PATCH v4 12/20] x86, boot: Add checking for memcpy Baoquan He
2016-03-22 7:32 ` [PATCH v4 13/20] x86, kaslr: Introduce struct slot_area to manage randomization slot info Baoquan He
2016-03-22 7:32 ` [PATCH v4 14/20] x86, kaslr: Add two functions which will be used later Baoquan He
2016-03-22 7:32 ` [PATCH v4 15/20] x86, kaslr: Introduce fetch_random_virt_offset to randomize the kernel text mapping address Baoquan He
2016-03-22 7:32 ` [PATCH v4 16/20] x86, kaslr: Randomize physical and virtual address of kernel separately Baoquan He
2016-03-22 7:32 ` [PATCH v4 17/20] x86, kaslr: Add support of kernel physical address randomization above 4G Baoquan He
2016-03-22 7:32 ` [PATCH v4 18/20] x86, kaslr: Remove useless codes Baoquan He
2016-03-22 7:32 ` [PATCH v4 19/20] x86, kaslr: Allow random address to be below loaded address Baoquan He
2016-03-22 19:54 ` Kees Cook
2016-03-23 1:41 ` Baoquan He
2016-03-23 8:59 ` [PATCH v5 " Baoquan He
2016-03-22 7:32 ` Baoquan He [this message]
2016-03-22 20:46 ` [PATCH v4 20/20] x86, kaslr: Use KERNEL_IMAGE_SIZE as the offset max for kernel virtual randomization Kees Cook
2016-03-22 20:25 ` [PATCH v4 00/20] x86, boot: kaslr cleanup and 64bit kaslr support Kees Cook
2016-03-23 22:40 ` Kees Cook
2016-04-05 1:56 ` Baoquan He
2016-04-05 20:00 ` Kees Cook
2016-04-13 10:19 ` Ingo Molnar
2016-04-13 14:11 ` Kees Cook
2016-04-14 6:02 ` Kees Cook
2016-04-14 6:24 ` Baoquan He
2016-04-14 15:06 ` Baoquan He
2016-04-14 17:56 ` Kees Cook
2016-04-15 4:08 ` Baoquan He
2016-04-15 4:52 ` Kees Cook
2016-04-15 6:55 ` Ingo Molnar
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=1458631937-14593-21-git-send-email-bhe@redhat.com \
--to=bhe@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=dyoung@redhat.com \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=lasse.collin@tukaani.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=vgoyal@redhat.com \
--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;
as well as URLs for NNTP newsgroup(s).