Skip to content

Commit 4b1c742

Browse files
mdrothsuryasaimadhu
authored andcommitted
x86/boot: Don't propagate uninitialized boot_params->cc_blob_address
In some cases, bootloaders will leave boot_params->cc_blob_address uninitialized rather than zeroing it out. This field is only meant to be set by the boot/compressed kernel in order to pass information to the uncompressed kernel when SEV-SNP support is enabled. Therefore, there are no cases where the bootloader-provided values should be treated as anything other than garbage. Otherwise, the uncompressed kernel may attempt to access this bogus address, leading to a crash during early boot. Normally, sanitize_boot_params() would be used to clear out such fields but that happens too late: sev_enable() may have already initialized it to a valid value that should not be zeroed out. Instead, have sev_enable() zero it out unconditionally beforehand. Also ensure this happens for !CONFIG_AMD_MEM_ENCRYPT as well by also including this handling in the sev_enable() stub function. [ bp: Massage commit message and comments. ] Fixes: b190a04 ("x86/sev: Add SEV-SNP feature detection/setup") Reported-by: Jeremi Piotrowski <[email protected]> Reported-by: [email protected] Signed-off-by: Michael Roth <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: [email protected] Link: https://bugzilla.kernel.org/show_bug.cgi?id=216387 Link: https://lore.kernel.org/r/[email protected]
1 parent ea902bc commit 4b1c742

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

arch/x86/boot/compressed/misc.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,17 @@ void snp_set_page_private(unsigned long paddr);
132132
void snp_set_page_shared(unsigned long paddr);
133133
void sev_prep_identity_maps(unsigned long top_level_pgt);
134134
#else
135-
static inline void sev_enable(struct boot_params *bp) { }
135+
static inline void sev_enable(struct boot_params *bp)
136+
{
137+
/*
138+
* bp->cc_blob_address should only be set by boot/compressed kernel.
139+
* Initialize it to 0 unconditionally (thus here in this stub too) to
140+
* ensure that uninitialized values from buggy bootloaders aren't
141+
* propagated.
142+
*/
143+
if (bp)
144+
bp->cc_blob_address = 0;
145+
}
136146
static inline void sev_es_shutdown_ghcb(void) { }
137147
static inline bool sev_es_check_ghcb_fault(unsigned long address)
138148
{

arch/x86/boot/compressed/sev.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ void sev_enable(struct boot_params *bp)
276276
struct msr m;
277277
bool snp;
278278

279+
/*
280+
* bp->cc_blob_address should only be set by boot/compressed kernel.
281+
* Initialize it to 0 to ensure that uninitialized values from
282+
* buggy bootloaders aren't propagated.
283+
*/
284+
if (bp)
285+
bp->cc_blob_address = 0;
286+
279287
/*
280288
* Setup/preliminary detection of SNP. This will be sanity-checked
281289
* against CPUID/MSR values later.

0 commit comments

Comments
 (0)