From: Yuntao Wang <ytcoode@gmail.com>
To: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
"Borislav Petkov (AMD)" <bp@alien8.de>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
Ingo Molnar <mingo@kernel.org>,
Dionna Glaze <dionnaglaze@google.com>,
Nikolay Borisov <nik.borisov@suse.com>,
Yuntao Wang <ytcoode@gmail.com>
Subject: [PATCH] x86/efistub: fix the missing KASLR_FLAG bit in boot_params->hdr.loadflags
Date: Tue, 26 Dec 2023 22:02:50 +0800 [thread overview]
Message-ID: <20231226140250.224516-1-ytcoode@gmail.com> (raw)
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
next reply other threads:[~2023-12-26 14:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-26 14:02 Yuntao Wang [this message]
2024-01-02 15:29 ` [PATCH] x86/efistub: fix the missing KASLR_FLAG bit in boot_params->hdr.loadflags Ard Biesheuvel
2024-01-02 16:26 ` Tom Lendacky
2024-01-02 16:26 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231226140250.224516-1-ytcoode@gmail.com \
--to=ytcoode@gmail.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dionnaglaze@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=nik.borisov@suse.com \
--cc=thomas.lendacky@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox