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

Commit 9a45f036 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge branch 'x86-boot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 boot updates from Ingo Molnar:
 "The biggest changes in this cycle were:

   - prepare for more KASLR related changes, by restructuring, cleaning
     up and fixing the existing boot code.  (Kees Cook, Baoquan He,
     Yinghai Lu)

   - simplifly/concentrate subarch handling code, eliminate
     paravirt_enabled() usage.  (Luis R Rodriguez)"

* 'x86-boot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (50 commits)
  x86/KASLR: Clarify purpose of each get_random_long()
  x86/KASLR: Add virtual address choosing function
  x86/KASLR: Return earliest overlap when avoiding regions
  x86/KASLR: Add 'struct slot_area' to manage random_addr slots
  x86/boot: Add missing file header comments
  x86/KASLR: Initialize mapping_info every time
  x86/boot: Comment what finalize_identity_maps() does
  x86/KASLR: Build identity mappings on demand
  x86/boot: Split out kernel_ident_mapping_init()
  x86/boot: Clean up indenting for asm/boot.h
  x86/KASLR: Improve comments around the mem_avoid[] logic
  x86/boot: Simplify pointer casting in choose_random_location()
  x86/KASLR: Consolidate mem_avoid[] entries
  x86/boot: Clean up pointer casting
  x86/boot: Warn on future overlapping memcpy() use
  x86/boot: Extract error reporting functions
  x86/boot: Correctly bounds-check relocations
  x86/KASLR: Clean up unused code from old 'run_size' and rename it to 'kernel_total_size'
  x86/boot: Fix "run_size" calculation
  x86/boot: Calculate decompression size during boot not build
  ...
parents 168f1a71 d2d3462f
Loading
Loading
Loading
Loading
+28 −44
Original line number Diff line number Diff line
@@ -1921,54 +1921,38 @@ config RELOCATABLE
	  (CONFIG_PHYSICAL_START) is used as the minimum location.

config RANDOMIZE_BASE
	bool "Randomize the address of the kernel image"
	bool "Randomize the address of the kernel image (KASLR)"
	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.
	  In support of Kernel Address Space Layout Randomization (KASLR),
	  this randomizes the physical address at which the kernel image
	  is decompressed and the virtual address where the kernel
	  image is mapped, as a security feature that deters exploit
	  attempts relying on knowledge of the location of kernel
	  code internals.

	  The kernel physical and virtual address can be randomized
	  from 16MB up to 1GB on 64-bit and 512MB on 32-bit. (Note that
	  using RANDOMIZE_BASE reduces the memory space available to
	  kernel modules from 1.5GB to 1GB.)

	  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.
	  supported. If RDTSC is supported, its value is mixed into
	  the entropy pool as well. If neither RDRAND nor RDTSC are
	  supported, then entropy 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 2GB addressing, and
	  PHYSICAL_ALIGN must be at a minimum of 2MB, only 10 bits of
	  entropy is theoretically possible. Currently, with the
	  default value for PHYSICAL_ALIGN and due to page table
	  layouts, 64-bit uses 9 bits of entropy and 32-bit uses 8 bits.

	   If unsure, say N.
	  If CONFIG_HIBERNATE is also enabled, KASLR is disabled at boot
	  time. To enable it, boot with "kaslr" on the kernel command
	  line (which will also disable hibernation).

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.
	  If unsure, say N.

# Relocation on x86 needs some additional build support
config X86_NEED_RELOCS
+2 −1
Original line number Diff line number Diff line
@@ -208,7 +208,8 @@ endif

head-y := arch/x86/kernel/head_$(BITS).o
head-y += arch/x86/kernel/head$(BITS).o
head-y += arch/x86/kernel/head.o
head-y += arch/x86/kernel/ebda.o
head-y += arch/x86/kernel/platform-quirks.o

libs-y  += arch/x86/lib/

+2 −11
Original line number Diff line number Diff line
@@ -86,16 +86,7 @@ $(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE

SETUP_OBJS = $(addprefix $(obj)/,$(setup-y))

sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|_end\)$$/\#define VO_\2 0x\1/p'

quiet_cmd_voffset = VOFFSET $@
      cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@

targets += voffset.h
$(obj)/voffset.h: vmlinux FORCE
	$(call if_changed,voffset)

sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(startup_32\|startup_64\|efi32_stub_entry\|efi64_stub_entry\|efi_pe_entry\|input_data\|_end\|z_.*\)$$/\#define ZO_\2 0x\1/p'
sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(startup_32\|startup_64\|efi32_stub_entry\|efi64_stub_entry\|efi_pe_entry\|input_data\|_end\|_ehead\|_text\|z_.*\)$$/\#define ZO_\2 0x\1/p'

quiet_cmd_zoffset = ZOFFSET $@
      cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@
@@ -106,7 +97,7 @@ $(obj)/zoffset.h: $(obj)/compressed/vmlinux FORCE


AFLAGS_header.o += -I$(obj)
$(obj)/header.o: $(obj)/voffset.h $(obj)/zoffset.h
$(obj)/header.o: $(obj)/zoffset.h

LDFLAGS_setup.elf	:= -T
$(obj)/setup.elf: $(src)/setup.ld $(SETUP_OBJS) FORCE
+18 −5
Original line number Diff line number Diff line
@@ -57,12 +57,27 @@ LDFLAGS_vmlinux := -T
hostprogs-y	:= mkpiggy
HOST_EXTRACFLAGS += -I$(srctree)/tools/include

sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'

quiet_cmd_voffset = VOFFSET $@
      cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@

targets += ../voffset.h

$(obj)/../voffset.h: vmlinux FORCE
	$(call if_changed,voffset)

$(obj)/misc.o: $(obj)/../voffset.h

vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
	$(obj)/string.o $(obj)/cmdline.o \
	$(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
	$(obj)/piggy.o $(obj)/cpuflags.o

vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/aslr.o
vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
ifdef CONFIG_X86_64
	vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/pagetable.o
endif

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

@@ -109,10 +124,8 @@ suffix-$(CONFIG_KERNEL_XZ) := xz
suffix-$(CONFIG_KERNEL_LZO) 	:= lzo
suffix-$(CONFIG_KERNEL_LZ4) 	:= lz4

RUN_SIZE = $(shell $(OBJDUMP) -h vmlinux | \
	     $(CONFIG_SHELL) $(srctree)/arch/x86/tools/calc_run_size.sh)
quiet_cmd_mkpiggy = MKPIGGY $@
      cmd_mkpiggy = $(obj)/mkpiggy $< $(RUN_SIZE) > $@ || ( rm -f $@ ; false )
      cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false )

targets += piggy.S
$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
+2 −2
Original line number Diff line number Diff line
@@ -15,9 +15,9 @@ static inline char rdfs8(addr_t addr)
#include "../cmdline.c"
static unsigned long get_cmd_line_ptr(void)
{
	unsigned long cmd_line_ptr = real_mode->hdr.cmd_line_ptr;
	unsigned long cmd_line_ptr = boot_params->hdr.cmd_line_ptr;

	cmd_line_ptr |= (u64)real_mode->ext_cmd_line_ptr << 32;
	cmd_line_ptr |= (u64)boot_params->ext_cmd_line_ptr << 32;

	return cmd_line_ptr;
}
Loading