If OVMF was built with -D SMM_REQUIRE, that implies that the runtime OS is not trusted and we should defend against it tampering with the firmware's data. One such datum is the PEI firmware volume (PEIFV). Normally PEIFV is decompressed on the first boot by SEC, then the OS preserves it across S3 suspend-resume cycles; at S3 resume SEC just reuses the originally decompressed PEIFV. However, if we don't trust the OS, then SEC must decompress PEIFV from the pristine flash every time, lest we execute OS-injected code or work with OS-injected data. Due to how FVMAIN_COMPACT is organized, we can't decompress just PEIFV; the decompression brings DXEFV with itself, plus it uses a temporary output buffer and a scratch buffer too, which even reach above the end of the finally installed DXEFV. For this reason we must keep away a non-malicious OS from DXEFV too, plus the memory up to PcdOvmfDecomprScratchEnd. The delay introduced by the LZMA decompression on S3 resume is negligible. If -D SMM_REQUIRE is not specified, then PcdSmmSmramRequire remains FALSE (from the DEC file), and then this patch has no effect (not counting some changed debug messages). If QEMU doesn't support S3 (or the user disabled it on the QEMU command line), then this patch has no effect also. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19037 6f19259b-4bc3-4df7-8a09-765794883524
101 lines
2.7 KiB
C
101 lines
2.7 KiB
C
/** @file
|
|
Build FV related hobs for platform.
|
|
|
|
Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
|
|
This program and the accompanying materials
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
**/
|
|
|
|
#include "PiPei.h"
|
|
#include "Platform.h"
|
|
#include <Library/DebugLib.h>
|
|
#include <Library/HobLib.h>
|
|
#include <Library/PeiServicesLib.h>
|
|
#include <Library/PcdLib.h>
|
|
|
|
|
|
/**
|
|
Publish PEI & DXE (Decompressed) Memory based FVs to let PEI
|
|
and DXE know about them.
|
|
|
|
@retval EFI_SUCCESS Platform PEI FVs were initialized successfully.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
PeiFvInitialization (
|
|
VOID
|
|
)
|
|
{
|
|
BOOLEAN SecureS3Needed;
|
|
|
|
DEBUG ((EFI_D_INFO, "Platform PEI Firmware Volume Initialization\n"));
|
|
|
|
//
|
|
// Create a memory allocation HOB for the PEI FV.
|
|
//
|
|
// Allocate as ACPI NVS is S3 is supported
|
|
//
|
|
BuildMemoryAllocationHob (
|
|
PcdGet32 (PcdOvmfPeiMemFvBase),
|
|
PcdGet32 (PcdOvmfPeiMemFvSize),
|
|
mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData
|
|
);
|
|
|
|
//
|
|
// Let DXE know about the DXE FV
|
|
//
|
|
BuildFvHob (PcdGet32 (PcdOvmfDxeMemFvBase), PcdGet32 (PcdOvmfDxeMemFvSize));
|
|
|
|
SecureS3Needed = mS3Supported && FeaturePcdGet (PcdSmmSmramRequire);
|
|
|
|
//
|
|
// Create a memory allocation HOB for the DXE FV.
|
|
//
|
|
// If "secure" S3 is needed, then SEC will decompress both PEI and DXE
|
|
// firmware volumes at S3 resume too, hence we need to keep away the OS from
|
|
// DXEFV as well. Otherwise we only need to keep away DXE itself from the
|
|
// DXEFV area.
|
|
//
|
|
BuildMemoryAllocationHob (
|
|
PcdGet32 (PcdOvmfDxeMemFvBase),
|
|
PcdGet32 (PcdOvmfDxeMemFvSize),
|
|
SecureS3Needed ? EfiACPIMemoryNVS : EfiBootServicesData
|
|
);
|
|
|
|
//
|
|
// Additionally, said decompression will use temporary memory above the end
|
|
// of DXEFV, so let's keep away the OS from there too.
|
|
//
|
|
if (SecureS3Needed) {
|
|
UINT32 DxeMemFvEnd;
|
|
|
|
DxeMemFvEnd = PcdGet32 (PcdOvmfDxeMemFvBase) +
|
|
PcdGet32 (PcdOvmfDxeMemFvSize);
|
|
BuildMemoryAllocationHob (
|
|
DxeMemFvEnd,
|
|
PcdGet32 (PcdOvmfDecompressionScratchEnd) - DxeMemFvEnd,
|
|
EfiACPIMemoryNVS
|
|
);
|
|
}
|
|
|
|
//
|
|
// Let PEI know about the DXE FV so it can find the DXE Core
|
|
//
|
|
PeiServicesInstallFvInfoPpi (
|
|
NULL,
|
|
(VOID *)(UINTN) PcdGet32 (PcdOvmfDxeMemFvBase),
|
|
PcdGet32 (PcdOvmfDxeMemFvSize),
|
|
NULL,
|
|
NULL
|
|
);
|
|
|
|
return EFI_SUCCESS;
|
|
}
|
|
|