diff options
Diffstat (limited to 'arch/x86/mm/kaslr.c')
-rw-r--r-- | arch/x86/mm/kaslr.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c index ec8654f117d8..aec03aa96312 100644 --- a/arch/x86/mm/kaslr.c +++ b/arch/x86/mm/kaslr.c | |||
@@ -40,17 +40,26 @@ | |||
40 | * You need to add an if/def entry if you introduce a new memory region | 40 | * You need to add an if/def entry if you introduce a new memory region |
41 | * compatible with KASLR. Your entry must be in logical order with memory | 41 | * compatible with KASLR. Your entry must be in logical order with memory |
42 | * layout. For example, ESPFIX is before EFI because its virtual address is | 42 | * layout. For example, ESPFIX is before EFI because its virtual address is |
43 | * before. You also need to add a BUILD_BUG_ON in kernel_randomize_memory to | 43 | * before. You also need to add a BUILD_BUG_ON() in kernel_randomize_memory() to |
44 | * ensure that this order is correct and won't be changed. | 44 | * ensure that this order is correct and won't be changed. |
45 | */ | 45 | */ |
46 | static const unsigned long vaddr_start = __PAGE_OFFSET_BASE; | 46 | static const unsigned long vaddr_start = __PAGE_OFFSET_BASE; |
47 | static const unsigned long vaddr_end = VMEMMAP_START; | 47 | |
48 | #if defined(CONFIG_X86_ESPFIX64) | ||
49 | static const unsigned long vaddr_end = ESPFIX_BASE_ADDR; | ||
50 | #elif defined(CONFIG_EFI) | ||
51 | static const unsigned long vaddr_end = EFI_VA_START; | ||
52 | #else | ||
53 | static const unsigned long vaddr_end = __START_KERNEL_map; | ||
54 | #endif | ||
48 | 55 | ||
49 | /* Default values */ | 56 | /* Default values */ |
50 | unsigned long page_offset_base = __PAGE_OFFSET_BASE; | 57 | unsigned long page_offset_base = __PAGE_OFFSET_BASE; |
51 | EXPORT_SYMBOL(page_offset_base); | 58 | EXPORT_SYMBOL(page_offset_base); |
52 | unsigned long vmalloc_base = __VMALLOC_BASE; | 59 | unsigned long vmalloc_base = __VMALLOC_BASE; |
53 | EXPORT_SYMBOL(vmalloc_base); | 60 | EXPORT_SYMBOL(vmalloc_base); |
61 | unsigned long vmemmap_base = __VMEMMAP_BASE; | ||
62 | EXPORT_SYMBOL(vmemmap_base); | ||
54 | 63 | ||
55 | /* | 64 | /* |
56 | * Memory regions randomized by KASLR (except modules that use a separate logic | 65 | * Memory regions randomized by KASLR (except modules that use a separate logic |
@@ -63,6 +72,7 @@ static __initdata struct kaslr_memory_region { | |||
63 | } kaslr_regions[] = { | 72 | } kaslr_regions[] = { |
64 | { &page_offset_base, 64/* Maximum */ }, | 73 | { &page_offset_base, 64/* Maximum */ }, |
65 | { &vmalloc_base, VMALLOC_SIZE_TB }, | 74 | { &vmalloc_base, VMALLOC_SIZE_TB }, |
75 | { &vmemmap_base, 1 }, | ||
66 | }; | 76 | }; |
67 | 77 | ||
68 | /* Get size in bytes used by the memory region */ | 78 | /* Get size in bytes used by the memory region */ |
@@ -89,6 +99,18 @@ void __init kernel_randomize_memory(void) | |||
89 | struct rnd_state rand_state; | 99 | struct rnd_state rand_state; |
90 | unsigned long remain_entropy; | 100 | unsigned long remain_entropy; |
91 | 101 | ||
102 | /* | ||
103 | * All these BUILD_BUG_ON checks ensures the memory layout is | ||
104 | * consistent with the vaddr_start/vaddr_end variables. | ||
105 | */ | ||
106 | BUILD_BUG_ON(vaddr_start >= vaddr_end); | ||
107 | BUILD_BUG_ON(config_enabled(CONFIG_X86_ESPFIX64) && | ||
108 | vaddr_end >= EFI_VA_START); | ||
109 | BUILD_BUG_ON((config_enabled(CONFIG_X86_ESPFIX64) || | ||
110 | config_enabled(CONFIG_EFI)) && | ||
111 | vaddr_end >= __START_KERNEL_map); | ||
112 | BUILD_BUG_ON(vaddr_end > __START_KERNEL_map); | ||
113 | |||
92 | if (!kaslr_memory_enabled()) | 114 | if (!kaslr_memory_enabled()) |
93 | return; | 115 | return; |
94 | 116 | ||