TianoCore EDK2 master
|
#include <PiDxe.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiLib.h>
#include <Library/ImagePropertiesRecordLib.h>
#include <Guid/EventGroup.h>
#include <Guid/MemoryAttributesTable.h>
#include <Protocol/FirmwareVolume2.h>
#include <Protocol/SimpleFileSystem.h>
#include "DxeMain.h"
#include "Mem/HeapGuard.h"
Go to the source code of this file.
Macros | |
#define | IMAGE_UNKNOWN 0x00000001 |
#define | IMAGE_FROM_FV 0x00000002 |
#define | DO_NOT_PROTECT 0x00000000 |
#define | PROTECT_IF_ALIGNED_ELSE_ALLOW 0x00000001 |
#define | MEMORY_TYPE_OS_RESERVED_MIN 0x80000000 |
#define | MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000 |
#define | PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size))) |
Variables | |
UINT32 | mImageProtectionPolicy |
LIST_ENTRY | mGcdMemorySpaceMap |
STATIC LIST_ENTRY | mProtectedImageRecordList |
UEFI Memory Protection support.
If the UEFI image is page aligned, the image code section is set to read only and the image data section is set to non-executable.
1) This policy is applied for all UEFI image including boot service driver, runtime driver or application. 2) This policy is applied only if the UEFI image meets the page alignment requirement. 3) This policy is applied only if the Source UEFI image matches the PcdImageProtectionPolicy definition. 4) This policy is not applied to the non-PE image region.
The DxeCore calls CpuArchProtocol->SetMemoryAttributes() to protect the image. If the CpuArch protocol is not installed yet, the DxeCore enqueues the protection request. Once the CpuArch is installed, the DxeCore dequeues the protection request and applies policy.
Once the image is unloaded, the protection is removed automatically.
Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file MemoryProtection.c.
#define DO_NOT_PROTECT 0x00000000 |
Definition at line 55 of file MemoryProtection.c.
#define IMAGE_FROM_FV 0x00000002 |
Definition at line 50 of file MemoryProtection.c.
#define IMAGE_UNKNOWN 0x00000001 |
Definition at line 49 of file MemoryProtection.c.
#define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000 |
Definition at line 59 of file MemoryProtection.c.
#define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000 |
Definition at line 58 of file MemoryProtection.c.
#define PREVIOUS_MEMORY_DESCRIPTOR | ( | MemoryDescriptor, | |
Size | |||
) | ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size))) |
Definition at line 61 of file MemoryProtection.c.
#define PROTECT_IF_ALIGNED_ELSE_ALLOW 0x00000001 |
Definition at line 56 of file MemoryProtection.c.
EFI_STATUS EFIAPI ApplyMemoryProtectionPolicy | ( | IN EFI_MEMORY_TYPE | OldType, |
IN EFI_MEMORY_TYPE | NewType, | ||
IN EFI_PHYSICAL_ADDRESS | Memory, | ||
IN UINT64 | Length | ||
) |
Manage memory permission attributes on a memory range, according to the configured DXE memory protection policy.
OldType | The old memory type of the range |
NewType | The new memory type of the range |
Memory | The base address of the range |
Length | The size of the range (in bytes) |
Definition at line 1035 of file MemoryProtection.c.
VOID EFIAPI CoreInitializeMemoryProtection | ( | VOID | ) |
Initialize Memory Protection support.
Definition at line 931 of file MemoryProtection.c.
VOID EFIAPI DisableNullDetectionAtTheEndOfDxe | ( | EFI_EVENT | Event, |
VOID * | Context | ||
) |
Disable NULL pointer detection after EndOfDxe. This is a workaround resort in order to skip unfixable NULL pointer access issues detected in OptionROM or boot loaders.
[in] | Event | The Event this notify function registered to. |
[in] | Context | Pointer to the context data registered to the Event. |
Definition at line 884 of file MemoryProtection.c.
UINT32 GetImageType | ( | IN CONST EFI_DEVICE_PATH_PROTOCOL * | File | ) |
Get the image type.
[in] | File | This is a pointer to the device path of the file that is being dispatched. |
Definition at line 79 of file MemoryProtection.c.
STATIC UINT32 GetMemoryProtectionSectionAlignment | ( | IN EFI_MEMORY_TYPE | MemoryType | ) |
Return the section alignment requirement for the PE image section type.
[in] | MemoryType | PE/COFF image memory type |
The | required section alignment for this memory type |
Definition at line 293 of file MemoryProtection.c.
STATIC UINT64 GetPermissionAttributeForMemoryType | ( | IN EFI_MEMORY_TYPE | MemoryType | ) |
Return the EFI memory permission attribute associated with memory type 'MemoryType' under the configured DXE memory protection policy.
MemoryType | Memory type. |
Definition at line 440 of file MemoryProtection.c.
UINT32 GetProtectionPolicyFromImageType | ( | IN UINT32 | ImageType | ) |
Get UEFI image protection policy based upon image type.
[in] | ImageType | The UEFI image type |
Definition at line 126 of file MemoryProtection.c.
UINT32 GetUefiImageProtectionPolicy | ( | IN EFI_LOADED_IMAGE_PROTOCOL * | LoadedImage, |
IN EFI_DEVICE_PATH_PROTOCOL * | LoadedImageDevicePath | ||
) |
Get UEFI image protection policy based upon loaded image device path.
[in] | LoadedImage | The loaded image protocol |
[in] | LoadedImageDevicePath | The loaded image device path protocol |
Definition at line 146 of file MemoryProtection.c.
STATIC VOID InitializeDxeNxMemoryProtectionPolicy | ( | VOID | ) |
Remove exec permissions from all regions whose type is identified by PcdDxeNxMemoryProtectionPolicy.
Definition at line 572 of file MemoryProtection.c.
STATIC BOOLEAN IsInSmm | ( | VOID | ) |
Returns whether we are currently executing in SMM mode.
Definition at line 1002 of file MemoryProtection.c.
A notification for CPU_ARCH protocol.
[in] | Event | Event whose notification function is being invoked. |
[in] | Context | Pointer to the notification function's context, which is implementation-dependent. |
Definition at line 773 of file MemoryProtection.c.
VOID MemoryProtectionExitBootServicesCallback | ( | VOID | ) |
ExitBootServices Callback function for memory protection.
Definition at line 850 of file MemoryProtection.c.
STATIC VOID MergeMemoryMapForProtectionPolicy | ( | IN OUT EFI_MEMORY_DESCRIPTOR * | MemoryMap, |
IN OUT UINTN * | MemoryMapSize, | ||
IN UINTN | DescriptorSize | ||
) |
Merge adjacent memory map entries if they use the same memory protection policy
[in,out] | MemoryMap | A pointer to the buffer in which firmware places the current memory map. |
[in,out] | MemoryMapSize | A pointer to the size, in bytes, of the MemoryMap buffer. On input, this is the size of the current memory map. On output, it is the size of new memory map after merge. |
[in] | DescriptorSize | Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR. |
Definition at line 514 of file MemoryProtection.c.
VOID ProtectUefiImage | ( | IN EFI_LOADED_IMAGE_PROTOCOL * | LoadedImage, |
IN EFI_DEVICE_PATH_PROTOCOL * | LoadedImageDevicePath | ||
) |
Protect UEFI PE/COFF image.
[in] | LoadedImage | The loaded image protocol |
[in] | LoadedImageDevicePath | The loaded image device path protocol |
Definition at line 330 of file MemoryProtection.c.
Set UEFI image memory attributes.
[in] | BaseAddress | Specified start address |
[in] | Length | Specified length |
[in] | Attributes | Specified attributes |
Definition at line 188 of file MemoryProtection.c.
VOID SetUefiImageProtectionAttributes | ( | IN IMAGE_PROPERTIES_RECORD * | ImageRecord | ) |
Set UEFI image protection attributes.
[in] | ImageRecord | A UEFI image record |
Definition at line 215 of file MemoryProtection.c.
STATIC VOID SortMemoryMap | ( | IN OUT EFI_MEMORY_DESCRIPTOR * | MemoryMap, |
IN UINTN | MemoryMapSize, | ||
IN UINTN | DescriptorSize | ||
) |
Sort memory map entries based upon PhysicalStart, from low to high.
MemoryMap | A pointer to the buffer in which firmware places the current memory map. |
MemoryMapSize | Size, in bytes, of the MemoryMap buffer. |
DescriptorSize | Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR. |
Definition at line 471 of file MemoryProtection.c.
VOID UnprotectUefiImage | ( | IN EFI_LOADED_IMAGE_PROTOCOL * | LoadedImage, |
IN EFI_DEVICE_PATH_PROTOCOL * | LoadedImageDevicePath | ||
) |
Unprotect UEFI image.
[in] | LoadedImage | The loaded image protocol |
[in] | LoadedImageDevicePath | The loaded image device path protocol |
Definition at line 399 of file MemoryProtection.c.
|
extern |
UINT32 mImageProtectionPolicy |
Definition at line 64 of file MemoryProtection.c.
STATIC LIST_ENTRY mProtectedImageRecordList |
Definition at line 68 of file MemoryProtection.c.