linux-stable/arch/x86
Kevin Loughlin df84d9f779 x86/sev: Skip ROM range scans and validation for SEV-SNP guests
commit 0f4a1e8098 upstream.

SEV-SNP requires encrypted memory to be validated before access.
Because the ROM memory range is not part of the e820 table, it is not
pre-validated by the BIOS. Therefore, if a SEV-SNP guest kernel wishes
to access this range, the guest must first validate the range.

The current SEV-SNP code does indeed scan the ROM range during early
boot and thus attempts to validate the ROM range in probe_roms().
However, this behavior is neither sufficient nor necessary for the
following reasons:

* With regards to sufficiency, if EFI_CONFIG_TABLES are not enabled and
  CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK is set, the kernel will
  attempt to access the memory at SMBIOS_ENTRY_POINT_SCAN_START (which
  falls in the ROM range) prior to validation.

  For example, Project Oak Stage 0 provides a minimal guest firmware
  that currently meets these configuration conditions, meaning guests
  booting atop Oak Stage 0 firmware encounter a problematic call chain
  during dmi_setup() -> dmi_scan_machine() that results in a crash
  during boot if SEV-SNP is enabled.

* With regards to necessity, SEV-SNP guests generally read garbage
  (which changes across boots) from the ROM range, meaning these scans
  are unnecessary. The guest reads garbage because the legacy ROM range
  is unencrypted data but is accessed via an encrypted PMD during early
  boot (where the PMD is marked as encrypted due to potentially mapping
  actually-encrypted data in other PMD-contained ranges).

In one exceptional case, EISA probing treats the ROM range as
unencrypted data, which is inconsistent with other probing.

Continuing to allow SEV-SNP guests to use garbage and to inconsistently
classify ROM range encryption status can trigger undesirable behavior.
For instance, if garbage bytes appear to be a valid signature, memory
may be unnecessarily reserved for the ROM range. Future code or other
use cases may result in more problematic (arbitrary) behavior that
should be avoided.

While one solution would be to overhaul the early PMD mapping to always
treat the ROM region of the PMD as unencrypted, SEV-SNP guests do not
currently rely on data from the ROM region during early boot (and even
if they did, they would be mostly relying on garbage data anyways).

As a simpler solution, skip the ROM range scans (and the otherwise-
necessary range validation) during SEV-SNP guest early boot. The
potential SEV-SNP guest crash due to lack of ROM range validation is
thus avoided by simply not accessing the ROM range.

In most cases, skip the scans by overriding problematic x86_init
functions during sme_early_init() to SNP-safe variants, which can be
likened to x86_init overrides done for other platforms (ex: Xen); such
overrides also avoid the spread of cc_platform_has() checks throughout
the tree.

In the exceptional EISA case, still use cc_platform_has() for the
simplest change, given (1) checks for guest type (ex: Xen domain status)
are already performed here, and (2) these checks occur in a subsys
initcall instead of an x86_init function.

  [ bp: Massage commit message, remove "we"s. ]

Fixes: 9704c07bf9 ("x86/kernel: Validate ROM memory before accessing when SEV-SNP is active")
Signed-off-by: Kevin Loughlin <kevinloughlin@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Cc: <stable@kernel.org>
Link: https://lore.kernel.org/r/20240313121546.2964854-1-kevinloughlin@google.com
Signed-off-by: Kevin Loughlin <kevinloughlin@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-03 15:19:55 +02:00
..
boot x86/efistub: Add missing boot_params for mixed mode compat entry 2024-04-03 15:19:47 +02:00
coco x86/sev: Fix position dependent variable references in startup code 2024-04-03 15:19:47 +02:00
configs
crypto crypto: x86/sha - load modules based on CPU features 2023-11-28 17:07:07 +00:00
entry x86/entry_32: Add VERW just before userspace transition 2024-03-06 14:45:20 +00:00
events perf/x86/amd/core: Avoid register reset when CPU is dead 2024-03-26 18:20:56 -04:00
hyperv x86/hyperv: Fix the detection of E820_TYPE_PRAM in a Gen2 VM 2023-12-20 17:00:21 +01:00
ia32
include x86/sev: Skip ROM range scans and validation for SEV-SNP guests 2024-04-03 15:19:55 +02:00
kernel x86/sev: Skip ROM range scans and validation for SEV-SNP guests 2024-04-03 15:19:55 +02:00
kvm KVM: SVM: Flush pages under kvm->lock to fix UAF in svm_register_enc_region() 2024-04-03 15:19:40 +02:00
lib x86/lib: Fix overflow when counting digits 2024-01-25 15:27:18 -08:00
math-emu
mm x86/sev: Skip ROM range scans and validation for SEV-SNP guests 2024-04-03 15:19:55 +02:00
net x86/returnthunk: Allow different return thunks 2024-03-01 13:26:33 +01:00
pci x86/pci/xen: populate MSI sysfs entries 2023-05-30 14:03:22 +01:00
platform x86/efi: Make efi_set_virtual_address_map IBT safe 2023-07-19 16:21:45 +02:00
power x86/pm: Add enumeration check before spec MSRs save/restore setup 2022-11-21 14:16:16 +01:00
purgatory x86/purgatory: Remove LTO flags 2023-09-23 11:11:09 +02:00
ras
realmode x86/boot: Skip realmode init code when running as Xen PV guest 2022-12-31 13:32:16 +01:00
tools x86, relocs: Ignore relocations in .notes section 2024-03-26 18:20:39 -04:00
um x86: um: vdso: Add '%rcx' and '%r11' to the syscall clobber list 2023-03-11 13:55:22 +01:00
video
virt/vmx/tdx
xen x86/xen: Add some null pointer checking to smp.c 2024-03-26 18:20:24 -04:00
.gitignore
Kbuild
Kconfig x86/Kconfig: Remove CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT 2024-04-03 15:19:47 +02:00
Kconfig.assembler
Kconfig.cpu x86/Kconfig: Transmeta Crusoe is CPU family 5, not 6 2024-02-23 09:12:43 +01:00
Kconfig.debug
Makefile x86/build: Move '-mindirect-branch-cs-prefix' out of GCC-only block 2023-02-09 11:28:13 +01:00
Makefile.um um: Only disable SSE on clang to work around old GCC bugs 2023-05-01 08:26:27 +09:00
Makefile_32.cpu