efi/x86: Fix the missing KASLR_FLAG bit in boot_params->hdr.loadflags
authorYuntao Wang <ytcoode@gmail.com>
Tue, 26 Dec 2023 14:02:50 +0000 (22:02 +0800)
committerArd Biesheuvel <ardb@kernel.org>
Tue, 2 Jan 2024 15:51:28 +0000 (16:51 +0100)
When KASLR is enabled, the KASLR_FLAG bit in boot_params->hdr.loadflags
should be set to 1 to propagate KASLR status from compressed kernel to
kernel, just as the choose_random_location() function does.

Currently, when the kernel is booted via the EFI stub, the KASLR_FLAG
bit in boot_params->hdr.loadflags is not set, even though it should be.
This causes some functions, such as kernel_randomize_memory(), not to
execute as expected. Fix it.

Fixes: a1b87d54f4e4 ("x86/efistub: Avoid legacy decompressor when doing EFI boot")
Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
[ardb: drop 'else' branch clearing KASLR_FLAG]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/libstub/x86-stub.c

index da9b7b8..0d510c9 100644 (file)
@@ -787,6 +787,8 @@ static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)
                        efi_debug("AMI firmware v2.0 or older detected - disabling physical KASLR\n");
                        seed[0] = 0;
                }
+
+               boot_params_ptr->hdr.loadflags |= KASLR_FLAG;
        }
 
        status = efi_random_alloc(alloc_size, CONFIG_PHYSICAL_ALIGN, &addr,