diff options
author | Ingo Molnar <mingo@kernel.org> | 2015-02-19 06:06:04 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2015-02-19 06:31:34 -0500 |
commit | a267b0a349bb021c010e36a2a13e1e16657b1b0f (patch) | |
tree | 4438a10ecc864f15ce6f37c1764fffa995a9a175 /arch/x86/boot | |
parent | ee408b4207c8281a91f039e89d06de264d319466 (diff) | |
parent | 4e7c22d447bb6d7e37bfe39ff658486ae78e8d77 (diff) |
Merge branch 'tip-x86-kaslr' of git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp into x86/urgent
Pull ASLR and kASLR fixes from Borislav Petkov:
- Add a global flag announcing KASLR state so that relevant code can do
informed decisions based on its setting. (Jiri Kosina)
- Fix a stack randomization entropy decrease bug. (Hector Marco-Gisbert)
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/boot')
-rw-r--r-- | arch/x86/boot/compressed/aslr.c | 34 | ||||
-rw-r--r-- | arch/x86/boot/compressed/misc.c | 3 | ||||
-rw-r--r-- | arch/x86/boot/compressed/misc.h | 6 |
3 files changed, 39 insertions, 4 deletions
diff --git a/arch/x86/boot/compressed/aslr.c b/arch/x86/boot/compressed/aslr.c index bb1376381985..7083c16cccba 100644 --- a/arch/x86/boot/compressed/aslr.c +++ b/arch/x86/boot/compressed/aslr.c | |||
@@ -14,6 +14,13 @@ | |||
14 | static const char build_str[] = UTS_RELEASE " (" LINUX_COMPILE_BY "@" | 14 | static const char build_str[] = UTS_RELEASE " (" LINUX_COMPILE_BY "@" |
15 | LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION; | 15 | LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION; |
16 | 16 | ||
17 | struct kaslr_setup_data { | ||
18 | __u64 next; | ||
19 | __u32 type; | ||
20 | __u32 len; | ||
21 | __u8 data[1]; | ||
22 | } kaslr_setup_data; | ||
23 | |||
17 | #define I8254_PORT_CONTROL 0x43 | 24 | #define I8254_PORT_CONTROL 0x43 |
18 | #define I8254_PORT_COUNTER0 0x40 | 25 | #define I8254_PORT_COUNTER0 0x40 |
19 | #define I8254_CMD_READBACK 0xC0 | 26 | #define I8254_CMD_READBACK 0xC0 |
@@ -295,7 +302,29 @@ static unsigned long find_random_addr(unsigned long minimum, | |||
295 | return slots_fetch_random(); | 302 | return slots_fetch_random(); |
296 | } | 303 | } |
297 | 304 | ||
298 | unsigned char *choose_kernel_location(unsigned char *input, | 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, | ||
299 | unsigned long input_size, | 328 | unsigned long input_size, |
300 | unsigned char *output, | 329 | unsigned char *output, |
301 | unsigned long output_size) | 330 | unsigned long output_size) |
@@ -306,14 +335,17 @@ unsigned char *choose_kernel_location(unsigned char *input, | |||
306 | #ifdef CONFIG_HIBERNATION | 335 | #ifdef CONFIG_HIBERNATION |
307 | if (!cmdline_find_option_bool("kaslr")) { | 336 | if (!cmdline_find_option_bool("kaslr")) { |
308 | debug_putstr("KASLR disabled by default...\n"); | 337 | debug_putstr("KASLR disabled by default...\n"); |
338 | add_kaslr_setup_data(params, 0); | ||
309 | goto out; | 339 | goto out; |
310 | } | 340 | } |
311 | #else | 341 | #else |
312 | if (cmdline_find_option_bool("nokaslr")) { | 342 | if (cmdline_find_option_bool("nokaslr")) { |
313 | debug_putstr("KASLR disabled by cmdline...\n"); | 343 | debug_putstr("KASLR disabled by cmdline...\n"); |
344 | add_kaslr_setup_data(params, 0); | ||
314 | goto out; | 345 | goto out; |
315 | } | 346 | } |
316 | #endif | 347 | #endif |
348 | add_kaslr_setup_data(params, 1); | ||
317 | 349 | ||
318 | /* Record the various known unsafe memory ranges. */ | 350 | /* Record the various known unsafe memory ranges. */ |
319 | mem_avoid_init((unsigned long)input, input_size, | 351 | mem_avoid_init((unsigned long)input, input_size, |
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index a950864a64da..5903089c818f 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c | |||
@@ -401,7 +401,8 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap, | |||
401 | * the entire decompressed kernel plus relocation table, or the | 401 | * the entire decompressed kernel plus relocation table, or the |
402 | * entire decompressed kernel plus .bss and .brk sections. | 402 | * entire decompressed kernel plus .bss and .brk sections. |
403 | */ | 403 | */ |
404 | output = choose_kernel_location(input_data, input_len, output, | 404 | output = choose_kernel_location(real_mode, input_data, input_len, |
405 | output, | ||
405 | output_len > run_size ? output_len | 406 | output_len > run_size ? output_len |
406 | : run_size); | 407 | : run_size); |
407 | 408 | ||
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index 24e3e569a13c..6d6730743024 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h | |||
@@ -56,7 +56,8 @@ int cmdline_find_option_bool(const char *option); | |||
56 | 56 | ||
57 | #if CONFIG_RANDOMIZE_BASE | 57 | #if CONFIG_RANDOMIZE_BASE |
58 | /* aslr.c */ | 58 | /* aslr.c */ |
59 | unsigned char *choose_kernel_location(unsigned char *input, | 59 | unsigned char *choose_kernel_location(struct boot_params *params, |
60 | unsigned char *input, | ||
60 | unsigned long input_size, | 61 | unsigned long input_size, |
61 | unsigned char *output, | 62 | unsigned char *output, |
62 | unsigned long output_size); | 63 | unsigned long output_size); |
@@ -64,7 +65,8 @@ unsigned char *choose_kernel_location(unsigned char *input, | |||
64 | bool has_cpuflag(int flag); | 65 | bool has_cpuflag(int flag); |
65 | #else | 66 | #else |
66 | static inline | 67 | static inline |
67 | unsigned char *choose_kernel_location(unsigned char *input, | 68 | unsigned char *choose_kernel_location(struct boot_params *params, |
69 | unsigned char *input, | ||
68 | unsigned long input_size, | 70 | unsigned long input_size, |
69 | unsigned char *output, | 71 | unsigned char *output, |
70 | unsigned long output_size) | 72 | unsigned long output_size) |