Skip to content

Commit 69797da

Browse files
suryasaimadhuingomolnar
authored andcommitted
Revert "x86/mm/ASLR: Propagate base load address calculation"
This reverts commit: f47233c ("x86/mm/ASLR: Propagate base load address calculation") The main reason for the revert is that the new boot flag does not work at all currently, and in order to make this work, we need non-trivial changes to the x86 boot code which we didn't manage to get done in time for merging. And even if we did, they would've been too risky so instead of rushing things and break booting 4.1 on boxes left and right, we will be very strict and conservative and will take our time with this to fix and test it properly. Reported-by: Yinghai Lu <yinghai@kernel.org> Signed-off-by: Borislav Petkov <bp@suse.de> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Baoquan He <bhe@redhat.com> Cc: H. Peter Anvin <hpa@linux.intel.com Cc: Jiri Kosina <jkosina@suse.cz> Cc: Josh Triplett <josh@joshtriplett.org> Cc: Junjie Mao <eternal.n08@gmail.com> Cc: Kees Cook <keescook@chromium.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matt Fleming <matt.fleming@intel.com> Link: http://lkml.kernel.org/r/20150316100628.GD22995@pd.tnic Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent f4c3686 commit 69797da

7 files changed

Lines changed: 17 additions & 61 deletions

File tree

‎arch/x86/boot/compressed/aslr.c‎

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
static const char build_str[] = UTS_RELEASE " (" LINUX_COMPILE_BY "@"
1515
LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION;
1616

17-
struct kaslr_setup_data {
18-
__u64 next;
19-
__u32 type;
20-
__u32 len;
21-
__u8 data[1];
22-
} kaslr_setup_data;
23-
2417
#define I8254_PORT_CONTROL 0x43
2518
#define I8254_PORT_COUNTER0 0x40
2619
#define I8254_CMD_READBACK 0xC0
@@ -302,29 +295,7 @@ static unsigned long find_random_addr(unsigned long minimum,
302295
return slots_fetch_random();
303296
}
304297

