x86/sev: Fix overflow when computing address for PVALIDATE
PATCH 1/1 x86/sev: Fix overflow when computing address for PVALIDATE
The GFN in the struct used for page-state change requests is a 40-bit bit-field, so attempts to shift it by PAGE_SHIFT to get an address will result in bits getting lost if they cross the 1TB boundary. This ends up causing crashes when booting 1TB SNP guests with kernels that support lazy-acceptance (without kernel-side lazy-acceptance support, OVMF handles the PVALIDATE for GFNs in the upper address ranges, so this overflow condition is never encountered by the kernel).
Fix this by casting the 40-bit GFN field to a 64-bit type before converting it to an address.
--- arch/x86/kernel/sev-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/sev-shared.c +1 -1
@@ -1083,7 +1083,7 @@ static void pvalidate_pages(struct snp_psc_desc *desc)for (i =0 ; i <= desc->hdr.end_entry; i++) { e = &desc->entries[i]; - vaddr = (unsigned long )pfn_to_kaddr (e->gfn); + vaddr = (unsigned long )pfn_to_kaddr ((unsigned long )e->gfn); size = e->pagesize ?RMP_PG_SIZE_2M :RMP_PG_SIZE_4K ; validate = e->operation ==SNP_PAGE_STATE_PRIVATE ;
Signature · 1 line
2.25.1
arch/x86/kernel/sev-shared.c static void pvalidate_pages(struct snp_psc_desc *desc) · line 1088
Quoted 5 lines · Michael Roth
arch/x86/kernel/sev-shared.c +1
-1- vaddr = (unsigned long )pfn_to_kaddr (e->gfn); + vaddr = (unsigned long )pfn_to_kaddr ((unsigned long )e->gfn); size = e->pagesize ?RMP_PG_SIZE_2M :RMP_PG_SIZE_4K ; validate = e->operation ==SNP_PAGE_STATE_PRIVATE ;
... and people wonder why some of us avoid bitfields.
Shouldn't we just fix this permanently in pfn_to_kaddr()? Surely more of these are lurking around. Anything doing a large shift up on a little type is asking for trouble.