Skip to content

Commit f4bcd8c

Browse files
committed
Merge branch 'x86-kaslr-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 kernel address space randomization support from Peter Anvin: "This enables kernel address space randomization for x86" * 'x86-kaslr-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86, kaslr: Clarify RANDOMIZE_BASE_MAX_OFFSET x86, kaslr: Remove unused including <linux/version.h> x86, kaslr: Use char array to gain sizeof sanity x86, kaslr: Add a circular multiply for better bit diffusion x86, kaslr: Mix entropy sources together as needed x86/relocs: Add percpu fixup for GNU ld 2.23 x86, boot: Rename get_flags() and check_flags() to *_cpuflags() x86, kaslr: Raise the maximum virtual address to -1 GiB on x86_64 x86, kaslr: Report kernel offset on panic x86, kaslr: Select random position from e820 maps x86, kaslr: Provide randomness functions x86, kaslr: Return location from decompress_kernel x86, boot: Move CPU flags out of cpucheck x86, relocs: Add more per-cpu gold special cases
2 parents 7fe67a1 + da2b6fb commit f4bcd8c

File tree

22 files changed

+654
-158
lines changed

22 files changed

+654
-158
lines changed

Documentation/kernel-parameters.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,6 +2017,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
20172017
noapic [SMP,APIC] Tells the kernel to not make use of any
20182018
IOAPICs that may be present in the system.
20192019

2020+
nokaslr [X86]
2021+
Disable kernel base offset ASLR (Address Space
2022+
Layout Randomization) if built into the kernel.
2023+
20202024
noautogroup Disable scheduler automatic task group creation.
20212025

20222026
nobats [PPC] Do not use BATs for mapping kernel lowmem

arch/x86/Kconfig

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,16 +1693,67 @@ config RELOCATABLE
16931693

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

1698-
# Relocation on x86-32 needs some additional build support
1698+
config RANDOMIZE_BASE
1699+
bool "Randomize the address of the kernel image"
1700+
depends on RELOCATABLE
1701+
depends on !HIBERNATION
1702+
default n
1703+
---help---
1704+
Randomizes the physical and virtual address at which the
1705+
kernel image is decompressed, as a security feature that
1706+
deters exploit attempts relying on knowledge of the location
1707+
of kernel internals.
1708+
1709+
Entropy is generated using the RDRAND instruction if it is
1710+
supported. If RDTSC is supported, it is used as well. If
1711+
neither RDRAND nor RDTSC are supported, then randomness is
1712+
read from the i8254 timer.
1713+
1714+
The kernel will be offset by up to RANDOMIZE_BASE_MAX_OFFSET,
1715+
and aligned according to PHYSICAL_ALIGN. Since the kernel is
1716+
built using 2GiB addressing, and PHYSICAL_ALGIN must be at a
1717+
minimum of 2MiB, only 10 bits of entropy is theoretically
1718+
possible. At best, due to page table layouts, 64-bit can use
1719+
9 bits of entropy and 32-bit uses 8 bits.
1720+
1721+
If unsure, say N.
1722+
1723+
config RANDOMIZE_BASE_MAX_OFFSET
1724+
hex "Maximum kASLR offset allowed" if EXPERT
1725+
depends on RANDOMIZE_BASE
1726+
range 0x0 0x20000000 if X86_32
1727+
default "0x20000000" if X86_32
1728+
range 0x0 0x40000000 if X86_64
1729+
default "0x40000000" if X86_64
1730+
---help---
1731+
The lesser of RANDOMIZE_BASE_MAX_OFFSET and available physical
1732+
memory is used to determine the maximal offset in bytes that will
1733+
be applied to the kernel when kernel Address Space Layout
1734+
Randomization (kASLR) is active. This must be a multiple of
1735+
PHYSICAL_ALIGN.
1736+
1737+
On 32-bit this is limited to 512MiB by page table layouts. The
1738+
default is 512MiB.
1739+
1740+
On 64-bit this is limited by how the kernel fixmap page table is
1741+
positioned, so this cannot be larger than 1GiB currently. Without
1742+
RANDOMIZE_BASE, there is a 512MiB to 1.5GiB split between kernel
1743+
and modules. When RANDOMIZE_BASE_MAX_OFFSET is above 512MiB, the
1744+
modules area will shrink to compensate, up to the current maximum
1745+
1GiB to 1GiB split. The default is 1GiB.
1746+
1747+
If unsure, leave at the default value.
1748+
1749+
# Relocation on x86 needs some additional build support
16991750
config X86_NEED_RELOCS
17001751
def_bool y
1701-
depends on X86_32 && RELOCATABLE
1752+
depends on RANDOMIZE_BASE || (X86_32 && RELOCATABLE)
17021753

17031754
config PHYSICAL_ALIGN
17041755
hex "Alignment value to which kernel should be aligned"
1705-
default "0x1000000"
1756+
default "0x200000"
17061757
range 0x2000 0x1000000 if X86_32
17071758
range 0x200000 0x1000000 if X86_64
17081759
---help---

arch/x86/boot/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ targets := vmlinux.bin setup.bin setup.elf bzImage
2020
targets += fdimage fdimage144 fdimage288 image.iso mtools.conf
2121
subdir- := compressed
2222

23-
setup-y += a20.o bioscall.o cmdline.o copy.o cpu.o cpucheck.o
23+
setup-y += a20.o bioscall.o cmdline.o copy.o cpu.o cpuflags.o cpucheck.o
2424
setup-y += early_serial_console.o edd.o header.o main.o mca.o memory.o
2525
setup-y += pm.o pmjump.o printf.o regs.o string.o tty.o video.o
2626
setup-y += video-mode.o version.o

arch/x86/boot/boot.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
#include <asm/boot.h>
2727
#include <asm/setup.h>
2828
#include "bitops.h"
29-
#include <asm/cpufeature.h>
30-
#include <asm/processor-flags.h>
3129
#include "ctype.h"
30+
#include "cpuflags.h"
3231

3332
/* Useful macros */
3433
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
@@ -307,14 +306,7 @@ static inline int cmdline_find_option_bool(const char *option)
307306
return __cmdline_find_option_bool(cmd_line_ptr, option);
308307
}
309308

310-
311309
/* cpu.c, cpucheck.c */
312-
struct cpu_features {
313-
int level; /* Family, or 64 for x86-64 */
314-
int model;
315-
u32 flags[NCAPINTS];
316-
};
317-
extern struct cpu_features cpu;
318310
int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr);
319311
int validate_cpu(void);
320312

arch/x86/boot/compressed/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ HOST_EXTRACFLAGS += -I$(srctree)/tools/include
2828

2929
VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
3030
$(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \
31-
$(obj)/piggy.o
31+
$(obj)/piggy.o $(obj)/cpuflags.o $(obj)/aslr.o
3232

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

0 commit comments

Comments
 (0)