305-
static void add_kaslr_setup_data(struct boot_params *params, __u8 enabled)
306-
{
307-
struct setup_data *data;
308-
309-
kaslr_setup_data.type = SETUP_KASLR;
310-
kaslr_setup_data.len = 1;
311-
kaslr_setup_data.next = 0;
312-
kaslr_setup_data.data[0] = enabled;
313-
314-
data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
315-
316-
while (data && data->next)
317-
data = (struct setup_data *)(unsigned long)data->next;
318-
319-
if (data)
320-
data->next = (unsigned long)&kaslr_setup_data;
321-
else
322-
params->hdr.setup_data = (unsigned long)&kaslr_setup_data;
323-
324-
}
325-
326-
unsigned char *choose_kernel_location(struct boot_params *params,
327-
unsigned char *input,
298+
unsigned char *choose_kernel_location(unsigned char *input,
328299
unsigned long input_size,
329300
unsigned char *output,
330301
unsigned long output_size)
@@ -335,17 +306,14 @@ unsigned char *choose_kernel_location(struct boot_params *params,
335306
#ifdef CONFIG_HIBERNATION
336307
if (!cmdline_find_option_bool("kaslr")) {
337308
debug_putstr("KASLR disabled by default...\n");
338-
add_kaslr_setup_data(params, 0);
339309
goto out;
340310
}
341311
#else
342312
if (cmdline_find_option_bool("nokaslr")) {
343313
debug_putstr("KASLR disabled by cmdline...\n");
344-
add_kaslr_setup_data(params, 0);
345314
goto out;
346315
}
347316
#endif
348-
add_kaslr_setup_data(params, 1);
349317

350318
/* Record the various known unsafe memory ranges. */
351319
mem_avoid_init((unsigned long)input, input_size,

‎arch/x86/boot/compressed/misc.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
401401
* the entire decompressed kernel plus relocation table, or the
402402
* entire decompressed kernel plus .bss and .brk sections.
403403
*/
404-
output = choose_kernel_location(real_mode, input_data, input_len,
405-
output,
404+
output = choose_kernel_location(input_data, input_len, output,
406405
output_len > run_size ? output_len
407406
: run_size);
408407

‎arch/x86/boot/compressed/misc.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,15 @@ int cmdline_find_option_bool(const char *option);
5757

5858
#if CONFIG_RANDOMIZE_BASE
5959
/* aslr.c */
60-
unsigned char *choose_kernel_location(struct boot_params *params,
61-
unsigned char *input,
60+
unsigned char *choose_kernel_location(unsigned char *input,
6261
unsigned long input_size,
6362
unsigned char *output,
6463
unsigned long output_size);
6564
/* cpuflags.c */
6665
bool has_cpuflag(int flag);
6766
#else
6867
static inline
69-
unsigned char *choose_kernel_location(struct boot_params *params,
70-
unsigned char *input,
68+
unsigned char *choose_kernel_location(unsigned char *input,
7169
unsigned long input_size,
7270
unsigned char *output,
7371
unsigned long output_size)

‎arch/x86/include/asm/page_types.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ extern int devmem_is_allowed(unsigned long pagenr);
5151
extern unsigned long max_low_pfn_mapped;
5252
extern unsigned long max_pfn_mapped;
5353

54-
extern bool kaslr_enabled;
55-
5654
static inline phys_addr_t get_max_mapped(void)
5755
{
5856
return (phys_addr_t)max_pfn_mapped << PAGE_SHIFT;

‎arch/x86/include/uapi/asm/bootparam.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#define SETUP_DTB 2
88
#define SETUP_PCI 3
99
#define SETUP_EFI 4
10-
#define SETUP_KASLR 5
1110

1211
/* ram_size flags */
1312
#define RAMDISK_IMAGE_START_MASK 0x07FF

‎arch/x86/kernel/module.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,21 @@ do { \
4747

4848
#ifdef CONFIG_RANDOMIZE_BASE
4949
static unsigned long module_load_offset;
50+
static int randomize_modules = 1;
5051

5152
/* Mutex protects the module_load_offset. */
5253
static DEFINE_MUTEX(module_kaslr_mutex);
5354

55+
static int __init parse_nokaslr(char *p)
56+
{
57+
randomize_modules = 0;
58+
return 0;
59+
}
60+
early_param("nokaslr", parse_nokaslr);
61+
5462
static unsigned long int get_module_load_offset(void)
5563
{
56-
if (kaslr_enabled) {
64+
if (randomize_modules) {
5765
mutex_lock(&module_kaslr_mutex);
5866
/*
5967
* Calculate the module_load_offset the first time this

‎arch/x86/kernel/setup.c‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@
122122
unsigned long max_low_pfn_mapped;
123123
unsigned long max_pfn_mapped;
124124

125-
bool __read_mostly kaslr_enabled = false;
126-
127125
#ifdef CONFIG_DMI
128126
RESERVE_BRK(dmi_alloc, 65536);
129127
#endif
@@ -427,11 +425,6 @@ static void __init reserve_initrd(void)
427425
}
428426
#endif /* CONFIG_BLK_DEV_INITRD */
429427

430-
static void __init parse_kaslr_setup(u64 pa_data, u32 data_len)
431-
{
432-
kaslr_enabled = (bool)(pa_data + sizeof(struct setup_data));
433-
}
434-
435428
static void __init parse_setup_data(void)
436429
{
437430
struct setup_data *data;
@@ -457,9 +450,6 @@ static void __init parse_setup_data(void)
457450
case SETUP_EFI:
458451
parse_efi_setup(pa_data, data_len);
459452
break;
460-
case SETUP_KASLR:
461-
parse_kaslr_setup(pa_data, data_len);
462-
break;
463453
default:
464454
break;
465455
}
@@ -842,14 +832,10 @@ static void __init trim_low_memory_range(void)
842832
static int
843833
dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
844834
{
845-
if (kaslr_enabled)
846-
pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n",
847-
(unsigned long)&_text - __START_KERNEL,
848-
__START_KERNEL,
849-
__START_KERNEL_map,
850-
MODULES_VADDR-1);
851-
else
852-
pr_emerg("Kernel Offset: disabled\n");
835+
pr_emerg("Kernel Offset: 0x%lx from 0x%lx "
836+
"(relocation range: 0x%lx-0x%lx)\n",
837+
(unsigned long)&_text - __START_KERNEL, __START_KERNEL,
838+
__START_KERNEL_map, MODULES_VADDR-1);
853839

854840
return 0;
855841
}

0 commit comments

Comments
 (0)