|
@@ -80,16 +80,25 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
|
|
|
kernel_memsize = kernel_size + (_end - _edata);
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && phys_seed != 0) {
|
|
|
+ /*
|
|
|
+ * If CONFIG_DEBUG_ALIGN_RODATA is not set, produce a
|
|
|
+ * displacement in the interval [0, MIN_KIMG_ALIGN) that
|
|
|
+ * is a multiple of the minimal segment alignment (SZ_64K)
|
|
|
+ */
|
|
|
+ u32 mask = (MIN_KIMG_ALIGN - 1) & ~(SZ_64K - 1);
|
|
|
+ u32 offset = !IS_ENABLED(CONFIG_DEBUG_ALIGN_RODATA) ?
|
|
|
+ (phys_seed >> 32) & mask : TEXT_OFFSET;
|
|
|
+
|
|
|
/*
|
|
|
* If KASLR is enabled, and we have some randomness available,
|
|
|
* locate the kernel at a randomized offset in physical memory.
|
|
|
*/
|
|
|
- *reserve_size = kernel_memsize + TEXT_OFFSET;
|
|
|
+ *reserve_size = kernel_memsize + offset;
|
|
|
status = efi_random_alloc(sys_table_arg, *reserve_size,
|
|
|
MIN_KIMG_ALIGN, reserve_addr,
|
|
|
- phys_seed);
|
|
|
+ (u32)phys_seed);
|
|
|
|
|
|
- *image_addr = *reserve_addr + TEXT_OFFSET;
|
|
|
+ *image_addr = *reserve_addr + offset;
|
|
|
} else {
|
|
|
/*
|
|
|
* Else, try a straight allocation at the preferred offset.
|