Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ab3820f authored by Kees Cook's avatar Kees Cook Committed by H. Peter Anvin
Browse files

x86, kaslr: Return location from decompress_kernel



This allows decompress_kernel to return a new location for the kernel to
be relocated to. Additionally, enforces CONFIG_PHYSICAL_START as the
minimum relocation position when building with CONFIG_RELOCATABLE.

With CONFIG_RANDOMIZE_BASE set, the choose_kernel_location routine
will select a new location to decompress the kernel, though here it is
presently a no-op. The kernel command line option "nokaslr" is introduced
to bypass these routines.

Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Link: http://lkml.kernel.org/r/1381450698-28710-3-git-send-email-keescook@chromium.org


Signed-off-by: default avatarH. Peter Anvin <hpa@linux.intel.com>
parent dd78b973
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1975,6 +1975,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
	noapic		[SMP,APIC] Tells the kernel to not make use of any
			IOAPICs that may be present in the system.

	nokaslr		[X86]
			Disable kernel base offset ASLR (Address Space
			Layout Randomization) if built into the kernel.

	noautogroup	Disable scheduler automatic task group creation.

	nobats		[PPC] Do not use BATs for mapping kernel lowmem
+34 −4
Original line number Diff line number Diff line
@@ -1722,16 +1722,46 @@ config RELOCATABLE

	  Note: If CONFIG_RELOCATABLE=y, then the kernel runs from the address
	  it has been loaded at and the compile time physical address
	  (CONFIG_PHYSICAL_START) is ignored.
	  (CONFIG_PHYSICAL_START) is used as the minimum location.

# Relocation on x86-32 needs some additional build support
config RANDOMIZE_BASE
	bool "Randomize the address of the kernel image"
	depends on RELOCATABLE
	depends on !HIBERNATION
	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.

	   Entropy is generated using the RDRAND instruction if it
	   is supported.  If not, then RDTSC is used, if supported. If
	   neither RDRAND nor RDTSC are supported, then no randomness
	   is introduced.

	   The kernel will be offset by up to RANDOMIZE_BASE_MAX_OFFSET,
	   and aligned according to PHYSICAL_ALIGN.

config RANDOMIZE_BASE_MAX_OFFSET
	hex "Maximum ASLR offset allowed"
	depends on RANDOMIZE_BASE
	default "0x10000000"
	range 0x0 0x10000000
	---help---
	 Determines the maximal offset in bytes that will be applied to the
	 kernel when Address Space Layout Randomization (ASLR) is active.
	 Must be less than or equal to the actual physical memory on the
	 system. This must be a power of two.

# Relocation on x86 needs some additional build support
config X86_NEED_RELOCS
	def_bool y
	depends on X86_32 && RELOCATABLE
	depends on RANDOMIZE_BASE || (X86_32 && RELOCATABLE)

config PHYSICAL_ALIGN
	hex "Alignment value to which kernel should be aligned"
	default "0x1000000"
	default "0x200000"
	range 0x2000 0x1000000 if X86_32
	range 0x200000 0x1000000 if X86_64
	---help---
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ HOST_EXTRACFLAGS += -I$(srctree)/tools/include

VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
	$(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \
	$(obj)/piggy.o $(obj)/cpuflags.o
	$(obj)/piggy.o $(obj)/cpuflags.o $(obj)/aslr.o

$(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone

+23 −0
Original line number Diff line number Diff line
#include "misc.h"

#ifdef CONFIG_RANDOMIZE_BASE

unsigned char *choose_kernel_location(unsigned char *input,
				      unsigned long input_size,
				      unsigned char *output,
				      unsigned long output_size)
{
	unsigned long choice = (unsigned long)output;

	if (cmdline_find_option_bool("nokaslr")) {
		debug_putstr("KASLR disabled...\n");
		goto out;
	}

	/* XXX: choose random location. */

out:
	return (unsigned char *)choice;
}

#endif /* CONFIG_RANDOMIZE_BASE */
+1 −1
Original line number Diff line number Diff line
#include "misc.h"

#ifdef CONFIG_EARLY_PRINTK
#if CONFIG_EARLY_PRINTK || CONFIG_RANDOMIZE_BASE

static unsigned long fs;
static inline void set_fs(unsigned long seg)
Loading