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

Commit a267b0a3 authored by Ingo Molnar's avatar Ingo Molnar
Browse files

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: default avatarIngo Molnar <mingo@kernel.org>
parents ee408b42 4e7c22d4
Loading
Loading
Loading
Loading
+33 −1
Original line number Diff line number Diff line
@@ -14,6 +14,13 @@
static const char build_str[] = UTS_RELEASE " (" LINUX_COMPILE_BY "@"
		LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION;

struct kaslr_setup_data {
	__u64 next;
	__u32 type;
	__u32 len;
	__u8 data[1];
} kaslr_setup_data;

#define I8254_PORT_CONTROL	0x43
#define I8254_PORT_COUNTER0	0x40
#define I8254_CMD_READBACK	0xC0
@@ -295,7 +302,29 @@ static unsigned long find_random_addr(unsigned long minimum,
	return slots_fetch_random();
}

unsigned char *choose_kernel_location(unsigned char *input,
static void add_kaslr_setup_data(struct boot_params *params, __u8 enabled)
{
	struct setup_data *data;

	kaslr_setup_data.type = SETUP_KASLR;
	kaslr_setup_data.len = 1;
	kaslr_setup_data.next = 0;
	kaslr_setup_data.data[0] = enabled;

	data = (struct setup_data *)(unsigned long)params->hdr.setup_data;

	while (data && data->next)
		data = (struct setup_data *)(unsigned long)data->next;

	if (data)
		data->next = (unsigned long)&kaslr_setup_data;
	else
		params->hdr.setup_data = (unsigned long)&kaslr_setup_data;

}

unsigned char *choose_kernel_location(struct boot_params *params,
				      unsigned char *input,
				      unsigned long input_size,
				      unsigned char *output,
				      unsigned long output_size)
@@ -306,14 +335,17 @@ unsigned char *choose_kernel_location(unsigned char *input,
#ifdef CONFIG_HIBERNATION
	if (!cmdline_find_option_bool("kaslr")) {
		debug_putstr("KASLR disabled by default...\n");
		add_kaslr_setup_data(params, 0);
		goto out;
	}
#else
	if (cmdline_find_option_bool("nokaslr")) {
		debug_putstr("KASLR disabled by cmdline...\n");
		add_kaslr_setup_data(params, 0);
		goto out;
	}
#endif
	add_kaslr_setup_data(params, 1);

	/* Record the various known unsafe memory ranges. */
	mem_avoid_init((unsigned long)input, input_size,
+2 −1
Original line number Diff line number Diff line
@@ -401,7 +401,8 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
	 * the entire decompressed kernel plus relocation table, or the
	 * entire decompressed kernel plus .bss and .brk sections.
	 */
	output = choose_kernel_location(input_data, input_len, output,
	output = choose_kernel_location(real_mode, input_data, input_len,
					output,
					output_len > run_size ? output_len
							      : run_size);

+4 −2
Original line number Diff line number Diff line
@@ -56,7 +56,8 @@ int cmdline_find_option_bool(const char *option);

#if CONFIG_RANDOMIZE_BASE
/* aslr.c */
unsigned char *choose_kernel_location(unsigned char *input,
unsigned char *choose_kernel_location(struct boot_params *params,
				      unsigned char *input,
				      unsigned long input_size,
				      unsigned char *output,
				      unsigned long output_size);
@@ -64,7 +65,8 @@ unsigned char *choose_kernel_location(unsigned char *input,
bool has_cpuflag(int flag);
#else
static inline
unsigned char *choose_kernel_location(unsigned char *input,
unsigned char *choose_kernel_location(struct boot_params *params,
				      unsigned char *input,
				      unsigned long input_size,
				      unsigned char *output,
				      unsigned long output_size)
+3 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@

#include <linux/const.h>
#include <linux/types.h>
#include <asm/bootparam.h>

/* PAGE_SHIFT determines the page size */
#define PAGE_SHIFT	12
@@ -51,6 +52,8 @@ extern int devmem_is_allowed(unsigned long pagenr);
extern unsigned long max_low_pfn_mapped;
extern unsigned long max_pfn_mapped;

extern bool kaslr_enabled;

static inline phys_addr_t get_max_mapped(void)
{
	return (phys_addr_t)max_pfn_mapped << PAGE_SHIFT;
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
#define SETUP_DTB			2
#define SETUP_PCI			3
#define SETUP_EFI			4
#define SETUP_KASLR			5

/* ram_size flags */
#define RAMDISK_IMAGE_START_MASK	0x07FF
Loading