Skip to content

Commit

Permalink
x86/kernel: Validate ROM memory before accessing when SEV-SNP is active
Browse files Browse the repository at this point in the history
probe_roms() accesses the memory range (0xc0000 - 0x10000) to probe
various ROMs. The memory range is not part of the E820 system RAM range.
The memory range is mapped as private (i.e encrypted) in the page table.

When SEV-SNP is active, all the private memory must be validated before
accessing. The ROM range was not part of E820 map, so the guest BIOS
did not validate it. An access to invalidated memory will cause a
exception yet, so validate the ROM memory regions before it is accessed.

  [ bp: Massage commit message. ]

Signed-off-by: Brijesh Singh <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
codomania authored and suryasaimadhu committed Apr 6, 2022
1 parent efac0ee commit 9704c07
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion arch/x86/kernel/probe_roms.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <asm/sections.h>
#include <asm/io.h>
#include <asm/setup_arch.h>
#include <asm/sev.h>

static struct resource system_rom_resource = {
.name = "System ROM",
Expand Down Expand Up @@ -197,11 +198,21 @@ static int __init romchecksum(const unsigned char *rom, unsigned long length)

void __init probe_roms(void)
{
const unsigned char *rom;
unsigned long start, length, upper;
const unsigned char *rom;
unsigned char c;
int i;

/*
* The ROM memory range is not part of the e820 table and is therefore not
* pre-validated by BIOS. The kernel page table maps the ROM region as encrypted
* memory, and SNP requires encrypted memory to be validated before access.
* Do that here.
*/
snp_prep_memory(video_rom_resource.start,
((system_rom_resource.end + 1) - video_rom_resource.start),
SNP_PAGE_STATE_PRIVATE);

/* video rom */
upper = adapter_rom_resources[0].start;
for (start = video_rom_resource.start; start < upper; start += 2048) {
Expand Down

0 comments on commit 9704c07

Please sign in to comment.