Skip to content

Commit f75ff17

Browse files
nikunjadbp3tk0v
authored andcommitted
x86/sev: Handle failures from snp_init()
Address the ignored failures from snp_init() in sme_enable(). Add error handling for scenarios where snp_init() fails to retrieve the SEV-SNP CC blob or encounters issues while parsing the CC blob. Ensure that SNP guests will error out early, preventing delayed error reporting or undefined behavior. Signed-off-by: Nikunj A Dadhania <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Tom Lendacky <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f3476bc commit f75ff17

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

arch/x86/mm/mem_encrypt_identity.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,10 @@ void __head sme_enable(struct boot_params *bp)
495495
unsigned int eax, ebx, ecx, edx;
496496
unsigned long feature_mask;
497497
unsigned long me_mask;
498-
bool snp;
498+
bool snp_en;
499499
u64 msr;
500500

501-
snp = snp_init(bp);
501+
snp_en = snp_init(bp);
502502

503503
/* Check for the SME/SEV support leaf */
504504
eax = 0x80000000;
@@ -531,8 +531,11 @@ void __head sme_enable(struct boot_params *bp)
531531
RIP_REL_REF(sev_status) = msr = __rdmsr(MSR_AMD64_SEV);
532532
feature_mask = (msr & MSR_AMD64_SEV_ENABLED) ? AMD_SEV_BIT : AMD_SME_BIT;
533533

534-
/* The SEV-SNP CC blob should never be present unless SEV-SNP is enabled. */
535-
if (snp && !(msr & MSR_AMD64_SEV_SNP_ENABLED))
534+
/*
535+
* Any discrepancies between the presence of a CC blob and SNP
536+
* enablement abort the guest.
537+
*/
538+
if (snp_en ^ !!(msr & MSR_AMD64_SEV_SNP_ENABLED))
536539
snp_abort();
537540

538541
/* Check if memory encryption is enabled */

0 commit comments

Comments
 (0)