* [PATCH] x86/efistub: fix the missing KASLR_FLAG bit in boot_params->hdr.loadflags
@ 2023-12-26 14:02 Yuntao Wang
2024-01-02 15:29 ` Ard Biesheuvel
0 siblings, 1 reply; 4+ messages in thread
From: Yuntao Wang @ 2023-12-26 14:02 UTC (permalink / raw)
To: linux-efi, linux-kernel
Cc: Ard Biesheuvel, Borislav Petkov (AMD), Kirill A. Shutemov,
Tom Lendacky, Ingo Molnar, Dionna Glaze, Nikolay Borisov,
Yuntao Wang
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 kernel is booted via 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.
Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
---
drivers/firmware/efi/libstub/x86-stub.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index da9b7b8d0716..b0c68593ad40 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -787,7 +787,10 @@ 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;
+ } else
+ boot_params_ptr->hdr.loadflags &= ~KASLR_FLAG;
status = efi_random_alloc(alloc_size, CONFIG_PHYSICAL_ALIGN, &addr,
seed[0], EFI_LOADER_CODE,
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] x86/efistub: fix the missing KASLR_FLAG bit in boot_params->hdr.loadflags
2023-12-26 14:02 [PATCH] x86/efistub: fix the missing KASLR_FLAG bit in boot_params->hdr.loadflags Yuntao Wang
@ 2024-01-02 15:29 ` Ard Biesheuvel
2024-01-02 16:26 ` Tom Lendacky
0 siblings, 1 reply; 4+ messages in thread
From: Ard Biesheuvel @ 2024-01-02 15:29 UTC (permalink / raw)
To: Yuntao Wang
Cc: linux-efi, linux-kernel, Borislav Petkov (AMD),
Kirill A. Shutemov, Tom Lendacky, Ingo Molnar, Dionna Glaze,
Nikolay Borisov
On Tue, 26 Dec 2023 at 15:03, Yuntao Wang <ytcoode@gmail.com> wrote:
>
> 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 kernel is booted via 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.
>
> Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
> ---
> drivers/firmware/efi/libstub/x86-stub.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
> index da9b7b8d0716..b0c68593ad40 100644
> --- a/drivers/firmware/efi/libstub/x86-stub.c
> +++ b/drivers/firmware/efi/libstub/x86-stub.c
> @@ -787,7 +787,10 @@ 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;
> + } else
> + boot_params_ptr->hdr.loadflags &= ~KASLR_FLAG;
>
Thanks for the fix.
I'll queue this up right away, but I am going to drop the 'else' part,
given that the KASLR flag is never set by the EFI stub so clearing it
should never be needed.
> status = efi_random_alloc(alloc_size, CONFIG_PHYSICAL_ALIGN, &addr,
> seed[0], EFI_LOADER_CODE,
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] x86/efistub: fix the missing KASLR_FLAG bit in boot_params->hdr.loadflags
2024-01-02 15:29 ` Ard Biesheuvel
@ 2024-01-02 16:26 ` Tom Lendacky
2024-01-02 16:26 ` Ard Biesheuvel
0 siblings, 1 reply; 4+ messages in thread
From: Tom Lendacky @ 2024-01-02 16:26 UTC (permalink / raw)
To: Ard Biesheuvel, Yuntao Wang
Cc: linux-efi, linux-kernel, Borislav Petkov (AMD),
Kirill A. Shutemov, Ingo Molnar, Dionna Glaze, Nikolay Borisov
On 1/2/24 09:29, Ard Biesheuvel wrote:
> On Tue, 26 Dec 2023 at 15:03, Yuntao Wang <ytcoode@gmail.com> wrote:
>>
>> 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 kernel is booted via 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.
>>
>> Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
>> ---
>> drivers/firmware/efi/libstub/x86-stub.c | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
>> index da9b7b8d0716..b0c68593ad40 100644
>> --- a/drivers/firmware/efi/libstub/x86-stub.c
>> +++ b/drivers/firmware/efi/libstub/x86-stub.c
>> @@ -787,7 +787,10 @@ 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;
>> + } else
>> + boot_params_ptr->hdr.loadflags &= ~KASLR_FLAG;
>>
>
> Thanks for the fix.
Does it need a Fixes: tag?
Thanks,
Tom
>
> I'll queue this up right away, but I am going to drop the 'else' part,
> given that the KASLR flag is never set by the EFI stub so clearing it
> should never be needed.
>
>
>> status = efi_random_alloc(alloc_size, CONFIG_PHYSICAL_ALIGN, &addr,
>> seed[0], EFI_LOADER_CODE,
>> --
>> 2.43.0
>>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] x86/efistub: fix the missing KASLR_FLAG bit in boot_params->hdr.loadflags
2024-01-02 16:26 ` Tom Lendacky
@ 2024-01-02 16:26 ` Ard Biesheuvel
0 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2024-01-02 16:26 UTC (permalink / raw)
To: Tom Lendacky
Cc: Yuntao Wang, linux-efi, linux-kernel, Borislav Petkov (AMD),
Kirill A. Shutemov, Ingo Molnar, Dionna Glaze, Nikolay Borisov
On Tue, 2 Jan 2024 at 17:26, Tom Lendacky <thomas.lendacky@amd.com> wrote:
>
> On 1/2/24 09:29, Ard Biesheuvel wrote:
> > On Tue, 26 Dec 2023 at 15:03, Yuntao Wang <ytcoode@gmail.com> wrote:
> >>
> >> 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 kernel is booted via 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.
> >>
> >> Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
> >> ---
> >> drivers/firmware/efi/libstub/x86-stub.c | 5 ++++-
> >> 1 file changed, 4 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
> >> index da9b7b8d0716..b0c68593ad40 100644
> >> --- a/drivers/firmware/efi/libstub/x86-stub.c
> >> +++ b/drivers/firmware/efi/libstub/x86-stub.c
> >> @@ -787,7 +787,10 @@ 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;
> >> + } else
> >> + boot_params_ptr->hdr.loadflags &= ~KASLR_FLAG;
> >>
> >
> > Thanks for the fix.
>
> Does it need a Fixes: tag?
>
Yes, I've added that.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-01-02 16:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-26 14:02 [PATCH] x86/efistub: fix the missing KASLR_FLAG bit in boot_params->hdr.loadflags Yuntao Wang
2024-01-02 15:29 ` Ard Biesheuvel
2024-01-02 16:26 ` Tom Lendacky
2024-01-02 16:26 ` Ard Biesheuvel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox