Skip to content

Commit 0862438

Browse files
Kiryl Shutsemau (Meta)ardbiesheuvel
authored andcommitted
efi: Fix reservation of unaccepted memory table
The reserve_unaccepted() function incorrectly calculates the size of the memblock reservation for the unaccepted memory table. It aligns the size of the table, but fails to account for cases where the table's starting physical address (efi.unaccepted) is not page-aligned. If the table starts at an offset within a page and its end crosses into a subsequent page that the aligned size does not cover, the end of the table will not be reserved. This can lead to the table being overwritten or inaccessible, causing a kernel panic in accept_memory(). This issue was observed when starting Intel TDX VMs with specific memory sizes (e.g., > 64GB). Fix this by calculating the end address first (including the unaligned start) and then aligning it up, ensuring the entire range is covered by the reservation. Fixes: 8dbe339 ("efi/unaccepted: Make sure unaccepted table is mapped") Reported-by: Moritz Sanft <ms@edgeless.systems> Signed-off-by: Kiryl Shutsemau (Meta) <kas@kernel.org> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 21279b1 commit 0862438

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • drivers/firmware/efi

drivers/firmware/efi/efi.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,13 +692,13 @@ static __init int match_config_table(const efi_guid_t *guid,
692692

693693
static __init void reserve_unaccepted(struct efi_unaccepted_memory *unaccepted)
694694
{
695-
phys_addr_t start, size;
695+
phys_addr_t start, end;
696696

697697
start = PAGE_ALIGN_DOWN(efi.unaccepted);
698-
size = PAGE_ALIGN(sizeof(*unaccepted) + unaccepted->size);
698+
end = PAGE_ALIGN(efi.unaccepted + sizeof(*unaccepted) + unaccepted->size);
699699

700-
memblock_add(start, size);
701-
memblock_reserve(start, size);
700+
memblock_add(start, end - start);
701+
memblock_reserve(start, end - start);
702702
}
703703

704704
int __init efi_config_parse_tables(const efi_config_table_t *config_tables,

0 commit comments

Comments
 (0)