MdeModulePkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the MdeModulePkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:02 -08:00
committed by mergify[bot]
parent 7c7184e201
commit 1436aea4d5
994 changed files with 107608 additions and 101311 deletions

View File

@@ -8,24 +8,22 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Variable.h"
//
// Module globals
//
EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpi = {
EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpi = {
PeiGetVariable,
PeiGetNextVariableName
};
EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = {
EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiReadOnlyVariable2PpiGuid,
&mVariablePpi
};
/**
Provide the functionality of the variable services.
@@ -39,8 +37,8 @@ EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = {
EFI_STATUS
EFIAPI
PeimInitializeVariableServices (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
return PeiServicesInstallPpi (&mPpiListVariable);
@@ -57,16 +55,15 @@ PeimInitializeVariableServices (
**/
VARIABLE_HEADER *
GetStartPointer (
IN VARIABLE_STORE_HEADER *VarStoreHeader
IN VARIABLE_STORE_HEADER *VarStoreHeader
)
{
//
// The start of variable store
//
return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1);
return (VARIABLE_HEADER *)HEADER_ALIGN (VarStoreHeader + 1);
}
/**
Gets the pointer to the end of the variable storage area.
@@ -81,16 +78,15 @@ GetStartPointer (
**/
VARIABLE_HEADER *
GetEndPointer (
IN VARIABLE_STORE_HEADER *VarStoreHeader
IN VARIABLE_STORE_HEADER *VarStoreHeader
)
{
//
// The end of variable store
//
return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size);
return (VARIABLE_HEADER *)HEADER_ALIGN ((UINTN)VarStoreHeader + VarStoreHeader->Size);
}
/**
This code checks if variable header is valid or not.
@@ -102,10 +98,10 @@ GetEndPointer (
**/
BOOLEAN
IsValidVariableHeader (
IN VARIABLE_HEADER *Variable
IN VARIABLE_HEADER *Variable
)
{
if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) {
if ((Variable == NULL) || (Variable->StartId != VARIABLE_DATA)) {
return FALSE;
}
@@ -122,10 +118,10 @@ IsValidVariableHeader (
**/
UINTN
GetVariableHeaderSize (
IN BOOLEAN AuthFlag
IN BOOLEAN AuthFlag
)
{
UINTN Value;
UINTN Value;
if (AuthFlag) {
Value = sizeof (AUTHENTICATED_VARIABLE_HEADER);
@@ -147,33 +143,36 @@ GetVariableHeaderSize (
**/
UINTN
NameSizeOfVariable (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFlag
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFlag
)
{
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable;
if (AuthFlag) {
if (AuthVariable->State == (UINT8) (-1) ||
AuthVariable->DataSize == (UINT32) (-1) ||
AuthVariable->NameSize == (UINT32) (-1) ||
AuthVariable->Attributes == (UINT32) (-1)) {
if ((AuthVariable->State == (UINT8)(-1)) ||
(AuthVariable->DataSize == (UINT32)(-1)) ||
(AuthVariable->NameSize == (UINT32)(-1)) ||
(AuthVariable->Attributes == (UINT32)(-1)))
{
return 0;
}
return (UINTN) AuthVariable->NameSize;
return (UINTN)AuthVariable->NameSize;
} else {
if (Variable->State == (UINT8) (-1) ||
Variable->DataSize == (UINT32) (-1) ||
Variable->NameSize == (UINT32) (-1) ||
Variable->Attributes == (UINT32) (-1)) {
if ((Variable->State == (UINT8)(-1)) ||
(Variable->DataSize == (UINT32)(-1)) ||
(Variable->NameSize == (UINT32)(-1)) ||
(Variable->Attributes == (UINT32)(-1)))
{
return 0;
}
return (UINTN) Variable->NameSize;
return (UINTN)Variable->NameSize;
}
}
/**
This code gets the size of data of variable.
@@ -185,29 +184,33 @@ NameSizeOfVariable (
**/
UINTN
DataSizeOfVariable (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFlag
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFlag
)
{
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable;
if (AuthFlag) {
if (AuthVariable->State == (UINT8) (-1) ||
AuthVariable->DataSize == (UINT32) (-1) ||
AuthVariable->NameSize == (UINT32) (-1) ||
AuthVariable->Attributes == (UINT32) (-1)) {
if ((AuthVariable->State == (UINT8)(-1)) ||
(AuthVariable->DataSize == (UINT32)(-1)) ||
(AuthVariable->NameSize == (UINT32)(-1)) ||
(AuthVariable->Attributes == (UINT32)(-1)))
{
return 0;
}
return (UINTN) AuthVariable->DataSize;
return (UINTN)AuthVariable->DataSize;
} else {
if (Variable->State == (UINT8) (-1) ||
Variable->DataSize == (UINT32) (-1) ||
Variable->NameSize == (UINT32) (-1) ||
Variable->Attributes == (UINT32) (-1)) {
if ((Variable->State == (UINT8)(-1)) ||
(Variable->DataSize == (UINT32)(-1)) ||
(Variable->NameSize == (UINT32)(-1)) ||
(Variable->Attributes == (UINT32)(-1)))
{
return 0;
}
return (UINTN) Variable->DataSize;
return (UINTN)Variable->DataSize;
}
}
@@ -222,11 +225,11 @@ DataSizeOfVariable (
**/
CHAR16 *
GetVariableNamePtr (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFlag
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFlag
)
{
return (CHAR16 *) ((UINTN) Variable + GetVariableHeaderSize (AuthFlag));
return (CHAR16 *)((UINTN)Variable + GetVariableHeaderSize (AuthFlag));
}
/**
@@ -240,13 +243,13 @@ GetVariableNamePtr (
**/
EFI_GUID *
GetVendorGuidPtr (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFlag
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFlag
)
{
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable;
if (AuthFlag) {
return &AuthVariable->VendorGuid;
} else {
@@ -266,24 +269,23 @@ GetVendorGuidPtr (
**/
UINT8 *
GetVariableDataPtr (
IN VARIABLE_HEADER *Variable,
IN VARIABLE_HEADER *VariableHeader,
IN BOOLEAN AuthFlag
IN VARIABLE_HEADER *Variable,
IN VARIABLE_HEADER *VariableHeader,
IN BOOLEAN AuthFlag
)
{
UINTN Value;
UINTN Value;
//
// Be careful about pad size for alignment
//
Value = (UINTN) GetVariableNamePtr (Variable, AuthFlag);
Value = (UINTN)GetVariableNamePtr (Variable, AuthFlag);
Value += NameSizeOfVariable (VariableHeader, AuthFlag);
Value += GET_PAD_SIZE (NameSizeOfVariable (VariableHeader, AuthFlag));
return (UINT8 *) Value;
return (UINT8 *)Value;
}
/**
This code gets the pointer to the next variable header.
@@ -296,16 +298,16 @@ GetVariableDataPtr (
**/
VARIABLE_HEADER *
GetNextVariablePtr (
IN VARIABLE_STORE_INFO *StoreInfo,
IN VARIABLE_HEADER *Variable,
IN VARIABLE_HEADER *VariableHeader
IN VARIABLE_STORE_INFO *StoreInfo,
IN VARIABLE_HEADER *Variable,
IN VARIABLE_HEADER *VariableHeader
)
{
EFI_PHYSICAL_ADDRESS TargetAddress;
EFI_PHYSICAL_ADDRESS SpareAddress;
UINTN Value;
Value = (UINTN) GetVariableDataPtr (Variable, VariableHeader, StoreInfo->AuthFlag);
Value = (UINTN)GetVariableDataPtr (Variable, VariableHeader, StoreInfo->AuthFlag);
Value += DataSizeOfVariable (VariableHeader, StoreInfo->AuthFlag);
Value += GET_PAD_SIZE (DataSizeOfVariable (VariableHeader, StoreInfo->AuthFlag));
//
@@ -315,16 +317,16 @@ GetNextVariablePtr (
if (StoreInfo->FtwLastWriteData != NULL) {
TargetAddress = StoreInfo->FtwLastWriteData->TargetAddress;
SpareAddress = StoreInfo->FtwLastWriteData->SpareAddress;
if (((UINTN) Variable < (UINTN) TargetAddress) && (Value >= (UINTN) TargetAddress)) {
SpareAddress = StoreInfo->FtwLastWriteData->SpareAddress;
if (((UINTN)Variable < (UINTN)TargetAddress) && (Value >= (UINTN)TargetAddress)) {
//
// Next variable is in spare block.
//
Value = (UINTN) SpareAddress + (Value - (UINTN) TargetAddress);
Value = (UINTN)SpareAddress + (Value - (UINTN)TargetAddress);
}
}
return (VARIABLE_HEADER *) Value;
return (VARIABLE_HEADER *)Value;
}
/**
@@ -339,27 +341,27 @@ GetNextVariablePtr (
**/
VARIABLE_STORE_STATUS
GetVariableStoreStatus (
IN VARIABLE_STORE_HEADER *VarStoreHeader
IN VARIABLE_STORE_HEADER *VarStoreHeader
)
{
if ((CompareGuid (&VarStoreHeader->Signature, &gEfiAuthenticatedVariableGuid) ||
CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid)) &&
VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&
VarStoreHeader->State == VARIABLE_STORE_HEALTHY
) {
(VarStoreHeader->Format == VARIABLE_STORE_FORMATTED) &&
(VarStoreHeader->State == VARIABLE_STORE_HEALTHY)
)
{
return EfiValid;
}
if (((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff &&
((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff &&
((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff &&
((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff &&
VarStoreHeader->Size == 0xffffffff &&
VarStoreHeader->Format == 0xff &&
VarStoreHeader->State == 0xff
) {
if ((((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff) &&
(((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff) &&
(((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff) &&
(((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff) &&
(VarStoreHeader->Size == 0xffffffff) &&
(VarStoreHeader->Format == 0xff) &&
(VarStoreHeader->State == 0xff)
)
{
return EfiRaw;
} else {
return EfiInvalid;
@@ -380,10 +382,10 @@ GetVariableStoreStatus (
**/
BOOLEAN
CompareVariableName (
IN VARIABLE_STORE_INFO *StoreInfo,
IN CONST CHAR16 *Name1,
IN CONST CHAR16 *Name2,
IN UINTN NameSize
IN VARIABLE_STORE_INFO *StoreInfo,
IN CONST CHAR16 *Name1,
IN CONST CHAR16 *Name2,
IN UINTN NameSize
)
{
EFI_PHYSICAL_ADDRESS TargetAddress;
@@ -392,40 +394,42 @@ CompareVariableName (
if (StoreInfo->FtwLastWriteData != NULL) {
TargetAddress = StoreInfo->FtwLastWriteData->TargetAddress;
SpareAddress = StoreInfo->FtwLastWriteData->SpareAddress;
if (((UINTN) Name1 < (UINTN) TargetAddress) && (((UINTN) Name1 + NameSize) > (UINTN) TargetAddress)) {
SpareAddress = StoreInfo->FtwLastWriteData->SpareAddress;
if (((UINTN)Name1 < (UINTN)TargetAddress) && (((UINTN)Name1 + NameSize) > (UINTN)TargetAddress)) {
//
// Name1 is inconsecutive.
//
PartialNameSize = (UINTN) TargetAddress - (UINTN) Name1;
PartialNameSize = (UINTN)TargetAddress - (UINTN)Name1;
//
// Partial content is in NV storage.
//
if (CompareMem ((UINT8 *) Name1, (UINT8 *) Name2, PartialNameSize) == 0) {
if (CompareMem ((UINT8 *)Name1, (UINT8 *)Name2, PartialNameSize) == 0) {
//
// Another partial content is in spare block.
//
if (CompareMem ((UINT8 *) (UINTN) SpareAddress, (UINT8 *) Name2 + PartialNameSize, NameSize - PartialNameSize) == 0) {
if (CompareMem ((UINT8 *)(UINTN)SpareAddress, (UINT8 *)Name2 + PartialNameSize, NameSize - PartialNameSize) == 0) {
return TRUE;
}
}
return FALSE;
} else if (((UINTN) Name2 < (UINTN) TargetAddress) && (((UINTN) Name2 + NameSize) > (UINTN) TargetAddress)) {
} else if (((UINTN)Name2 < (UINTN)TargetAddress) && (((UINTN)Name2 + NameSize) > (UINTN)TargetAddress)) {
//
// Name2 is inconsecutive.
//
PartialNameSize = (UINTN) TargetAddress - (UINTN) Name2;
PartialNameSize = (UINTN)TargetAddress - (UINTN)Name2;
//
// Partial content is in NV storage.
//
if (CompareMem ((UINT8 *) Name2, (UINT8 *) Name1, PartialNameSize) == 0) {
if (CompareMem ((UINT8 *)Name2, (UINT8 *)Name1, PartialNameSize) == 0) {
//
// Another partial content is in spare block.
//
if (CompareMem ((UINT8 *) (UINTN) SpareAddress, (UINT8 *) Name1 + PartialNameSize, NameSize - PartialNameSize) == 0) {
if (CompareMem ((UINT8 *)(UINTN)SpareAddress, (UINT8 *)Name1 + PartialNameSize, NameSize - PartialNameSize) == 0) {
return TRUE;
}
}
return FALSE;
}
}
@@ -433,9 +437,10 @@ CompareVariableName (
//
// Both Name1 and Name2 are consecutive.
//
if (CompareMem ((UINT8 *) Name1, (UINT8 *) Name2, NameSize) == 0) {
if (CompareMem ((UINT8 *)Name1, (UINT8 *)Name2, NameSize) == 0) {
return TRUE;
}
return FALSE;
}
@@ -455,12 +460,12 @@ CompareVariableName (
**/
EFI_STATUS
CompareWithValidVariable (
IN VARIABLE_STORE_INFO *StoreInfo,
IN VARIABLE_HEADER *Variable,
IN VARIABLE_HEADER *VariableHeader,
IN CONST CHAR16 *VariableName,
IN CONST EFI_GUID *VendorGuid,
OUT VARIABLE_POINTER_TRACK *PtrTrack
IN VARIABLE_STORE_INFO *StoreInfo,
IN VARIABLE_HEADER *Variable,
IN VARIABLE_HEADER *VariableHeader,
IN CONST CHAR16 *VariableName,
IN CONST EFI_GUID *VendorGuid,
OUT VARIABLE_POINTER_TRACK *PtrTrack
)
{
VOID *Point;
@@ -477,13 +482,14 @@ CompareWithValidVariable (
// Instead we compare the GUID a UINT32 at a time and branch
// on the first failed comparison.
//
if ((((INT32 *) VendorGuid)[0] == ((INT32 *) TempVendorGuid)[0]) &&
(((INT32 *) VendorGuid)[1] == ((INT32 *) TempVendorGuid)[1]) &&
(((INT32 *) VendorGuid)[2] == ((INT32 *) TempVendorGuid)[2]) &&
(((INT32 *) VendorGuid)[3] == ((INT32 *) TempVendorGuid)[3])
) {
if ((((INT32 *)VendorGuid)[0] == ((INT32 *)TempVendorGuid)[0]) &&
(((INT32 *)VendorGuid)[1] == ((INT32 *)TempVendorGuid)[1]) &&
(((INT32 *)VendorGuid)[2] == ((INT32 *)TempVendorGuid)[2]) &&
(((INT32 *)VendorGuid)[3] == ((INT32 *)TempVendorGuid)[3])
)
{
ASSERT (NameSizeOfVariable (VariableHeader, StoreInfo->AuthFlag) != 0);
Point = (VOID *) GetVariableNamePtr (Variable, StoreInfo->AuthFlag);
Point = (VOID *)GetVariableNamePtr (Variable, StoreInfo->AuthFlag);
if (CompareVariableName (StoreInfo, VariableName, Point, NameSizeOfVariable (VariableHeader, StoreInfo->AuthFlag))) {
PtrTrack->CurrPtr = Variable;
return EFI_SUCCESS;
@@ -503,45 +509,46 @@ CompareWithValidVariable (
**/
VOID
GetHobVariableStore (
OUT VARIABLE_STORE_INFO *StoreInfo,
OUT VARIABLE_STORE_HEADER **VariableStoreHeader
OUT VARIABLE_STORE_INFO *StoreInfo,
OUT VARIABLE_STORE_HEADER **VariableStoreHeader
)
{
EFI_HOB_GUID_TYPE *GuidHob;
EFI_HOB_GUID_TYPE *GuidHob;
//
// Make sure there is no more than one Variable HOB.
//
DEBUG_CODE_BEGIN ();
GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid);
GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid);
if (GuidHob != NULL) {
if ((GetNextGuidHob (&gEfiAuthenticatedVariableGuid, GET_NEXT_HOB (GuidHob)) != NULL)) {
DEBUG ((DEBUG_ERROR, "ERROR: Found two Auth Variable HOBs\n"));
ASSERT (FALSE);
} else if (GetFirstGuidHob (&gEfiVariableGuid) != NULL) {
DEBUG ((DEBUG_ERROR, "ERROR: Found one Auth + one Normal Variable HOBs\n"));
ASSERT (FALSE);
}
} else {
GuidHob = GetFirstGuidHob (&gEfiVariableGuid);
if (GuidHob != NULL) {
if ((GetNextGuidHob (&gEfiAuthenticatedVariableGuid, GET_NEXT_HOB (GuidHob)) != NULL)) {
DEBUG ((DEBUG_ERROR, "ERROR: Found two Auth Variable HOBs\n"));
if ((GetNextGuidHob (&gEfiVariableGuid, GET_NEXT_HOB (GuidHob)) != NULL)) {
DEBUG ((DEBUG_ERROR, "ERROR: Found two Normal Variable HOBs\n"));
ASSERT (FALSE);
} else if (GetFirstGuidHob (&gEfiVariableGuid) != NULL) {
DEBUG ((DEBUG_ERROR, "ERROR: Found one Auth + one Normal Variable HOBs\n"));
ASSERT (FALSE);
}
} else {
GuidHob = GetFirstGuidHob (&gEfiVariableGuid);
if (GuidHob != NULL) {
if ((GetNextGuidHob (&gEfiVariableGuid, GET_NEXT_HOB (GuidHob)) != NULL)) {
DEBUG ((DEBUG_ERROR, "ERROR: Found two Normal Variable HOBs\n"));
ASSERT (FALSE);
}
}
}
}
DEBUG_CODE_END ();
GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid);
if (GuidHob != NULL) {
*VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob);
StoreInfo->AuthFlag = TRUE;
*VariableStoreHeader = (VARIABLE_STORE_HEADER *)GET_GUID_HOB_DATA (GuidHob);
StoreInfo->AuthFlag = TRUE;
} else {
GuidHob = GetFirstGuidHob (&gEfiVariableGuid);
if (GuidHob != NULL) {
*VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob);
StoreInfo->AuthFlag = FALSE;
*VariableStoreHeader = (VARIABLE_STORE_HEADER *)GET_GUID_HOB_DATA (GuidHob);
StoreInfo->AuthFlag = FALSE;
}
}
}
@@ -556,8 +563,8 @@ GetHobVariableStore (
**/
VARIABLE_STORE_HEADER *
GetVariableStore (
IN VARIABLE_STORE_TYPE Type,
OUT VARIABLE_STORE_INFO *StoreInfo
IN VARIABLE_STORE_TYPE Type,
OUT VARIABLE_STORE_INFO *StoreInfo
)
{
EFI_HOB_GUID_TYPE *GuidHob;
@@ -568,10 +575,10 @@ GetVariableStore (
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
UINT32 BackUpOffset;
StoreInfo->IndexTable = NULL;
StoreInfo->IndexTable = NULL;
StoreInfo->FtwLastWriteData = NULL;
StoreInfo->AuthFlag = FALSE;
VariableStoreHeader = NULL;
StoreInfo->AuthFlag = FALSE;
VariableStoreHeader = NULL;
switch (Type) {
case VariableStoreTypeHob:
GetHobVariableStore (StoreInfo, &VariableStoreHeader);
@@ -585,37 +592,37 @@ GetVariableStore (
//
NvStorageSize = PcdGet32 (PcdFlashNvStorageVariableSize);
NvStorageBase = (EFI_PHYSICAL_ADDRESS) (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ?
PcdGet64 (PcdFlashNvStorageVariableBase64) :
PcdGet32 (PcdFlashNvStorageVariableBase)
NvStorageBase = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ?
PcdGet64 (PcdFlashNvStorageVariableBase64) :
PcdGet32 (PcdFlashNvStorageVariableBase)
);
ASSERT (NvStorageBase != 0);
//
// First let FvHeader point to NV storage base.
//
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) NvStorageBase;
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)NvStorageBase;
//
// Check the FTW last write data hob.
//
BackUpOffset = 0;
GuidHob = GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid);
GuidHob = GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid);
if (GuidHob != NULL) {
FtwLastWriteData = (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *) GET_GUID_HOB_DATA (GuidHob);
FtwLastWriteData = (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *)GET_GUID_HOB_DATA (GuidHob);
if (FtwLastWriteData->TargetAddress == NvStorageBase) {
//
// Let FvHeader point to spare block.
//
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FtwLastWriteData->SpareAddress;
DEBUG ((DEBUG_INFO, "PeiVariable: NV storage is backed up in spare block: 0x%x\n", (UINTN) FtwLastWriteData->SpareAddress));
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FtwLastWriteData->SpareAddress;
DEBUG ((DEBUG_INFO, "PeiVariable: NV storage is backed up in spare block: 0x%x\n", (UINTN)FtwLastWriteData->SpareAddress));
} else if ((FtwLastWriteData->TargetAddress > NvStorageBase) && (FtwLastWriteData->TargetAddress < (NvStorageBase + NvStorageSize))) {
StoreInfo->FtwLastWriteData = FtwLastWriteData;
//
// Flash NV storage from the offset is backed up in spare block.
//
BackUpOffset = (UINT32) (FtwLastWriteData->TargetAddress - NvStorageBase);
DEBUG ((DEBUG_INFO, "PeiVariable: High partial NV storage from offset: %x is backed up in spare block: 0x%x\n", BackUpOffset, (UINTN) FtwLastWriteData->SpareAddress));
BackUpOffset = (UINT32)(FtwLastWriteData->TargetAddress - NvStorageBase);
DEBUG ((DEBUG_INFO, "PeiVariable: High partial NV storage from offset: %x is backed up in spare block: 0x%x\n", BackUpOffset, (UINTN)FtwLastWriteData->SpareAddress));
//
// At least one block data in flash NV storage is still valid, so still leave FvHeader point to NV storage base.
//
@@ -630,9 +637,9 @@ GetVariableStore (
break;
}
VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINT8 *) FvHeader + FvHeader->HeaderLength);
VariableStoreHeader = (VARIABLE_STORE_HEADER *)((UINT8 *)FvHeader + FvHeader->HeaderLength);
StoreInfo->AuthFlag = (BOOLEAN) (CompareGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid));
StoreInfo->AuthFlag = (BOOLEAN)(CompareGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid));
GuidHob = GetFirstGuidHob (&gEfiVariableIndexTableGuid);
if (GuidHob != NULL) {
@@ -644,13 +651,14 @@ GetVariableStore (
// Note that as the resource of PEI phase is limited, only store the limited number of
// VAR_ADDED type variables to reduce access time.
//
StoreInfo->IndexTable = (VARIABLE_INDEX_TABLE *) BuildGuidHob (&gEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE));
StoreInfo->IndexTable = (VARIABLE_INDEX_TABLE *)BuildGuidHob (&gEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE));
StoreInfo->IndexTable->Length = 0;
StoreInfo->IndexTable->StartPtr = GetStartPointer (VariableStoreHeader);
StoreInfo->IndexTable->EndPtr = GetEndPointer (VariableStoreHeader);
StoreInfo->IndexTable->EndPtr = GetEndPointer (VariableStoreHeader);
StoreInfo->IndexTable->GoneThrough = 0;
}
}
break;
default:
@@ -675,9 +683,9 @@ GetVariableStore (
**/
BOOLEAN
GetVariableHeader (
IN VARIABLE_STORE_INFO *StoreInfo,
IN VARIABLE_HEADER *Variable,
OUT VARIABLE_HEADER **VariableHeader
IN VARIABLE_STORE_INFO *StoreInfo,
IN VARIABLE_HEADER *Variable,
OUT VARIABLE_HEADER **VariableHeader
)
{
EFI_PHYSICAL_ADDRESS TargetAddress;
@@ -696,33 +704,35 @@ GetVariableHeader (
if (StoreInfo->FtwLastWriteData != NULL) {
TargetAddress = StoreInfo->FtwLastWriteData->TargetAddress;
SpareAddress = StoreInfo->FtwLastWriteData->SpareAddress;
if (((UINTN) Variable > (UINTN) SpareAddress) &&
(((UINTN) Variable - (UINTN) SpareAddress + (UINTN) TargetAddress) >= (UINTN) GetEndPointer (StoreInfo->VariableStoreHeader))) {
SpareAddress = StoreInfo->FtwLastWriteData->SpareAddress;
if (((UINTN)Variable > (UINTN)SpareAddress) &&
(((UINTN)Variable - (UINTN)SpareAddress + (UINTN)TargetAddress) >= (UINTN)GetEndPointer (StoreInfo->VariableStoreHeader)))
{
//
// Reach the end of variable store.
//
return FALSE;
}
if (((UINTN) Variable < (UINTN) TargetAddress) && (((UINTN) Variable + GetVariableHeaderSize (StoreInfo->AuthFlag)) > (UINTN) TargetAddress)) {
if (((UINTN)Variable < (UINTN)TargetAddress) && (((UINTN)Variable + GetVariableHeaderSize (StoreInfo->AuthFlag)) > (UINTN)TargetAddress)) {
//
// Variable header pointed by Variable is inconsecutive,
// create a guid hob to combine the two partial variable header content together.
//
GuidHob = GetFirstGuidHob (&gEfiCallerIdGuid);
if (GuidHob != NULL) {
*VariableHeader = (VARIABLE_HEADER *) GET_GUID_HOB_DATA (GuidHob);
*VariableHeader = (VARIABLE_HEADER *)GET_GUID_HOB_DATA (GuidHob);
} else {
*VariableHeader = (VARIABLE_HEADER *) BuildGuidHob (&gEfiCallerIdGuid, GetVariableHeaderSize (StoreInfo->AuthFlag));
PartialHeaderSize = (UINTN) TargetAddress - (UINTN) Variable;
*VariableHeader = (VARIABLE_HEADER *)BuildGuidHob (&gEfiCallerIdGuid, GetVariableHeaderSize (StoreInfo->AuthFlag));
PartialHeaderSize = (UINTN)TargetAddress - (UINTN)Variable;
//
// Partial content is in NV storage.
//
CopyMem ((UINT8 *) *VariableHeader, (UINT8 *) Variable, PartialHeaderSize);
CopyMem ((UINT8 *)*VariableHeader, (UINT8 *)Variable, PartialHeaderSize);
//
// Another partial content is in spare block.
//
CopyMem ((UINT8 *) *VariableHeader + PartialHeaderSize, (UINT8 *) (UINTN) SpareAddress, GetVariableHeaderSize (StoreInfo->AuthFlag) - PartialHeaderSize);
CopyMem ((UINT8 *)*VariableHeader + PartialHeaderSize, (UINT8 *)(UINTN)SpareAddress, GetVariableHeaderSize (StoreInfo->AuthFlag) - PartialHeaderSize);
}
}
} else {
@@ -748,10 +758,10 @@ GetVariableHeader (
**/
VOID
GetVariableNameOrData (
IN VARIABLE_STORE_INFO *StoreInfo,
IN UINT8 *NameOrData,
IN UINTN Size,
OUT UINT8 *Buffer
IN VARIABLE_STORE_INFO *StoreInfo,
IN UINT8 *NameOrData,
IN UINTN Size,
OUT UINT8 *Buffer
)
{
EFI_PHYSICAL_ADDRESS TargetAddress;
@@ -760,12 +770,12 @@ GetVariableNameOrData (
if (StoreInfo->FtwLastWriteData != NULL) {
TargetAddress = StoreInfo->FtwLastWriteData->TargetAddress;
SpareAddress = StoreInfo->FtwLastWriteData->SpareAddress;
if (((UINTN) NameOrData < (UINTN) TargetAddress) && (((UINTN) NameOrData + Size) > (UINTN) TargetAddress)) {
SpareAddress = StoreInfo->FtwLastWriteData->SpareAddress;
if (((UINTN)NameOrData < (UINTN)TargetAddress) && (((UINTN)NameOrData + Size) > (UINTN)TargetAddress)) {
//
// Variable name/data is inconsecutive.
//
PartialSize = (UINTN) TargetAddress - (UINTN) NameOrData;
PartialSize = (UINTN)TargetAddress - (UINTN)NameOrData;
//
// Partial content is in NV storage.
//
@@ -773,7 +783,7 @@ GetVariableNameOrData (
//
// Another partial content is in spare block.
//
CopyMem (Buffer + PartialSize, (UINT8 *) (UINTN) SpareAddress, Size - PartialSize);
CopyMem (Buffer + PartialSize, (UINT8 *)(UINTN)SpareAddress, Size - PartialSize);
return;
}
}
@@ -799,22 +809,22 @@ GetVariableNameOrData (
**/
EFI_STATUS
FindVariableEx (
IN VARIABLE_STORE_INFO *StoreInfo,
IN CONST CHAR16 *VariableName,
IN CONST EFI_GUID *VendorGuid,
OUT VARIABLE_POINTER_TRACK *PtrTrack
IN VARIABLE_STORE_INFO *StoreInfo,
IN CONST CHAR16 *VariableName,
IN CONST EFI_GUID *VendorGuid,
OUT VARIABLE_POINTER_TRACK *PtrTrack
)
{
VARIABLE_HEADER *Variable;
VARIABLE_HEADER *LastVariable;
VARIABLE_HEADER *MaxIndex;
UINTN Index;
UINTN Offset;
BOOLEAN StopRecord;
VARIABLE_HEADER *InDeletedVariable;
VARIABLE_STORE_HEADER *VariableStoreHeader;
VARIABLE_INDEX_TABLE *IndexTable;
VARIABLE_HEADER *VariableHeader;
VARIABLE_HEADER *Variable;
VARIABLE_HEADER *LastVariable;
VARIABLE_HEADER *MaxIndex;
UINTN Index;
UINTN Offset;
BOOLEAN StopRecord;
VARIABLE_HEADER *InDeletedVariable;
VARIABLE_STORE_HEADER *VariableStoreHeader;
VARIABLE_INDEX_TABLE *IndexTable;
VARIABLE_HEADER *VariableHeader;
VariableStoreHeader = StoreInfo->VariableStoreHeader;
@@ -830,16 +840,16 @@ FindVariableEx (
return EFI_NOT_FOUND;
}
IndexTable = StoreInfo->IndexTable;
IndexTable = StoreInfo->IndexTable;
PtrTrack->StartPtr = GetStartPointer (VariableStoreHeader);
PtrTrack->EndPtr = GetEndPointer (VariableStoreHeader);
PtrTrack->EndPtr = GetEndPointer (VariableStoreHeader);
InDeletedVariable = NULL;
//
// No Variable Address equals zero, so 0 as initial value is safe.
//
MaxIndex = NULL;
MaxIndex = NULL;
VariableHeader = NULL;
if (IndexTable != NULL) {
@@ -849,8 +859,8 @@ FindVariableEx (
//
for (Offset = 0, Index = 0; Index < IndexTable->Length; Index++) {
ASSERT (Index < sizeof (IndexTable->Index) / sizeof (IndexTable->Index[0]));
Offset += IndexTable->Index[Index];
MaxIndex = (VARIABLE_HEADER *) ((UINT8 *) IndexTable->StartPtr + Offset);
Offset += IndexTable->Index[Index];
MaxIndex = (VARIABLE_HEADER *)((UINT8 *)IndexTable->StartPtr + Offset);
GetVariableHeader (StoreInfo, MaxIndex, &VariableHeader);
if (CompareWithValidVariable (StoreInfo, MaxIndex, VariableHeader, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {
if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
@@ -891,12 +901,12 @@ FindVariableEx (
//
StopRecord = FALSE;
while (GetVariableHeader (StoreInfo, Variable, &VariableHeader)) {
if (VariableHeader->State == VAR_ADDED || VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
if ((VariableHeader->State == VAR_ADDED) || (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED))) {
//
// Record Variable in VariableIndex HOB
//
if ((IndexTable != NULL) && !StopRecord) {
Offset = (UINTN) Variable - (UINTN) LastVariable;
Offset = (UINTN)Variable - (UINTN)LastVariable;
if ((Offset > 0x0FFFF) || (IndexTable->Length >= sizeof (IndexTable->Index) / sizeof (IndexTable->Index[0]))) {
//
// Stop to record if the distance of two neighbouring VAR_ADDED variable is larger than the allowable scope(UINT16),
@@ -904,8 +914,8 @@ FindVariableEx (
//
StopRecord = TRUE;
} else {
IndexTable->Index[IndexTable->Length++] = (UINT16) Offset;
LastVariable = Variable;
IndexTable->Index[IndexTable->Length++] = (UINT16)Offset;
LastVariable = Variable;
}
}
@@ -920,6 +930,7 @@ FindVariableEx (
Variable = GetNextVariablePtr (StoreInfo, Variable, VariableHeader);
}
//
// If gone through the VariableStore, that means we never find in Firmware any more.
//
@@ -952,14 +963,14 @@ FindVariable (
OUT VARIABLE_STORE_INFO *StoreInfo
)
{
EFI_STATUS Status;
VARIABLE_STORE_TYPE Type;
EFI_STATUS Status;
VARIABLE_STORE_TYPE Type;
if (VariableName[0] != 0 && VendorGuid == NULL) {
if ((VariableName[0] != 0) && (VendorGuid == NULL)) {
return EFI_INVALID_PARAMETER;
}
for (Type = (VARIABLE_STORE_TYPE) 0; Type < VariableStoreTypeMax; Type++) {
for (Type = (VARIABLE_STORE_TYPE)0; Type < VariableStoreTypeMax; Type++) {
GetVariableStore (Type, StoreInfo);
Status = FindVariableEx (
StoreInfo,
@@ -1005,12 +1016,12 @@ FindVariable (
EFI_STATUS
EFIAPI
PeiGetVariable (
IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
IN CONST CHAR16 *VariableName,
IN CONST EFI_GUID *VariableGuid,
OUT UINT32 *Attributes,
IN OUT UINTN *DataSize,
OUT VOID *Data OPTIONAL
IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
IN CONST CHAR16 *VariableName,
IN CONST EFI_GUID *VariableGuid,
OUT UINT32 *Attributes,
IN OUT UINTN *DataSize,
OUT VOID *Data OPTIONAL
)
{
VARIABLE_POINTER_TRACK Variable;
@@ -1019,7 +1030,7 @@ PeiGetVariable (
VARIABLE_STORE_INFO StoreInfo;
VARIABLE_HEADER *VariableHeader;
if (VariableName == NULL || VariableGuid == NULL || DataSize == NULL) {
if ((VariableName == NULL) || (VariableGuid == NULL) || (DataSize == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -1036,6 +1047,7 @@ PeiGetVariable (
if (EFI_ERROR (Status)) {
return Status;
}
GetVariableHeader (&StoreInfo, Variable.CurrPtr, &VariableHeader);
//
@@ -1056,6 +1068,7 @@ PeiGetVariable (
if (Attributes != NULL) {
*Attributes = VariableHeader->Attributes;
}
*DataSize = VarDataSize;
return Status;
@@ -1093,10 +1106,10 @@ PeiGetVariable (
EFI_STATUS
EFIAPI
PeiGetNextVariableName (
IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VariableGuid
IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VariableGuid
)
{
VARIABLE_STORE_TYPE Type;
@@ -1111,14 +1124,14 @@ PeiGetNextVariableName (
VARIABLE_STORE_INFO StoreInfoForNv;
VARIABLE_STORE_INFO StoreInfoForHob;
if (VariableName == NULL || VariableGuid == NULL || VariableNameSize == NULL) {
if ((VariableName == NULL) || (VariableGuid == NULL) || (VariableNameSize == NULL)) {
return EFI_INVALID_PARAMETER;
}
VariableHeader = NULL;
Status = FindVariable (VariableName, VariableGuid, &Variable, &StoreInfo);
if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {
if ((Variable.CurrPtr == NULL) || (Status != EFI_SUCCESS)) {
return Status;
}
@@ -1141,11 +1154,12 @@ PeiGetNextVariableName (
//
// Find current storage index
//
for (Type = (VARIABLE_STORE_TYPE) 0; Type < VariableStoreTypeMax; Type++) {
for (Type = (VARIABLE_STORE_TYPE)0; Type < VariableStoreTypeMax; Type++) {
if ((VariableStoreHeader[Type] != NULL) && (Variable.StartPtr == GetStartPointer (VariableStoreHeader[Type]))) {
break;
}
}
ASSERT (Type < VariableStoreTypeMax);
//
// Switch to next storage
@@ -1155,6 +1169,7 @@ PeiGetNextVariableName (
break;
}
}
//
// Capture the case that
// 1. current storage is the last one, or
@@ -1163,13 +1178,14 @@ PeiGetNextVariableName (
if (Type == VariableStoreTypeMax) {
return EFI_NOT_FOUND;
}
Variable.StartPtr = GetStartPointer (VariableStoreHeader[Type]);
Variable.EndPtr = GetEndPointer (VariableStoreHeader[Type]);
Variable.EndPtr = GetEndPointer (VariableStoreHeader[Type]);
Variable.CurrPtr = Variable.StartPtr;
GetVariableStore (Type, &StoreInfo);
}
if (VariableHeader->State == VAR_ADDED || VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
if ((VariableHeader->State == VAR_ADDED) || (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED))) {
if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
//
// If it is a IN_DELETED_TRANSITION variable,
@@ -1182,7 +1198,7 @@ PeiGetNextVariableName (
GetVendorGuidPtr (VariableHeader, StoreInfo.AuthFlag),
&VariablePtrTrack
);
if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr != Variable.CurrPtr) {
if (!EFI_ERROR (Status) && (VariablePtrTrack.CurrPtr != Variable.CurrPtr)) {
Variable.CurrPtr = GetNextVariablePtr (&StoreInfo, Variable.CurrPtr, VariableHeader);
continue;
}
@@ -1193,7 +1209,8 @@ PeiGetNextVariableName (
//
if ((VariableStoreHeader[VariableStoreTypeHob] != NULL) && (VariableStoreHeader[VariableStoreTypeNv] != NULL) &&
(Variable.StartPtr == GetStartPointer (VariableStoreHeader[VariableStoreTypeNv]))
) {
)
{
Status = FindVariableEx (
&StoreInfoForHob,
GetVariableNamePtr (Variable.CurrPtr, StoreInfo.AuthFlag),
@@ -1210,7 +1227,7 @@ PeiGetNextVariableName (
ASSERT (VarNameSize != 0);
if (VarNameSize <= *VariableNameSize) {
GetVariableNameOrData (&StoreInfo, (UINT8 *) GetVariableNamePtr (Variable.CurrPtr, StoreInfo.AuthFlag), VarNameSize, (UINT8 *) VariableName);
GetVariableNameOrData (&StoreInfo, (UINT8 *)GetVariableNamePtr (Variable.CurrPtr, StoreInfo.AuthFlag), VarNameSize, (UINT8 *)VariableName);
CopyMem (VariableGuid, GetVendorGuidPtr (VariableHeader, StoreInfo.AuthFlag), sizeof (EFI_GUID));

View File

@@ -47,6 +47,7 @@ typedef struct {
//
// Functions
//
/**
Provide the functionality of the variable services.
@@ -61,8 +62,8 @@ typedef struct {
EFI_STATUS
EFIAPI
PeimInitializeVariableServices (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
);
/**
@@ -95,12 +96,12 @@ PeimInitializeVariableServices (
EFI_STATUS
EFIAPI
PeiGetVariable (
IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
IN CONST CHAR16 *VariableName,
IN CONST EFI_GUID *VariableGuid,
OUT UINT32 *Attributes,
IN OUT UINTN *DataSize,
OUT VOID *Data OPTIONAL
IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
IN CONST CHAR16 *VariableName,
IN CONST EFI_GUID *VariableGuid,
OUT UINT32 *Attributes,
IN OUT UINTN *DataSize,
OUT VOID *Data OPTIONAL
);
/**
@@ -135,10 +136,10 @@ PeiGetVariable (
EFI_STATUS
EFIAPI
PeiGetNextVariableName (
IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VariableGuid
IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VariableGuid
);
#endif

View File

@@ -21,25 +21,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "PrivilegePolymorphic.h"
typedef struct {
CHAR16 *VariableName;
EFI_GUID *VendorGuid;
CHAR16 *VariableName;
EFI_GUID *VendorGuid;
} VARIABLE_TYPE;
VARIABLE_TYPE mVariableType[] = {
{EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid},
{EFI_PLATFORM_KEY_NAME, &gEfiGlobalVariableGuid},
{EFI_KEY_EXCHANGE_KEY_NAME, &gEfiGlobalVariableGuid},
{EFI_IMAGE_SECURITY_DATABASE, &gEfiImageSecurityDatabaseGuid},
{EFI_IMAGE_SECURITY_DATABASE1, &gEfiImageSecurityDatabaseGuid},
{EFI_IMAGE_SECURITY_DATABASE2, &gEfiImageSecurityDatabaseGuid},
{ EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid },
{ EFI_PLATFORM_KEY_NAME, &gEfiGlobalVariableGuid },
{ EFI_KEY_EXCHANGE_KEY_NAME, &gEfiGlobalVariableGuid },
{ EFI_IMAGE_SECURITY_DATABASE, &gEfiImageSecurityDatabaseGuid },
{ EFI_IMAGE_SECURITY_DATABASE1, &gEfiImageSecurityDatabaseGuid },
{ EFI_IMAGE_SECURITY_DATABASE2, &gEfiImageSecurityDatabaseGuid },
};
//
// "SecureBoot" may update following PK Del/Add
// Cache its value to detect value update
//
UINT8 *mSecureBootVarData = NULL;
UINTN mSecureBootVarDataSize = 0;
UINT8 *mSecureBootVarData = NULL;
UINTN mSecureBootVarDataSize = 0;
/**
This function will return if this variable is SecureBootPolicy Variable.
@@ -52,18 +52,20 @@ UINTN mSecureBootVarDataSize = 0;
**/
BOOLEAN
IsSecureBootPolicyVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
)
{
UINTN Index;
UINTN Index;
for (Index = 0; Index < sizeof(mVariableType)/sizeof(mVariableType[0]); Index++) {
for (Index = 0; Index < sizeof (mVariableType)/sizeof (mVariableType[0]); Index++) {
if ((StrCmp (VariableName, mVariableType[Index].VariableName) == 0) &&
(CompareGuid (VendorGuid, mVariableType[Index].VendorGuid))) {
(CompareGuid (VendorGuid, mVariableType[Index].VendorGuid)))
{
return TRUE;
}
}
return FALSE;
}
@@ -83,42 +85,42 @@ IsSecureBootPolicyVariable (
EFI_STATUS
EFIAPI
MeasureVariable (
IN CHAR16 *VarName,
IN EFI_GUID *VendorGuid,
IN VOID *VarData,
IN UINTN VarSize
IN CHAR16 *VarName,
IN EFI_GUID *VendorGuid,
IN VOID *VarData,
IN UINTN VarSize
)
{
EFI_STATUS Status;
UINTN VarNameLength;
UEFI_VARIABLE_DATA *VarLog;
UINT32 VarLogSize;
EFI_STATUS Status;
UINTN VarNameLength;
UEFI_VARIABLE_DATA *VarLog;
UINT32 VarLogSize;
ASSERT ((VarSize == 0 && VarData == NULL) || (VarSize != 0 && VarData != NULL));
VarNameLength = StrLen (VarName);
VarLogSize = (UINT32)(sizeof (*VarLog) + VarNameLength * sizeof (*VarName) + VarSize
- sizeof (VarLog->UnicodeName) - sizeof (VarLog->VariableData));
VarNameLength = StrLen (VarName);
VarLogSize = (UINT32)(sizeof (*VarLog) + VarNameLength * sizeof (*VarName) + VarSize
- sizeof (VarLog->UnicodeName) - sizeof (VarLog->VariableData));
VarLog = (UEFI_VARIABLE_DATA *) AllocateZeroPool (VarLogSize);
VarLog = (UEFI_VARIABLE_DATA *)AllocateZeroPool (VarLogSize);
if (VarLog == NULL) {
return EFI_OUT_OF_RESOURCES;
}
CopyMem (&VarLog->VariableName, VendorGuid, sizeof(VarLog->VariableName));
CopyMem (&VarLog->VariableName, VendorGuid, sizeof (VarLog->VariableName));
VarLog->UnicodeNameLength = VarNameLength;
VarLog->VariableDataLength = VarSize;
CopyMem (
VarLog->UnicodeName,
VarName,
VarNameLength * sizeof (*VarName)
);
VarLog->UnicodeName,
VarName,
VarNameLength * sizeof (*VarName)
);
if (VarSize != 0) {
CopyMem (
(CHAR16 *)VarLog->UnicodeName + VarNameLength,
VarData,
VarSize
);
(CHAR16 *)VarLog->UnicodeName + VarNameLength,
VarData,
VarSize
);
}
DEBUG ((DEBUG_INFO, "VariableDxe: MeasureVariable (Pcr - %x, EventType - %x, ", (UINTN)7, (UINTN)EV_EFI_VARIABLE_DRIVER_CONFIG));
@@ -171,10 +173,10 @@ InternalGetVariable (
BufferSize = 0;
*Value = NULL;
if (Size != NULL) {
*Size = 0;
*Size = 0;
}
Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &BufferSize, *Value);
Status = gRT->GetVariable ((CHAR16 *)Name, (EFI_GUID *)Guid, NULL, &BufferSize, *Value);
if (Status != EFI_BUFFER_TOO_SMALL) {
return Status;
}
@@ -191,9 +193,9 @@ InternalGetVariable (
//
// Get the variable data.
//
Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &BufferSize, *Value);
Status = gRT->GetVariable ((CHAR16 *)Name, (EFI_GUID *)Guid, NULL, &BufferSize, *Value);
if (EFI_ERROR (Status)) {
FreePool(*Value);
FreePool (*Value);
*Value = NULL;
}
@@ -214,16 +216,16 @@ InternalGetVariable (
VOID
EFIAPI
SecureBootHook (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
)
{
EFI_STATUS Status;
UINTN VariableDataSize;
VOID *VariableData;
EFI_STATUS Status;
UINTN VariableDataSize;
VOID *VariableData;
if (!IsSecureBootPolicyVariable (VariableName, VendorGuid)) {
return ;
return;
}
//
@@ -241,9 +243,10 @@ SecureBootHook (
//
// Measure DBT only if present and not empty
//
if (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE2) == 0 &&
CompareGuid (VendorGuid, &gEfiImageSecurityDatabaseGuid)) {
DEBUG((DEBUG_INFO, "Skip measuring variable %s since it's deleted\n", EFI_IMAGE_SECURITY_DATABASE2));
if ((StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE2) == 0) &&
CompareGuid (VendorGuid, &gEfiImageSecurityDatabaseGuid))
{
DEBUG ((DEBUG_INFO, "Skip measuring variable %s since it's deleted\n", EFI_IMAGE_SECURITY_DATABASE2));
return;
} else {
VariableData = NULL;
@@ -267,44 +270,45 @@ SecureBootHook (
// "SecureBoot" is 8bit & read-only. It can only be changed according to PK update
//
if ((StrCmp (VariableName, EFI_PLATFORM_KEY_NAME) == 0) &&
CompareGuid (VendorGuid, &gEfiGlobalVariableGuid)) {
Status = InternalGetVariable (
EFI_SECURE_BOOT_MODE_NAME,
&gEfiGlobalVariableGuid,
&VariableData,
&VariableDataSize
);
if (EFI_ERROR (Status)) {
return;
}
CompareGuid (VendorGuid, &gEfiGlobalVariableGuid))
{
Status = InternalGetVariable (
EFI_SECURE_BOOT_MODE_NAME,
&gEfiGlobalVariableGuid,
&VariableData,
&VariableDataSize
);
if (EFI_ERROR (Status)) {
return;
}
//
// If PK update is successful. "SecureBoot" shall always exist ever since variable write service is ready
//
ASSERT(mSecureBootVarData != NULL);
//
// If PK update is successful. "SecureBoot" shall always exist ever since variable write service is ready
//
ASSERT (mSecureBootVarData != NULL);
if (CompareMem(mSecureBootVarData, VariableData, VariableDataSize) != 0) {
FreePool(mSecureBootVarData);
mSecureBootVarData = VariableData;
mSecureBootVarDataSize = VariableDataSize;
if (CompareMem (mSecureBootVarData, VariableData, VariableDataSize) != 0) {
FreePool (mSecureBootVarData);
mSecureBootVarData = VariableData;
mSecureBootVarDataSize = VariableDataSize;
DEBUG((DEBUG_INFO, "%s variable updated according to PK change. Remeasure the value!\n", EFI_SECURE_BOOT_MODE_NAME));
Status = MeasureVariable (
EFI_SECURE_BOOT_MODE_NAME,
&gEfiGlobalVariableGuid,
mSecureBootVarData,
mSecureBootVarDataSize
);
DEBUG ((DEBUG_INFO, "MeasureBootPolicyVariable - %r\n", Status));
} else {
//
// "SecureBoot" variable is not changed
//
FreePool(VariableData);
}
DEBUG ((DEBUG_INFO, "%s variable updated according to PK change. Remeasure the value!\n", EFI_SECURE_BOOT_MODE_NAME));
Status = MeasureVariable (
EFI_SECURE_BOOT_MODE_NAME,
&gEfiGlobalVariableGuid,
mSecureBootVarData,
mSecureBootVarDataSize
);
DEBUG ((DEBUG_INFO, "MeasureBootPolicyVariable - %r\n", Status));
} else {
//
// "SecureBoot" variable is not changed
//
FreePool (VariableData);
}
}
return ;
return;
}
/**
@@ -314,11 +318,11 @@ SecureBootHook (
**/
VOID
EFIAPI
RecordSecureBootPolicyVarData(
RecordSecureBootPolicyVarData (
VOID
)
{
EFI_STATUS Status;
EFI_STATUS Status;
//
// Record initial "SecureBoot" variable value.
@@ -330,10 +334,10 @@ RecordSecureBootPolicyVarData(
(VOID **)&mSecureBootVarData,
&mSecureBootVarDataSize
);
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
//
// Read could fail when Auth Variable solution is not supported
//
DEBUG((DEBUG_INFO, "RecordSecureBootPolicyVarData GetVariable %s Status %x\n", EFI_SECURE_BOOT_MODE_NAME, Status));
DEBUG ((DEBUG_INFO, "RecordSecureBootPolicyVarData GetVariable %s Status %x\n", EFI_SECURE_BOOT_MODE_NAME, Status));
}
}

View File

@@ -11,6 +11,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _PRIVILEGE_POLYMORPHIC_H_
#define _PRIVILEGE_POLYMORPHIC_H_
@@ -25,8 +26,8 @@
VOID
EFIAPI
SecureBootHook (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
);
/**
@@ -71,11 +72,11 @@ MorLockInitAtEndOfDxe (
**/
EFI_STATUS
SetVariableCheckHandlerMor (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
);
/**

View File

@@ -28,9 +28,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
EFI_STATUS
GetLbaAndOffsetByAddress (
IN EFI_PHYSICAL_ADDRESS Address,
OUT EFI_LBA *Lba,
OUT UINTN *Offset
IN EFI_PHYSICAL_ADDRESS Address,
OUT EFI_LBA *Lba,
OUT UINTN *Offset
)
{
EFI_STATUS Status;
@@ -41,7 +41,7 @@ GetLbaAndOffsetByAddress (
UINT32 LbaIndex;
Fvb = NULL;
*Lba = (EFI_LBA) (-1);
*Lba = (EFI_LBA)(-1);
*Offset = 0;
//
@@ -60,7 +60,7 @@ GetLbaAndOffsetByAddress (
return Status;
}
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvbBaseAddress);
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN)FvbBaseAddress);
//
// Get the (LBA, Offset) of Address.
@@ -76,9 +76,9 @@ GetLbaAndOffsetByAddress (
// Found the (Lba, Offset).
//
*Lba = LbaIndex - 1;
*Offset = (UINTN) (Address - (FvbBaseAddress + FvbMapEntry->Length * (LbaIndex - 1)));
*Offset = (UINTN)(Address - (FvbBaseAddress + FvbMapEntry->Length * (LbaIndex - 1)));
return EFI_SUCCESS;
}
}
}
}
@@ -116,10 +116,11 @@ FtwVariableSpace (
//
// Locate fault tolerant write protocol.
//
Status = GetFtwProtocol((VOID **) &FtwProtocol);
Status = GetFtwProtocol ((VOID **)&FtwProtocol);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
//
// Locate Fvb handle by address.
//
@@ -127,6 +128,7 @@ FtwVariableSpace (
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get LBA and Offset by address.
//
@@ -135,7 +137,7 @@ FtwVariableSpace (
return EFI_ABORTED;
}
FtwBufferSize = ((VARIABLE_STORE_HEADER *) ((UINTN) VariableBase))->Size;
FtwBufferSize = ((VARIABLE_STORE_HEADER *)((UINTN)VariableBase))->Size;
ASSERT (FtwBufferSize == VariableBuffer->Size);
//
@@ -143,12 +145,12 @@ FtwVariableSpace (
//
Status = FtwProtocol->Write (
FtwProtocol,
VarLba, // LBA
VarOffset, // Offset
FtwBufferSize, // NumBytes
NULL, // PrivateData NULL
FvbHandle, // Fvb Handle
(VOID *) VariableBuffer // write buffer
VarLba, // LBA
VarOffset, // Offset
FtwBufferSize, // NumBytes
NULL, // PrivateData NULL
FvbHandle, // Fvb Handle
(VOID *)VariableBuffer // write buffer
);
return Status;

View File

@@ -23,10 +23,10 @@
#include <Protocol/VariableLock.h>
#define UNIT_TEST_NAME "VarPol/VarLock Shim Unit Test"
#define UNIT_TEST_VERSION "1.0"
#define UNIT_TEST_NAME "VarPol/VarLock Shim Unit Test"
#define UNIT_TEST_VERSION "1.0"
///=== CODE UNDER TEST ===========================================================================
/// === CODE UNDER TEST ===========================================================================
EFI_STATUS
EFIAPI
@@ -36,41 +36,41 @@ VariableLockRequestToLock (
IN EFI_GUID *VendorGuid
);
///=== TEST DATA ==================================================================================
/// === TEST DATA ==================================================================================
//
// Test GUID 1 {F955BA2D-4A2C-480C-BFD1-3CC522610592}
//
EFI_GUID mTestGuid1 = {
0xf955ba2d, 0x4a2c, 0x480c, {0xbf, 0xd1, 0x3c, 0xc5, 0x22, 0x61, 0x5, 0x92}
0xf955ba2d, 0x4a2c, 0x480c, { 0xbf, 0xd1, 0x3c, 0xc5, 0x22, 0x61, 0x5, 0x92 }
};
//
// Test GUID 2 {2DEA799E-5E73-43B9-870E-C945CE82AF3A}
//
EFI_GUID mTestGuid2 = {
0x2dea799e, 0x5e73, 0x43b9, {0x87, 0xe, 0xc9, 0x45, 0xce, 0x82, 0xaf, 0x3a}
0x2dea799e, 0x5e73, 0x43b9, { 0x87, 0xe, 0xc9, 0x45, 0xce, 0x82, 0xaf, 0x3a }
};
//
// Test GUID 3 {698A2BFD-A616-482D-B88C-7100BD6682A9}
//
EFI_GUID mTestGuid3 = {
0x698a2bfd, 0xa616, 0x482d, {0xb8, 0x8c, 0x71, 0x0, 0xbd, 0x66, 0x82, 0xa9}
0x698a2bfd, 0xa616, 0x482d, { 0xb8, 0x8c, 0x71, 0x0, 0xbd, 0x66, 0x82, 0xa9 }
};
#define TEST_VAR_1_NAME L"TestVar1"
#define TEST_VAR_2_NAME L"TestVar2"
#define TEST_VAR_3_NAME L"TestVar3"
#define TEST_VAR_1_NAME L"TestVar1"
#define TEST_VAR_2_NAME L"TestVar2"
#define TEST_VAR_3_NAME L"TestVar3"
#define TEST_POLICY_ATTRIBUTES_NULL 0
#define TEST_POLICY_MIN_SIZE_NULL 0
#define TEST_POLICY_MAX_SIZE_NULL MAX_UINT32
#define TEST_POLICY_MIN_SIZE_10 10
#define TEST_POLICY_MAX_SIZE_200 200
#define TEST_POLICY_MIN_SIZE_10 10
#define TEST_POLICY_MAX_SIZE_200 200
///=== HELPER FUNCTIONS ===========================================================================
/// === HELPER FUNCTIONS ===========================================================================
/**
Mocked version of GetVariable, for testing.
@@ -100,15 +100,16 @@ StubGetVariableNull (
check_expected_ptr (VendorGuid);
check_expected_ptr (DataSize);
MockedAttr = (UINT32)mock();
MockedDataSize = (UINTN)mock();
MockedData = (VOID*)(UINTN)mock();
MockedReturn = (EFI_STATUS)mock();
MockedAttr = (UINT32)mock ();
MockedDataSize = (UINTN)mock ();
MockedData = (VOID *)(UINTN)mock ();
MockedReturn = (EFI_STATUS)mock ();
if (Attributes != NULL) {
*Attributes = MockedAttr;
}
if (Data != NULL && !EFI_ERROR (MockedReturn)) {
if ((Data != NULL) && !EFI_ERROR (MockedReturn)) {
CopyMem (Data, MockedData, MockedDataSize);
}
@@ -152,12 +153,12 @@ LibCleanup (
IN UNIT_TEST_CONTEXT Context
)
{
DeinitVariablePolicyLib();
DeinitVariablePolicyLib ();
}
///=== TEST CASES =================================================================================
/// === TEST CASES =================================================================================
///===== SHIM SUITE ===========================================================
/// ===== SHIM SUITE ===========================================================
/**
Test Case that locks a single variable using the Variable Lock Protocol.
@@ -257,38 +258,40 @@ LockingALockedVariableShouldSucceed (
UNIT_TEST_STATUS
EFIAPI
LockingAnUnlockedVariableShouldFail (
IN UNIT_TEST_CONTEXT Context
IN UNIT_TEST_CONTEXT Context
)
{
EFI_STATUS Status;
VARIABLE_POLICY_ENTRY *NewEntry;
EFI_STATUS Status;
VARIABLE_POLICY_ENTRY *NewEntry;
// Create a variable policy that locks the variable.
Status = CreateVarStateVariablePolicy (&mTestGuid1,
TEST_VAR_1_NAME,
TEST_POLICY_MIN_SIZE_NULL,
TEST_POLICY_MAX_SIZE_200,
TEST_POLICY_ATTRIBUTES_NULL,
TEST_POLICY_ATTRIBUTES_NULL,
&mTestGuid2,
1,
TEST_VAR_2_NAME,
&NewEntry);
Status = CreateVarStateVariablePolicy (
&mTestGuid1,
TEST_VAR_1_NAME,
TEST_POLICY_MIN_SIZE_NULL,
TEST_POLICY_MAX_SIZE_200,
TEST_POLICY_ATTRIBUTES_NULL,
TEST_POLICY_ATTRIBUTES_NULL,
&mTestGuid2,
1,
TEST_VAR_2_NAME,
&NewEntry
);
UT_ASSERT_NOT_EFI_ERROR (Status);
// Register the new policy.
Status = RegisterVariablePolicy (NewEntry);
// Configure the stub to not care about parameters. We're testing errors.
expect_any_always( StubGetVariableNull, VariableName );
expect_any_always( StubGetVariableNull, VendorGuid );
expect_any_always( StubGetVariableNull, DataSize );
// Configure the stub to not care about parameters. We're testing errors.
expect_any_always (StubGetVariableNull, VariableName);
expect_any_always (StubGetVariableNull, VendorGuid);
expect_any_always (StubGetVariableNull, DataSize);
// With a policy, make sure that writes still work, since the variable doesn't exist.
will_return( StubGetVariableNull, TEST_POLICY_ATTRIBUTES_NULL ); // Attributes
will_return( StubGetVariableNull, 0 ); // Size
will_return( StubGetVariableNull, (UINTN)NULL ); // DataPtr
will_return( StubGetVariableNull, EFI_NOT_FOUND); // Status
will_return (StubGetVariableNull, TEST_POLICY_ATTRIBUTES_NULL); // Attributes
will_return (StubGetVariableNull, 0); // Size
will_return (StubGetVariableNull, (UINTN)NULL); // DataPtr
will_return (StubGetVariableNull, EFI_NOT_FOUND); // Status
Status = VariableLockRequestToLock (NULL, TEST_VAR_1_NAME, &mTestGuid1);
UT_ASSERT_TRUE (EFI_ERROR (Status));
@@ -310,40 +313,42 @@ LockingAnUnlockedVariableShouldFail (
UNIT_TEST_STATUS
EFIAPI
LockingALockedVariableWithMatchingDataShouldSucceed (
IN UNIT_TEST_CONTEXT Context
IN UNIT_TEST_CONTEXT Context
)
{
EFI_STATUS Status;
VARIABLE_POLICY_ENTRY *NewEntry;
UINT8 Data;
EFI_STATUS Status;
VARIABLE_POLICY_ENTRY *NewEntry;
UINT8 Data;
// Create a variable policy that locks the variable.
Status = CreateVarStateVariablePolicy (&mTestGuid1,
TEST_VAR_1_NAME,
TEST_POLICY_MIN_SIZE_NULL,
TEST_POLICY_MAX_SIZE_200,
TEST_POLICY_ATTRIBUTES_NULL,
TEST_POLICY_ATTRIBUTES_NULL,
&mTestGuid2,
1,
TEST_VAR_2_NAME,
&NewEntry);
Status = CreateVarStateVariablePolicy (
&mTestGuid1,
TEST_VAR_1_NAME,
TEST_POLICY_MIN_SIZE_NULL,
TEST_POLICY_MAX_SIZE_200,
TEST_POLICY_ATTRIBUTES_NULL,
TEST_POLICY_ATTRIBUTES_NULL,
&mTestGuid2,
1,
TEST_VAR_2_NAME,
&NewEntry
);
UT_ASSERT_NOT_EFI_ERROR (Status);
// Register the new policy.
Status = RegisterVariablePolicy (NewEntry);
// Configure the stub to not care about parameters. We're testing errors.
expect_any_always( StubGetVariableNull, VariableName );
expect_any_always( StubGetVariableNull, VendorGuid );
expect_any_always( StubGetVariableNull, DataSize );
// Configure the stub to not care about parameters. We're testing errors.
expect_any_always (StubGetVariableNull, VariableName);
expect_any_always (StubGetVariableNull, VendorGuid);
expect_any_always (StubGetVariableNull, DataSize);
// With a policy, make sure that writes still work, since the variable doesn't exist.
Data = 1;
will_return( StubGetVariableNull, TEST_POLICY_ATTRIBUTES_NULL ); // Attributes
will_return( StubGetVariableNull, sizeof (Data) ); // Size
will_return( StubGetVariableNull, (UINTN)&Data ); // DataPtr
will_return( StubGetVariableNull, EFI_SUCCESS); // Status
will_return (StubGetVariableNull, TEST_POLICY_ATTRIBUTES_NULL); // Attributes
will_return (StubGetVariableNull, sizeof (Data)); // Size
will_return (StubGetVariableNull, (UINTN)&Data); // DataPtr
will_return (StubGetVariableNull, EFI_SUCCESS); // Status
Status = VariableLockRequestToLock (NULL, TEST_VAR_1_NAME, &mTestGuid1);
UT_ASSERT_TRUE (!EFI_ERROR (Status));
@@ -365,40 +370,42 @@ LockingALockedVariableWithMatchingDataShouldSucceed (
UNIT_TEST_STATUS
EFIAPI
LockingALockedVariableWithNonMatchingDataShouldFail (
IN UNIT_TEST_CONTEXT Context
IN UNIT_TEST_CONTEXT Context
)
{
EFI_STATUS Status;
VARIABLE_POLICY_ENTRY *NewEntry;
UINT8 Data;
EFI_STATUS Status;
VARIABLE_POLICY_ENTRY *NewEntry;
UINT8 Data;
// Create a variable policy that locks the variable.
Status = CreateVarStateVariablePolicy (&mTestGuid1,
TEST_VAR_1_NAME,
TEST_POLICY_MIN_SIZE_NULL,
TEST_POLICY_MAX_SIZE_200,
TEST_POLICY_ATTRIBUTES_NULL,
TEST_POLICY_ATTRIBUTES_NULL,
&mTestGuid2,
1,
TEST_VAR_2_NAME,
&NewEntry);
Status = CreateVarStateVariablePolicy (
&mTestGuid1,
TEST_VAR_1_NAME,
TEST_POLICY_MIN_SIZE_NULL,
TEST_POLICY_MAX_SIZE_200,
TEST_POLICY_ATTRIBUTES_NULL,
TEST_POLICY_ATTRIBUTES_NULL,
&mTestGuid2,
1,
TEST_VAR_2_NAME,
&NewEntry
);
UT_ASSERT_NOT_EFI_ERROR (Status);
// Register the new policy.
Status = RegisterVariablePolicy (NewEntry);
// Configure the stub to not care about parameters. We're testing errors.
expect_any_always( StubGetVariableNull, VariableName );
expect_any_always( StubGetVariableNull, VendorGuid );
expect_any_always( StubGetVariableNull, DataSize );
// Configure the stub to not care about parameters. We're testing errors.
expect_any_always (StubGetVariableNull, VariableName);
expect_any_always (StubGetVariableNull, VendorGuid);
expect_any_always (StubGetVariableNull, DataSize);
// With a policy, make sure that writes still work, since the variable doesn't exist.
Data = 2;
will_return( StubGetVariableNull, TEST_POLICY_ATTRIBUTES_NULL ); // Attributes
will_return( StubGetVariableNull, sizeof (Data) ); // Size
will_return( StubGetVariableNull, (UINTN)&Data ); // DataPtr
will_return( StubGetVariableNull, EFI_SUCCESS); // Status
will_return (StubGetVariableNull, TEST_POLICY_ATTRIBUTES_NULL); // Attributes
will_return (StubGetVariableNull, sizeof (Data)); // Size
will_return (StubGetVariableNull, (UINTN)&Data); // DataPtr
will_return (StubGetVariableNull, EFI_SUCCESS); // Status
Status = VariableLockRequestToLock (NULL, TEST_VAR_1_NAME, &mTestGuid1);
UT_ASSERT_TRUE (EFI_ERROR (Status));
@@ -419,27 +426,29 @@ LockingALockedVariableWithNonMatchingDataShouldFail (
UNIT_TEST_STATUS
EFIAPI
SettingPolicyForALockedVariableShouldFail (
IN UNIT_TEST_CONTEXT Context
IN UNIT_TEST_CONTEXT Context
)
{
EFI_STATUS Status;
VARIABLE_POLICY_ENTRY *NewEntry;
EFI_STATUS Status;
VARIABLE_POLICY_ENTRY *NewEntry;
// Lock the variable.
Status = VariableLockRequestToLock (NULL, TEST_VAR_1_NAME, &mTestGuid1);
UT_ASSERT_NOT_EFI_ERROR (Status);
// Create a variable policy that locks the variable.
Status = CreateVarStateVariablePolicy (&mTestGuid1,
TEST_VAR_1_NAME,
TEST_POLICY_MIN_SIZE_NULL,
TEST_POLICY_MAX_SIZE_200,
TEST_POLICY_ATTRIBUTES_NULL,
TEST_POLICY_ATTRIBUTES_NULL,
&mTestGuid2,
1,
TEST_VAR_2_NAME,
&NewEntry);
Status = CreateVarStateVariablePolicy (
&mTestGuid1,
TEST_VAR_1_NAME,
TEST_POLICY_MIN_SIZE_NULL,
TEST_POLICY_MAX_SIZE_200,
TEST_POLICY_ATTRIBUTES_NULL,
TEST_POLICY_ATTRIBUTES_NULL,
&mTestGuid2,
1,
TEST_VAR_2_NAME,
&NewEntry
);
UT_ASSERT_NOT_EFI_ERROR (Status);
// Register the new policy.
@@ -483,48 +492,81 @@ UnitTestMain (
// Add all test suites and tests.
//
Status = CreateUnitTestSuite (
&ShimTests, Framework,
"Variable Lock Shim Tests", "VarPolicy.VarLockShim", NULL, NULL
&ShimTests,
Framework,
"Variable Lock Shim Tests",
"VarPolicy.VarLockShim",
NULL,
NULL
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for ShimTests\n"));
Status = EFI_OUT_OF_RESOURCES;
goto EXIT;
}
AddTestCase (
ShimTests,
"Locking a variable with no matching policies should always work", "EmptyPolicies",
LockingWithoutAnyPoliciesShouldSucceed, LibInitMocked, LibCleanup, NULL
"Locking a variable with no matching policies should always work",
"EmptyPolicies",
LockingWithoutAnyPoliciesShouldSucceed,
LibInitMocked,
LibCleanup,
NULL
);
AddTestCase (
ShimTests,
"Locking a variable twice should always work", "DoubleLock",
LockingTwiceShouldSucceed, LibInitMocked, LibCleanup, NULL
"Locking a variable twice should always work",
"DoubleLock",
LockingTwiceShouldSucceed,
LibInitMocked,
LibCleanup,
NULL
);
AddTestCase (
ShimTests,
"Locking a variable that's already locked by another policy should work", "LockAfterPolicy",
LockingALockedVariableShouldSucceed, LibInitMocked, LibCleanup, NULL
"Locking a variable that's already locked by another policy should work",
"LockAfterPolicy",
LockingALockedVariableShouldSucceed,
LibInitMocked,
LibCleanup,
NULL
);
AddTestCase (
ShimTests,
"Locking a variable that already has an unlocked policy should fail", "LockAfterUnlockedPolicy",
LockingAnUnlockedVariableShouldFail, LibInitMocked, LibCleanup, NULL
"Locking a variable that already has an unlocked policy should fail",
"LockAfterUnlockedPolicy",
LockingAnUnlockedVariableShouldFail,
LibInitMocked,
LibCleanup,
NULL
);
AddTestCase (
ShimTests,
"Locking a variable that already has an locked policy should succeed", "LockAfterLockedPolicyMatchingData",
LockingALockedVariableWithMatchingDataShouldSucceed, LibInitMocked, LibCleanup, NULL
"Locking a variable that already has an locked policy should succeed",
"LockAfterLockedPolicyMatchingData",
LockingALockedVariableWithMatchingDataShouldSucceed,
LibInitMocked,
LibCleanup,
NULL
);
AddTestCase (
ShimTests,
"Locking a variable that already has an locked policy with matching data should succeed", "LockAfterLockedPolicyNonMatchingData",
LockingALockedVariableWithNonMatchingDataShouldFail, LibInitMocked, LibCleanup, NULL
"Locking a variable that already has an locked policy with matching data should succeed",
"LockAfterLockedPolicyNonMatchingData",
LockingALockedVariableWithNonMatchingDataShouldFail,
LibInitMocked,
LibCleanup,
NULL
);
AddTestCase (
ShimTests,
"Adding a policy for a variable that has previously been locked should always fail", "SetPolicyAfterLock",
SettingPolicyForALockedVariableShouldFail, LibInitMocked, LibCleanup, NULL
"Adding a policy for a variable that has previously been locked should always fail",
"SetPolicyAfterLock",
SettingPolicyForALockedVariableShouldFail,
LibInitMocked,
LibCleanup,
NULL
);
//
@@ -543,7 +585,7 @@ EXIT:
///
/// Avoid ECC error for function name that starts with lower case letter
///
#define Main main
#define Main main
/**
Standard POSIX C entry point for host based unit test execution.

View File

@@ -42,11 +42,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
EFI_STATUS
SetVariableCheckHandlerMor (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
)
{
//
@@ -110,38 +110,43 @@ MorLockInitAtEndOfDxe (
VOID
)
{
EFI_STATUS Status;
EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy;
EFI_STATUS Status;
EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy;
// First, we obviously need to locate the VariablePolicy protocol.
Status = gBS->LocateProtocol( &gEdkiiVariablePolicyProtocolGuid, NULL, (VOID**)&VariablePolicy );
if (EFI_ERROR( Status )) {
DEBUG(( DEBUG_ERROR, "%a - Could not locate VariablePolicy protocol! %r\n", __FUNCTION__, Status ));
Status = gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid, NULL, (VOID **)&VariablePolicy);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a - Could not locate VariablePolicy protocol! %r\n", __FUNCTION__, Status));
return;
}
// If we're successful, go ahead and set the policies to protect the target variables.
Status = RegisterBasicVariablePolicy( VariablePolicy,
&gEfiMemoryOverwriteRequestControlLockGuid,
MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,
VARIABLE_POLICY_NO_MIN_SIZE,
VARIABLE_POLICY_NO_MAX_SIZE,
VARIABLE_POLICY_NO_MUST_ATTR,
VARIABLE_POLICY_NO_CANT_ATTR,
VARIABLE_POLICY_TYPE_LOCK_NOW );
if (EFI_ERROR( Status )) {
DEBUG(( DEBUG_ERROR, "%a - Could not lock variable %s! %r\n", __FUNCTION__, MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, Status ));
Status = RegisterBasicVariablePolicy (
VariablePolicy,
&gEfiMemoryOverwriteRequestControlLockGuid,
MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,
VARIABLE_POLICY_NO_MIN_SIZE,
VARIABLE_POLICY_NO_MAX_SIZE,
VARIABLE_POLICY_NO_MUST_ATTR,
VARIABLE_POLICY_NO_CANT_ATTR,
VARIABLE_POLICY_TYPE_LOCK_NOW
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a - Could not lock variable %s! %r\n", __FUNCTION__, MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, Status));
}
Status = RegisterBasicVariablePolicy( VariablePolicy,
&gEfiMemoryOverwriteControlDataGuid,
MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
VARIABLE_POLICY_NO_MIN_SIZE,
VARIABLE_POLICY_NO_MAX_SIZE,
VARIABLE_POLICY_NO_MUST_ATTR,
VARIABLE_POLICY_NO_CANT_ATTR,
VARIABLE_POLICY_TYPE_LOCK_NOW );
if (EFI_ERROR( Status )) {
DEBUG(( DEBUG_ERROR, "%a - Could not lock variable %s! %r\n", __FUNCTION__, MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, Status ));
Status = RegisterBasicVariablePolicy (
VariablePolicy,
&gEfiMemoryOverwriteControlDataGuid,
MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
VARIABLE_POLICY_NO_MIN_SIZE,
VARIABLE_POLICY_NO_MAX_SIZE,
VARIABLE_POLICY_NO_MUST_ATTR,
VARIABLE_POLICY_NO_CANT_ATTR,
VARIABLE_POLICY_TYPE_LOCK_NOW
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a - Could not lock variable %s! %r\n", __FUNCTION__, MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, Status));
}
return;

View File

@@ -23,34 +23,34 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/VariablePolicyLib.h>
typedef struct {
CHAR16 *VariableName;
EFI_GUID *VendorGuid;
CHAR16 *VariableName;
EFI_GUID *VendorGuid;
} VARIABLE_TYPE;
VARIABLE_TYPE mMorVariableType[] = {
{MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, &gEfiMemoryOverwriteControlDataGuid},
{MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid},
{ MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, &gEfiMemoryOverwriteControlDataGuid },
{ MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid },
};
BOOLEAN mMorPassThru = FALSE;
BOOLEAN mMorPassThru = FALSE;
#define MOR_LOCK_DATA_UNLOCKED 0x0
#define MOR_LOCK_DATA_LOCKED_WITHOUT_KEY 0x1
#define MOR_LOCK_DATA_LOCKED_WITH_KEY 0x2
#define MOR_LOCK_DATA_UNLOCKED 0x0
#define MOR_LOCK_DATA_LOCKED_WITHOUT_KEY 0x1
#define MOR_LOCK_DATA_LOCKED_WITH_KEY 0x2
#define MOR_LOCK_V1_SIZE 1
#define MOR_LOCK_V2_KEY_SIZE 8
typedef enum {
MorLockStateUnlocked = 0,
MorLockStateLocked = 1,
MorLockStateLocked = 1,
} MOR_LOCK_STATE;
BOOLEAN mMorLockInitializationRequired = FALSE;
UINT8 mMorLockKey[MOR_LOCK_V2_KEY_SIZE];
BOOLEAN mMorLockKeyEmpty = TRUE;
BOOLEAN mMorLockPassThru = FALSE;
MOR_LOCK_STATE mMorLockState = MorLockStateUnlocked;
MOR_LOCK_STATE mMorLockState = MorLockStateUnlocked;
/**
Returns if this is MOR related variable.
@@ -63,18 +63,20 @@ MOR_LOCK_STATE mMorLockState = MorLockStateUnlocked;
**/
BOOLEAN
IsAnyMorVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
)
{
UINTN Index;
UINTN Index;
for (Index = 0; Index < sizeof(mMorVariableType)/sizeof(mMorVariableType[0]); Index++) {
for (Index = 0; Index < sizeof (mMorVariableType)/sizeof (mMorVariableType[0]); Index++) {
if ((StrCmp (VariableName, mMorVariableType[Index].VariableName) == 0) &&
(CompareGuid (VendorGuid, mMorVariableType[Index].VendorGuid))) {
(CompareGuid (VendorGuid, mMorVariableType[Index].VendorGuid)))
{
return TRUE;
}
}
return FALSE;
}
@@ -89,14 +91,16 @@ IsAnyMorVariable (
**/
BOOLEAN
IsMorLockVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
)
{
if ((StrCmp (VariableName, MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME) == 0) &&
(CompareGuid (VendorGuid, &gEfiMemoryOverwriteRequestControlLockGuid))) {
(CompareGuid (VendorGuid, &gEfiMemoryOverwriteRequestControlLockGuid)))
{
return TRUE;
}
return FALSE;
}
@@ -127,13 +131,13 @@ SetMorLockVariable (
EFI_STATUS Status;
mMorLockPassThru = TRUE;
Status = VariableServiceSetVariable (
MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,
&gEfiMemoryOverwriteRequestControlLockGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(Data),
&Data
);
Status = VariableServiceSetVariable (
MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,
&gEfiMemoryOverwriteRequestControlLockGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof (Data),
&Data
);
mMorLockPassThru = FALSE;
return Status;
}
@@ -158,11 +162,11 @@ SetMorLockVariable (
**/
EFI_STATUS
SetVariableCheckHandlerMorLock (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
)
{
EFI_STATUS Status;
@@ -170,7 +174,7 @@ SetVariableCheckHandlerMorLock (
//
// Basic Check
//
if (Attributes == 0 || DataSize == 0 || Data == NULL) {
if ((Attributes == 0) || (DataSize == 0) || (Data == NULL)) {
//
// Permit deletion for passthru request, deny it otherwise.
//
@@ -178,7 +182,8 @@ SetVariableCheckHandlerMorLock (
}
if ((Attributes != (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)) ||
((DataSize != MOR_LOCK_V1_SIZE) && (DataSize != MOR_LOCK_V2_KEY_SIZE))) {
((DataSize != MOR_LOCK_V1_SIZE) && (DataSize != MOR_LOCK_V2_KEY_SIZE)))
{
return EFI_INVALID_PARAMETER;
}
@@ -245,7 +250,7 @@ SetVariableCheckHandlerMorLock (
// Need set here because the data value on flash is different
//
Status = SetMorLockVariable (MOR_LOCK_DATA_LOCKED_WITH_KEY);
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
//
// SetVar fail, do not provision the key
//
@@ -273,6 +278,7 @@ SetVariableCheckHandlerMorLock (
if (mMorLockKeyEmpty || (DataSize != MOR_LOCK_V2_KEY_SIZE)) {
return EFI_ACCESS_DENIED;
}
if ((CompareMem (Data, mMorLockKey, MOR_LOCK_V2_KEY_SIZE) == 0)) {
//
// Key match - unlock
@@ -291,9 +297,9 @@ SetVariableCheckHandlerMorLock (
//
// Unlock Success
//
mMorLockState = MorLockStateUnlocked;
mMorLockState = MorLockStateUnlocked;
mMorLockKeyEmpty = TRUE;
ZeroMem (mMorLockKey, sizeof(mMorLockKey));
ZeroMem (mMorLockKey, sizeof (mMorLockKey));
//
// return EFI_ALREADY_STARTED to skip variable set.
//
@@ -303,9 +309,9 @@ SetVariableCheckHandlerMorLock (
//
// Key mismatch - Prevent Dictionary Attack
//
mMorLockState = MorLockStateLocked;
mMorLockState = MorLockStateLocked;
mMorLockKeyEmpty = TRUE;
ZeroMem (mMorLockKey, sizeof(mMorLockKey));
ZeroMem (mMorLockKey, sizeof (mMorLockKey));
return EFI_ACCESS_DENIED;
}
}
@@ -332,11 +338,11 @@ SetVariableCheckHandlerMorLock (
**/
EFI_STATUS
SetVariableCheckHandlerMor (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
)
{
//
@@ -347,7 +353,7 @@ SetVariableCheckHandlerMor (
}
// Permit deletion when policy is disabled.
if (!IsVariablePolicyEnabled() && ((Attributes == 0) || (DataSize == 0))) {
if (!IsVariablePolicyEnabled () && ((Attributes == 0) || (DataSize == 0))) {
return EFI_SUCCESS;
}
@@ -379,16 +385,19 @@ SetVariableCheckHandlerMor (
// Basic Check
//
if ((Attributes != (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)) ||
(DataSize != sizeof(UINT8)) ||
(Data == NULL)) {
(DataSize != sizeof (UINT8)) ||
(Data == NULL))
{
return EFI_INVALID_PARAMETER;
}
if (mMorLockState == MorLockStateLocked) {
//
// If lock, deny access
//
return EFI_ACCESS_DENIED;
}
//
// grant access
//
@@ -420,10 +429,10 @@ MorLockInitAtEndOfDxe (
VOID
)
{
UINTN MorSize;
EFI_STATUS MorStatus;
EFI_STATUS Status;
VARIABLE_POLICY_ENTRY *NewPolicy;
UINTN MorSize;
EFI_STATUS MorStatus;
EFI_STATUS Status;
VARIABLE_POLICY_ENTRY *NewPolicy;
if (!mMorLockInitializationRequired) {
//
@@ -437,7 +446,7 @@ MorLockInitAtEndOfDxe (
//
// Check if the MOR variable exists.
//
MorSize = 0;
MorSize = 0;
MorStatus = VariableServiceGetVariable (
MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
&gEfiMemoryOverwriteControlDataGuid,
@@ -497,23 +506,27 @@ MorLockInitAtEndOfDxe (
// Lock the variable so that no other module may create it.
//
NewPolicy = NULL;
Status = CreateBasicVariablePolicy( &gEfiMemoryOverwriteControlDataGuid,
MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
VARIABLE_POLICY_NO_MIN_SIZE,
VARIABLE_POLICY_NO_MAX_SIZE,
VARIABLE_POLICY_NO_MUST_ATTR,
VARIABLE_POLICY_NO_CANT_ATTR,
VARIABLE_POLICY_TYPE_LOCK_NOW,
&NewPolicy );
if (!EFI_ERROR( Status )) {
Status = RegisterVariablePolicy( NewPolicy );
Status = CreateBasicVariablePolicy (
&gEfiMemoryOverwriteControlDataGuid,
MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
VARIABLE_POLICY_NO_MIN_SIZE,
VARIABLE_POLICY_NO_MAX_SIZE,
VARIABLE_POLICY_NO_MUST_ATTR,
VARIABLE_POLICY_NO_CANT_ATTR,
VARIABLE_POLICY_TYPE_LOCK_NOW,
&NewPolicy
);
if (!EFI_ERROR (Status)) {
Status = RegisterVariablePolicy (NewPolicy);
}
if (EFI_ERROR( Status )) {
DEBUG(( DEBUG_ERROR, "%a - Failed to lock variable %s! %r\n", __FUNCTION__, MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, Status ));
ASSERT_EFI_ERROR( Status );
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a - Failed to lock variable %s! %r\n", __FUNCTION__, MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, Status));
ASSERT_EFI_ERROR (Status);
}
if (NewPolicy != NULL) {
FreePool( NewPolicy );
FreePool (NewPolicy);
}
//
@@ -531,22 +544,26 @@ MorLockInitAtEndOfDxe (
mMorLockPassThru = FALSE;
NewPolicy = NULL;
Status = CreateBasicVariablePolicy( &gEfiMemoryOverwriteRequestControlLockGuid,
MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,
VARIABLE_POLICY_NO_MIN_SIZE,
VARIABLE_POLICY_NO_MAX_SIZE,
VARIABLE_POLICY_NO_MUST_ATTR,
VARIABLE_POLICY_NO_CANT_ATTR,
VARIABLE_POLICY_TYPE_LOCK_NOW,
&NewPolicy );
if (!EFI_ERROR( Status )) {
Status = RegisterVariablePolicy( NewPolicy );
Status = CreateBasicVariablePolicy (
&gEfiMemoryOverwriteRequestControlLockGuid,
MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,
VARIABLE_POLICY_NO_MIN_SIZE,
VARIABLE_POLICY_NO_MAX_SIZE,
VARIABLE_POLICY_NO_MUST_ATTR,
VARIABLE_POLICY_NO_CANT_ATTR,
VARIABLE_POLICY_TYPE_LOCK_NOW,
&NewPolicy
);
if (!EFI_ERROR (Status)) {
Status = RegisterVariablePolicy (NewPolicy);
}
if (EFI_ERROR( Status )) {
DEBUG(( DEBUG_ERROR, "%a - Failed to lock variable %s! %r\n", __FUNCTION__, MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, Status ));
ASSERT_EFI_ERROR( Status );
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a - Failed to lock variable %s! %r\n", __FUNCTION__, MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, Status));
ASSERT_EFI_ERROR (Status);
}
if (NewPolicy != NULL) {
FreePool( NewPolicy );
FreePool (NewPolicy);
}
}

View File

@@ -27,10 +27,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
EFI_STATUS
EFIAPI
VarCheckRegisterSetVariableCheckHandler (
IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler
IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler
)
{
EFI_STATUS Status;
EFI_STATUS Status;
AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
Status = VarCheckLibRegisterSetVariableCheckHandler (Handler);
@@ -57,12 +57,12 @@ VarCheckRegisterSetVariableCheckHandler (
EFI_STATUS
EFIAPI
VarCheckVariablePropertySet (
IN CHAR16 *Name,
IN EFI_GUID *Guid,
IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
IN CHAR16 *Name,
IN EFI_GUID *Guid,
IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
)
{
EFI_STATUS Status;
EFI_STATUS Status;
AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
Status = VarCheckLibVariablePropertySet (Name, Guid, VariableProperty);
@@ -86,12 +86,12 @@ VarCheckVariablePropertySet (
EFI_STATUS
EFIAPI
VarCheckVariablePropertyGet (
IN CHAR16 *Name,
IN EFI_GUID *Guid,
OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
IN CHAR16 *Name,
IN EFI_GUID *Guid,
OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
)
{
EFI_STATUS Status;
EFI_STATUS Status;
AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
Status = VarCheckLibVariablePropertyGet (Name, Guid, VariableProperty);
@@ -99,4 +99,3 @@ VarCheckVariablePropertyGet (
return Status;
}

File diff suppressed because it is too large Load Diff

View File

@@ -40,12 +40,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "PrivilegePolymorphic.h"
#define NV_STORAGE_VARIABLE_BASE (EFI_PHYSICAL_ADDRESS) \
#define NV_STORAGE_VARIABLE_BASE (EFI_PHYSICAL_ADDRESS)\
(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ? \
PcdGet64 (PcdFlashNvStorageVariableBase64) : \
PcdGet32 (PcdFlashNvStorageVariableBase))
#define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE | \
#define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE |\
EFI_VARIABLE_BOOTSERVICE_ACCESS | \
EFI_VARIABLE_RUNTIME_ACCESS | \
EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
@@ -55,7 +55,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
///
/// The size of a 3 character ISO639 language code.
///
#define ISO_639_2_ENTRY_SIZE 3
#define ISO_639_2_ENTRY_SIZE 3
typedef enum {
VariableStoreTypeVolatile,
@@ -65,65 +65,65 @@ typedef enum {
} VARIABLE_STORE_TYPE;
typedef struct {
UINT32 PendingUpdateOffset;
UINT32 PendingUpdateLength;
VARIABLE_STORE_HEADER *Store;
UINT32 PendingUpdateOffset;
UINT32 PendingUpdateLength;
VARIABLE_STORE_HEADER *Store;
} VARIABLE_RUNTIME_CACHE;
typedef struct {
BOOLEAN *ReadLock;
BOOLEAN *PendingUpdate;
BOOLEAN *HobFlushComplete;
VARIABLE_RUNTIME_CACHE VariableRuntimeHobCache;
VARIABLE_RUNTIME_CACHE VariableRuntimeNvCache;
VARIABLE_RUNTIME_CACHE VariableRuntimeVolatileCache;
BOOLEAN *ReadLock;
BOOLEAN *PendingUpdate;
BOOLEAN *HobFlushComplete;
VARIABLE_RUNTIME_CACHE VariableRuntimeHobCache;
VARIABLE_RUNTIME_CACHE VariableRuntimeNvCache;
VARIABLE_RUNTIME_CACHE VariableRuntimeVolatileCache;
} VARIABLE_RUNTIME_CACHE_CONTEXT;
typedef struct {
VARIABLE_HEADER *CurrPtr;
VARIABLE_HEADER *CurrPtr;
//
// If both ADDED and IN_DELETED_TRANSITION variable are present,
// InDeletedTransitionPtr will point to the IN_DELETED_TRANSITION one.
// Otherwise, CurrPtr will point to the ADDED or IN_DELETED_TRANSITION one,
// and InDeletedTransitionPtr will be NULL at the same time.
//
VARIABLE_HEADER *InDeletedTransitionPtr;
VARIABLE_HEADER *EndPtr;
VARIABLE_HEADER *StartPtr;
BOOLEAN Volatile;
VARIABLE_HEADER *InDeletedTransitionPtr;
VARIABLE_HEADER *EndPtr;
VARIABLE_HEADER *StartPtr;
BOOLEAN Volatile;
} VARIABLE_POINTER_TRACK;
typedef struct {
EFI_PHYSICAL_ADDRESS HobVariableBase;
EFI_PHYSICAL_ADDRESS VolatileVariableBase;
EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;
VARIABLE_RUNTIME_CACHE_CONTEXT VariableRuntimeCacheContext;
EFI_LOCK VariableServicesLock;
UINT32 ReentrantState;
BOOLEAN AuthFormat;
BOOLEAN AuthSupport;
BOOLEAN EmuNvMode;
EFI_PHYSICAL_ADDRESS HobVariableBase;
EFI_PHYSICAL_ADDRESS VolatileVariableBase;
EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;
VARIABLE_RUNTIME_CACHE_CONTEXT VariableRuntimeCacheContext;
EFI_LOCK VariableServicesLock;
UINT32 ReentrantState;
BOOLEAN AuthFormat;
BOOLEAN AuthSupport;
BOOLEAN EmuNvMode;
} VARIABLE_GLOBAL;
typedef struct {
VARIABLE_GLOBAL VariableGlobal;
UINTN VolatileLastVariableOffset;
UINTN NonVolatileLastVariableOffset;
UINTN CommonVariableSpace;
UINTN CommonMaxUserVariableSpace;
UINTN CommonRuntimeVariableSpace;
UINTN CommonVariableTotalSize;
UINTN CommonUserVariableTotalSize;
UINTN HwErrVariableTotalSize;
UINTN MaxVariableSize;
UINTN MaxAuthVariableSize;
UINTN MaxVolatileVariableSize;
UINTN ScratchBufferSize;
CHAR8 *PlatformLangCodes;
CHAR8 *LangCodes;
CHAR8 *PlatformLang;
CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1];
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance;
VARIABLE_GLOBAL VariableGlobal;
UINTN VolatileLastVariableOffset;
UINTN NonVolatileLastVariableOffset;
UINTN CommonVariableSpace;
UINTN CommonMaxUserVariableSpace;
UINTN CommonRuntimeVariableSpace;
UINTN CommonVariableTotalSize;
UINTN CommonUserVariableTotalSize;
UINTN HwErrVariableTotalSize;
UINTN MaxVariableSize;
UINTN MaxAuthVariableSize;
UINTN MaxVolatileVariableSize;
UINTN ScratchBufferSize;
CHAR8 *PlatformLangCodes;
CHAR8 *LangCodes;
CHAR8 *PlatformLang;
CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1];
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance;
} VARIABLE_MODULE_GLOBAL;
/**
@@ -135,8 +135,8 @@ typedef struct {
**/
VOID
FlushHobVariableToFlash (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
);
/**
@@ -218,8 +218,8 @@ FindVariable (
BOOLEAN
EFIAPI
CheckRemainingSpaceForConsistencyInternal (
IN UINT32 Attributes,
IN VA_LIST Marker
IN UINT32 Attributes,
IN VA_LIST Marker
);
/**
@@ -243,18 +243,17 @@ CheckRemainingSpaceForConsistencyInternal (
**/
EFI_STATUS
UpdateVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN VOID *Data,
IN UINTN DataSize,
IN UINT32 Attributes OPTIONAL,
IN UINT32 KeyIndex OPTIONAL,
IN UINT64 MonotonicCount OPTIONAL,
IN OUT VARIABLE_POINTER_TRACK *Variable,
IN EFI_TIME *TimeStamp OPTIONAL
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN VOID *Data,
IN UINTN DataSize,
IN UINT32 Attributes OPTIONAL,
IN UINT32 KeyIndex OPTIONAL,
IN UINT64 MonotonicCount OPTIONAL,
IN OUT VARIABLE_POINTER_TRACK *Variable,
IN EFI_TIME *TimeStamp OPTIONAL
);
/**
Return TRUE if ExitBootServices () has been called.
@@ -284,10 +283,9 @@ AtRuntime (
EFI_LOCK *
InitializeLock (
IN OUT EFI_LOCK *Lock,
IN EFI_TPL Priority
IN EFI_TPL Priority
);
/**
Acquires lock only at boot time. Simply returns at runtime.
@@ -305,7 +303,6 @@ AcquireLockOnlyAtBootTime (
IN EFI_LOCK *Lock
);
/**
Releases lock only at boot time. Simply returns at runtime.
@@ -358,8 +355,8 @@ GetFvbByHandle (
**/
EFI_STATUS
GetFvbCountAndBuffer (
OUT UINTN *NumberHandles,
OUT EFI_HANDLE **Buffer
OUT UINTN *NumberHandles,
OUT EFI_HANDLE **Buffer
);
/**
@@ -379,7 +376,7 @@ VariableCommonInitialize (
**/
VOID
ReclaimForOS(
ReclaimForOS (
VOID
);
@@ -418,7 +415,7 @@ VariableWriteServiceInitialize (
**/
EFI_STATUS
GetFtwProtocol (
OUT VOID **FtwProtocol
OUT VOID **FtwProtocol
);
/**
@@ -461,11 +458,11 @@ GetFvbInfoByAddress (
EFI_STATUS
EFIAPI
VariableServiceGetVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT UINT32 *Attributes OPTIONAL,
IN OUT UINTN *DataSize,
OUT VOID *Data OPTIONAL
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT UINT32 *Attributes OPTIONAL,
IN OUT UINTN *DataSize,
OUT VOID *Data OPTIONAL
);
/**
@@ -496,9 +493,9 @@ VariableServiceGetVariable (
EFI_STATUS
EFIAPI
VariableServiceGetNextVariableName (
IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VendorGuid
IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VendorGuid
);
/**
@@ -529,11 +526,11 @@ VariableServiceGetNextVariableName (
EFI_STATUS
EFIAPI
VariableServiceSetVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
);
/**
@@ -558,10 +555,10 @@ VariableServiceSetVariable (
EFI_STATUS
EFIAPI
VariableServiceQueryVariableInfoInternal (
IN UINT32 Attributes,
OUT UINT64 *MaximumVariableStorageSize,
OUT UINT64 *RemainingVariableStorageSize,
OUT UINT64 *MaximumVariableSize
IN UINT32 Attributes,
OUT UINT64 *MaximumVariableStorageSize,
OUT UINT64 *RemainingVariableStorageSize,
OUT UINT64 *MaximumVariableSize
);
/**
@@ -588,10 +585,10 @@ VariableServiceQueryVariableInfoInternal (
EFI_STATUS
EFIAPI
VariableServiceQueryVariableInfo (
IN UINT32 Attributes,
OUT UINT64 *MaximumVariableStorageSize,
OUT UINT64 *RemainingVariableStorageSize,
OUT UINT64 *MaximumVariableSize
IN UINT32 Attributes,
OUT UINT64 *MaximumVariableStorageSize,
OUT UINT64 *RemainingVariableStorageSize,
OUT UINT64 *MaximumVariableSize
);
/**
@@ -612,9 +609,9 @@ VariableServiceQueryVariableInfo (
EFI_STATUS
EFIAPI
VariableLockRequestToLock (
IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
);
/**
@@ -634,7 +631,7 @@ VariableLockRequestToLock (
EFI_STATUS
EFIAPI
VarCheckRegisterSetVariableCheckHandler (
IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler
IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler
);
/**
@@ -655,9 +652,9 @@ VarCheckRegisterSetVariableCheckHandler (
EFI_STATUS
EFIAPI
VarCheckVariablePropertySet (
IN CHAR16 *Name,
IN EFI_GUID *Guid,
IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
IN CHAR16 *Name,
IN EFI_GUID *Guid,
IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
);
/**
@@ -675,9 +672,9 @@ VarCheckVariablePropertySet (
EFI_STATUS
EFIAPI
VarCheckVariablePropertyGet (
IN CHAR16 *Name,
IN EFI_GUID *Guid,
OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
IN CHAR16 *Name,
IN EFI_GUID *Guid,
OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
);
/**
@@ -689,14 +686,14 @@ InitializeVariableQuota (
VOID
);
extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;
extern EFI_FIRMWARE_VOLUME_HEADER *mNvFvHeaderCache;
extern VARIABLE_STORE_HEADER *mNvVariableCache;
extern VARIABLE_INFO_ENTRY *gVariableInfo;
extern BOOLEAN mEndOfDxe;
extern VAR_CHECK_REQUEST_SOURCE mRequestSource;
extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;
extern EFI_FIRMWARE_VOLUME_HEADER *mNvFvHeaderCache;
extern VARIABLE_STORE_HEADER *mNvVariableCache;
extern VARIABLE_INFO_ENTRY *gVariableInfo;
extern BOOLEAN mEndOfDxe;
extern VAR_CHECK_REQUEST_SOURCE mRequestSource;
extern AUTH_VAR_LIB_CONTEXT_OUT mAuthContextOut;
extern AUTH_VAR_LIB_CONTEXT_OUT mAuthContextOut;
/**
Finds variable in storage blocks of volatile and non-volatile storage areas.
@@ -719,9 +716,9 @@ extern AUTH_VAR_LIB_CONTEXT_OUT mAuthContextOut;
EFI_STATUS
EFIAPI
VariableExLibFindVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT AUTH_VARIABLE_INFO *AuthVariableInfo
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT AUTH_VARIABLE_INFO *AuthVariableInfo
);
/**
@@ -745,9 +742,9 @@ VariableExLibFindVariable (
EFI_STATUS
EFIAPI
VariableExLibFindNextVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT AUTH_VARIABLE_INFO *AuthVariableInfo
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT AUTH_VARIABLE_INFO *AuthVariableInfo
);
/**
@@ -765,7 +762,7 @@ VariableExLibFindNextVariable (
EFI_STATUS
EFIAPI
VariableExLibUpdateVariable (
IN AUTH_VARIABLE_INFO *AuthVariableInfo
IN AUTH_VARIABLE_INFO *AuthVariableInfo
);
/**
@@ -783,8 +780,8 @@ VariableExLibUpdateVariable (
EFI_STATUS
EFIAPI
VariableExLibGetScratchBuffer (
IN OUT UINTN *ScratchBufferSize,
OUT VOID **ScratchBuffer
IN OUT UINTN *ScratchBufferSize,
OUT VOID **ScratchBuffer
);
/**
@@ -809,7 +806,7 @@ VariableExLibGetScratchBuffer (
BOOLEAN
EFIAPI
VariableExLibCheckRemainingSpaceForConsistency (
IN UINT32 Attributes,
IN UINT32 Attributes,
...
);

View File

@@ -18,24 +18,28 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
EFI_STATUS
EFIAPI
ProtocolIsVariablePolicyEnabled (
OUT BOOLEAN *State
OUT BOOLEAN *State
);
EFI_HANDLE mHandle = NULL;
EFI_EVENT mVirtualAddressChangeEvent = NULL;
VOID *mFtwRegistration = NULL;
VOID ***mVarCheckAddressPointer = NULL;
UINTN mVarCheckAddressPointerCount = 0;
EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock = { VariableLockRequestToLock };
EDKII_VARIABLE_POLICY_PROTOCOL mVariablePolicyProtocol = { EDKII_VARIABLE_POLICY_PROTOCOL_REVISION,
DisableVariablePolicy,
ProtocolIsVariablePolicyEnabled,
RegisterVariablePolicy,
DumpVariablePolicy,
LockVariablePolicy };
EDKII_VAR_CHECK_PROTOCOL mVarCheck = { VarCheckRegisterSetVariableCheckHandler,
VarCheckVariablePropertySet,
VarCheckVariablePropertyGet };
EFI_HANDLE mHandle = NULL;
EFI_EVENT mVirtualAddressChangeEvent = NULL;
VOID *mFtwRegistration = NULL;
VOID ***mVarCheckAddressPointer = NULL;
UINTN mVarCheckAddressPointerCount = 0;
EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock = { VariableLockRequestToLock };
EDKII_VARIABLE_POLICY_PROTOCOL mVariablePolicyProtocol = {
EDKII_VARIABLE_POLICY_PROTOCOL_REVISION,
DisableVariablePolicy,
ProtocolIsVariablePolicyEnabled,
RegisterVariablePolicy,
DumpVariablePolicy,
LockVariablePolicy
};
EDKII_VAR_CHECK_PROTOCOL mVarCheck = {
VarCheckRegisterSetVariableCheckHandler,
VarCheckVariablePropertySet,
VarCheckVariablePropertyGet
};
/**
Some Secure Boot Policy Variable may update following other variable changes(SecureBoot follows PK change, etc).
@@ -44,7 +48,7 @@ EDKII_VAR_CHECK_PROTOCOL mVarCheck = { VarCheckRegis
**/
VOID
EFIAPI
RecordSecureBootPolicyVarData(
RecordSecureBootPolicyVarData (
VOID
);
@@ -61,7 +65,6 @@ AtRuntime (
return EfiAtRuntime ();
}
/**
Initializes a basic mutual exclusion lock.
@@ -80,14 +83,13 @@ AtRuntime (
**/
EFI_LOCK *
InitializeLock (
IN OUT EFI_LOCK *Lock,
IN EFI_TPL Priority
IN OUT EFI_LOCK *Lock,
IN EFI_TPL Priority
)
{
return EfiInitializeLock (Lock, Priority);
}
/**
Acquires lock only at boot time. Simply returns at runtime.
@@ -102,7 +104,7 @@ InitializeLock (
**/
VOID
AcquireLockOnlyAtBootTime (
IN EFI_LOCK *Lock
IN EFI_LOCK *Lock
)
{
if (!AtRuntime ()) {
@@ -110,7 +112,6 @@ AcquireLockOnlyAtBootTime (
}
}
/**
Releases lock only at boot time. Simply returns at runtime.
@@ -125,7 +126,7 @@ AcquireLockOnlyAtBootTime (
**/
VOID
ReleaseLockOnlyAtBootTime (
IN EFI_LOCK *Lock
IN EFI_LOCK *Lock
)
{
if (!AtRuntime ()) {
@@ -145,10 +146,10 @@ ReleaseLockOnlyAtBootTime (
**/
EFI_STATUS
GetFtwProtocol (
OUT VOID **FtwProtocol
OUT VOID **FtwProtocol
)
{
EFI_STATUS Status;
EFI_STATUS Status;
//
// Locate Fault Tolerent Write protocol
@@ -185,11 +186,10 @@ GetFvbByHandle (
return gBS->HandleProtocol (
FvBlockHandle,
&gEfiFirmwareVolumeBlockProtocolGuid,
(VOID **) FvBlock
(VOID **)FvBlock
);
}
/**
Function returns an array of handles that support the FVB protocol
in a buffer allocated from pool.
@@ -207,11 +207,11 @@ GetFvbByHandle (
**/
EFI_STATUS
GetFvbCountAndBuffer (
OUT UINTN *NumberHandles,
OUT EFI_HANDLE **Buffer
OUT UINTN *NumberHandles,
OUT EFI_HANDLE **Buffer
)
{
EFI_STATUS Status;
EFI_STATUS Status;
//
// Locate all handles of Fvb protocol
@@ -226,7 +226,6 @@ GetFvbCountAndBuffer (
return Status;
}
/**
Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
@@ -240,46 +239,46 @@ GetFvbCountAndBuffer (
VOID
EFIAPI
VariableClassAddressChangeEvent (
IN EFI_EVENT Event,
IN VOID *Context
IN EFI_EVENT Event,
IN VOID *Context
)
{
UINTN Index;
UINTN Index;
if (mVariableModuleGlobal->FvbInstance != NULL) {
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetBlockSize);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetAttributes);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->SetAttributes);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Read);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Write);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->EraseBlocks);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance->GetBlockSize);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance->GetAttributes);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance->SetAttributes);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance->Read);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance->Write);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance->EraseBlocks);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->FvbInstance);
}
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.HobVariableBase);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
EfiConvertPointer (0x0, (VOID **) &mNvVariableCache);
EfiConvertPointer (0x0, (VOID **) &mNvFvHeaderCache);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->PlatformLangCodes);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->LangCodes);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->PlatformLang);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal->VariableGlobal.HobVariableBase);
EfiConvertPointer (0x0, (VOID **)&mVariableModuleGlobal);
EfiConvertPointer (0x0, (VOID **)&mNvVariableCache);
EfiConvertPointer (0x0, (VOID **)&mNvFvHeaderCache);
if (mAuthContextOut.AddressPointer != NULL) {
for (Index = 0; Index < mAuthContextOut.AddressPointerCount; Index++) {
EfiConvertPointer (0x0, (VOID **) mAuthContextOut.AddressPointer[Index]);
EfiConvertPointer (0x0, (VOID **)mAuthContextOut.AddressPointer[Index]);
}
}
if (mVarCheckAddressPointer != NULL) {
for (Index = 0; Index < mVarCheckAddressPointerCount; Index++) {
EfiConvertPointer (0x0, (VOID **) mVarCheckAddressPointer[Index]);
EfiConvertPointer (0x0, (VOID **)mVarCheckAddressPointer[Index]);
}
}
}
/**
Notification function of EVT_GROUP_READY_TO_BOOT event group.
@@ -294,11 +293,11 @@ VariableClassAddressChangeEvent (
VOID
EFIAPI
OnReadyToBoot (
EFI_EVENT Event,
VOID *Context
EFI_EVENT Event,
VOID *Context
)
{
EFI_STATUS Status;
EFI_STATUS Status;
if (!mEndOfDxe) {
MorLockInitAtEndOfDxe ();
@@ -308,13 +307,14 @@ OnReadyToBoot (
//
// Set the End Of DXE bit in case the EFI_END_OF_DXE_EVENT_GROUP_GUID event is not signaled.
//
mEndOfDxe = TRUE;
mEndOfDxe = TRUE;
mVarCheckAddressPointer = VarCheckLibInitializeAtEndOfDxe (&mVarCheckAddressPointerCount);
//
// The initialization for variable quota.
//
InitializeVariableQuota ();
}
ReclaimForOS ();
if (FeaturePcdGet (PcdVariableCollectStatistics)) {
if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
@@ -339,17 +339,17 @@ OnReadyToBoot (
VOID
EFIAPI
OnEndOfDxe (
EFI_EVENT Event,
VOID *Context
EFI_EVENT Event,
VOID *Context
)
{
EFI_STATUS Status;
EFI_STATUS Status;
DEBUG ((DEBUG_INFO, "[Variable]END_OF_DXE is signaled\n"));
MorLockInitAtEndOfDxe ();
Status = LockVariablePolicy ();
ASSERT_EFI_ERROR (Status);
mEndOfDxe = TRUE;
mEndOfDxe = TRUE;
mVarCheckAddressPointer = VarCheckLibInitializeAtEndOfDxe (&mVarCheckAddressPointerCount);
//
// The initialization for variable quota.
@@ -371,7 +371,7 @@ VariableWriteServiceInitializeDxe (
VOID
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = VariableWriteServiceInitialize ();
if (EFI_ERROR (Status)) {
@@ -382,7 +382,7 @@ VariableWriteServiceInitializeDxe (
// Some Secure Boot Policy Var (SecureBoot, etc) updates following other
// Secure Boot Policy Variable change. Record their initial value.
//
RecordSecureBootPolicyVarData();
RecordSecureBootPolicyVarData ();
//
// Install the Variable Write Architectural protocol.
@@ -409,27 +409,27 @@ VariableWriteServiceInitializeDxe (
VOID
EFIAPI
FtwNotificationEvent (
IN EFI_EVENT Event,
IN VOID *Context
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;
EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
EFI_PHYSICAL_ADDRESS BaseAddress;
UINT64 Length;
EFI_PHYSICAL_ADDRESS VariableStoreBase;
UINT64 VariableStoreLength;
UINTN FtwMaxBlockSize;
EFI_STATUS Status;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;
EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
EFI_PHYSICAL_ADDRESS BaseAddress;
UINT64 Length;
EFI_PHYSICAL_ADDRESS VariableStoreBase;
UINT64 VariableStoreLength;
UINTN FtwMaxBlockSize;
//
// Ensure FTW protocol is installed.
//
Status = GetFtwProtocol ((VOID**) &FtwProtocol);
Status = GetFtwProtocol ((VOID **)&FtwProtocol);
if (EFI_ERROR (Status)) {
return ;
return;
}
Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);
@@ -438,7 +438,7 @@ FtwNotificationEvent (
}
NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;
VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
//
// Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.
@@ -450,19 +450,20 @@ FtwNotificationEvent (
//
Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);
if (EFI_ERROR (Status)) {
return ;
return;
}
mVariableModuleGlobal->FvbInstance = FvbProtocol;
//
// Mark the variable storage region of the FLASH as RUNTIME.
//
VariableStoreLength = mNvVariableCache->Size;
BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);
Length = VariableStoreLength + (VariableStoreBase - BaseAddress);
Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);
BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);
Length = VariableStoreLength + (VariableStoreBase - BaseAddress);
Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);
Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "Variable driver failed to get flash memory attribute.\n"));
} else {
@@ -487,10 +488,8 @@ FtwNotificationEvent (
// Close the notify event to avoid install gEfiVariableWriteArchProtocolGuid again.
//
gBS->CloseEvent (Event);
}
/**
This API function returns whether or not the policy engine is
currently being enforced.
@@ -505,14 +504,13 @@ FtwNotificationEvent (
EFI_STATUS
EFIAPI
ProtocolIsVariablePolicyEnabled (
OUT BOOLEAN *State
OUT BOOLEAN *State
)
{
*State = IsVariablePolicyEnabled ();
return EFI_SUCCESS;
}
/**
Variable Driver main entry point. The Variable driver places the 4 EFI
runtime services in the EFI System Table and installs arch protocols
@@ -528,13 +526,13 @@ ProtocolIsVariablePolicyEnabled (
EFI_STATUS
EFIAPI
VariableServiceInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_EVENT ReadyToBootEvent;
EFI_EVENT EndOfDxeEvent;
EFI_STATUS Status;
EFI_EVENT ReadyToBootEvent;
EFI_EVENT EndOfDxeEvent;
Status = VariableCommonInitialize ();
ASSERT_EFI_ERROR (Status);
@@ -629,11 +627,11 @@ VariableServiceInitialize (
Status = VarCheckRegisterSetVariableCheckHandler (ValidateSetVariable);
ASSERT_EFI_ERROR (Status);
Status = gBS->InstallMultipleProtocolInterfaces (
&mHandle,
&gEdkiiVariablePolicyProtocolGuid,
&mVariablePolicyProtocol,
NULL
);
&mHandle,
&gEdkiiVariablePolicyProtocolGuid,
&mVariablePolicyProtocol,
NULL
);
ASSERT_EFI_ERROR (Status);
return EFI_SUCCESS;

View File

@@ -30,14 +30,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
EFI_STATUS
EFIAPI
VariableExLibFindVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT AUTH_VARIABLE_INFO *AuthVariableInfo
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT AUTH_VARIABLE_INFO *AuthVariableInfo
)
{
EFI_STATUS Status;
VARIABLE_POINTER_TRACK Variable;
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
EFI_STATUS Status;
VARIABLE_POINTER_TRACK Variable;
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
Status = FindVariable (
VariableName,
@@ -47,23 +47,23 @@ VariableExLibFindVariable (
FALSE
);
if (EFI_ERROR (Status)) {
AuthVariableInfo->Data = NULL;
AuthVariableInfo->DataSize = 0;
AuthVariableInfo->Attributes = 0;
AuthVariableInfo->PubKeyIndex = 0;
AuthVariableInfo->Data = NULL;
AuthVariableInfo->DataSize = 0;
AuthVariableInfo->Attributes = 0;
AuthVariableInfo->PubKeyIndex = 0;
AuthVariableInfo->MonotonicCount = 0;
AuthVariableInfo->TimeStamp = NULL;
AuthVariableInfo->TimeStamp = NULL;
return Status;
}
AuthVariableInfo->DataSize = DataSizeOfVariable (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
AuthVariableInfo->Data = GetVariableDataPtr (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
AuthVariableInfo->Attributes = Variable.CurrPtr->Attributes;
AuthVariableInfo->DataSize = DataSizeOfVariable (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
AuthVariableInfo->Data = GetVariableDataPtr (Variable.CurrPtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
AuthVariableInfo->Attributes = Variable.CurrPtr->Attributes;
if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable.CurrPtr;
AuthVariableInfo->PubKeyIndex = AuthVariable->PubKeyIndex;
AuthVariableInfo->MonotonicCount = ReadUnaligned64 (&(AuthVariable->MonotonicCount));
AuthVariableInfo->TimeStamp = &AuthVariable->TimeStamp;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable.CurrPtr;
AuthVariableInfo->PubKeyIndex = AuthVariable->PubKeyIndex;
AuthVariableInfo->MonotonicCount = ReadUnaligned64 (&(AuthVariable->MonotonicCount));
AuthVariableInfo->TimeStamp = &AuthVariable->TimeStamp;
}
return EFI_SUCCESS;
@@ -90,18 +90,18 @@ VariableExLibFindVariable (
EFI_STATUS
EFIAPI
VariableExLibFindNextVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT AUTH_VARIABLE_INFO *AuthVariableInfo
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT AUTH_VARIABLE_INFO *AuthVariableInfo
)
{
EFI_STATUS Status;
VARIABLE_HEADER *VariablePtr;
AUTHENTICATED_VARIABLE_HEADER *AuthVariablePtr;
VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax];
EFI_STATUS Status;
VARIABLE_HEADER *VariablePtr;
AUTHENTICATED_VARIABLE_HEADER *AuthVariablePtr;
VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax];
VariableStoreHeader[VariableStoreTypeVolatile] = (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;
VariableStoreHeader[VariableStoreTypeHob] = (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase;
VariableStoreHeader[VariableStoreTypeVolatile] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;
VariableStoreHeader[VariableStoreTypeHob] = (VARIABLE_STORE_HEADER *)(UINTN)mVariableModuleGlobal->VariableGlobal.HobVariableBase;
VariableStoreHeader[VariableStoreTypeNv] = mNvVariableCache;
Status = VariableServiceGetNextVariableInternal (
@@ -112,27 +112,27 @@ VariableExLibFindNextVariable (
mVariableModuleGlobal->VariableGlobal.AuthFormat
);
if (EFI_ERROR (Status)) {
AuthVariableInfo->VariableName = NULL;
AuthVariableInfo->VendorGuid = NULL;
AuthVariableInfo->Data = NULL;
AuthVariableInfo->DataSize = 0;
AuthVariableInfo->Attributes = 0;
AuthVariableInfo->PubKeyIndex = 0;
AuthVariableInfo->VariableName = NULL;
AuthVariableInfo->VendorGuid = NULL;
AuthVariableInfo->Data = NULL;
AuthVariableInfo->DataSize = 0;
AuthVariableInfo->Attributes = 0;
AuthVariableInfo->PubKeyIndex = 0;
AuthVariableInfo->MonotonicCount = 0;
AuthVariableInfo->TimeStamp = NULL;
AuthVariableInfo->TimeStamp = NULL;
return Status;
}
AuthVariableInfo->VariableName = GetVariableNamePtr (VariablePtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
AuthVariableInfo->VendorGuid = GetVendorGuidPtr (VariablePtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
AuthVariableInfo->DataSize = DataSizeOfVariable (VariablePtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
AuthVariableInfo->Data = GetVariableDataPtr (VariablePtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
AuthVariableInfo->Attributes = VariablePtr->Attributes;
AuthVariableInfo->VariableName = GetVariableNamePtr (VariablePtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
AuthVariableInfo->VendorGuid = GetVendorGuidPtr (VariablePtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
AuthVariableInfo->DataSize = DataSizeOfVariable (VariablePtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
AuthVariableInfo->Data = GetVariableDataPtr (VariablePtr, mVariableModuleGlobal->VariableGlobal.AuthFormat);
AuthVariableInfo->Attributes = VariablePtr->Attributes;
if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
AuthVariablePtr = (AUTHENTICATED_VARIABLE_HEADER *) VariablePtr;
AuthVariableInfo->PubKeyIndex = AuthVariablePtr->PubKeyIndex;
AuthVariableInfo->MonotonicCount = ReadUnaligned64 (&(AuthVariablePtr->MonotonicCount));
AuthVariableInfo->TimeStamp = &AuthVariablePtr->TimeStamp;
AuthVariablePtr = (AUTHENTICATED_VARIABLE_HEADER *)VariablePtr;
AuthVariableInfo->PubKeyIndex = AuthVariablePtr->PubKeyIndex;
AuthVariableInfo->MonotonicCount = ReadUnaligned64 (&(AuthVariablePtr->MonotonicCount));
AuthVariableInfo->TimeStamp = &AuthVariablePtr->TimeStamp;
}
return EFI_SUCCESS;
@@ -153,10 +153,10 @@ VariableExLibFindNextVariable (
EFI_STATUS
EFIAPI
VariableExLibUpdateVariable (
IN AUTH_VARIABLE_INFO *AuthVariableInfo
IN AUTH_VARIABLE_INFO *AuthVariableInfo
)
{
VARIABLE_POINTER_TRACK Variable;
VARIABLE_POINTER_TRACK Variable;
FindVariable (AuthVariableInfo->VariableName, AuthVariableInfo->VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
return UpdateVariable (
@@ -187,11 +187,11 @@ VariableExLibUpdateVariable (
EFI_STATUS
EFIAPI
VariableExLibGetScratchBuffer (
IN OUT UINTN *ScratchBufferSize,
OUT VOID **ScratchBuffer
IN OUT UINTN *ScratchBufferSize,
OUT VOID **ScratchBuffer
)
{
UINTN MaxBufferSize;
UINTN MaxBufferSize;
MaxBufferSize = mVariableModuleGlobal->ScratchBufferSize;
if (*ScratchBufferSize > MaxBufferSize) {
@@ -199,7 +199,7 @@ VariableExLibGetScratchBuffer (
return EFI_UNSUPPORTED;
}
*ScratchBuffer = GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase));
*ScratchBuffer = GetEndPointer ((VARIABLE_STORE_HEADER *)((UINTN)mVariableModuleGlobal->VariableGlobal.VolatileVariableBase));
return EFI_SUCCESS;
}
@@ -225,12 +225,12 @@ VariableExLibGetScratchBuffer (
BOOLEAN
EFIAPI
VariableExLibCheckRemainingSpaceForConsistency (
IN UINT32 Attributes,
IN UINT32 Attributes,
...
)
{
VA_LIST Marker;
BOOLEAN Return;
VA_LIST Marker;
BOOLEAN Return;
VA_START (Marker, Attributes);

View File

@@ -53,17 +53,17 @@ VariableLockRequestToLock (
DEBUG ((DEBUG_WARN, "!!! DEPRECATED INTERFACE !!! Variable: %g %s\n", VendorGuid, VariableName));
NewPolicy = NULL;
Status = CreateBasicVariablePolicy(
VendorGuid,
VariableName,
VARIABLE_POLICY_NO_MIN_SIZE,
VARIABLE_POLICY_NO_MAX_SIZE,
VARIABLE_POLICY_NO_MUST_ATTR,
VARIABLE_POLICY_NO_CANT_ATTR,
VARIABLE_POLICY_TYPE_LOCK_NOW,
&NewPolicy
);
if (!EFI_ERROR( Status )) {
Status = CreateBasicVariablePolicy (
VendorGuid,
VariableName,
VARIABLE_POLICY_NO_MIN_SIZE,
VARIABLE_POLICY_NO_MAX_SIZE,
VARIABLE_POLICY_NO_MUST_ATTR,
VARIABLE_POLICY_NO_CANT_ATTR,
VARIABLE_POLICY_TYPE_LOCK_NOW,
&NewPolicy
);
if (!EFI_ERROR (Status)) {
Status = RegisterVariablePolicy (NewPolicy);
//
@@ -83,11 +83,13 @@ VariableLockRequestToLock (
}
}
}
if (EFI_ERROR (Status)) {
DEBUG(( DEBUG_ERROR, "%a - Failed to lock variable %s! %r\n", __FUNCTION__, VariableName, Status ));
DEBUG ((DEBUG_ERROR, "%a - Failed to lock variable %s! %r\n", __FUNCTION__, VariableName, Status));
}
if (NewPolicy != NULL) {
FreePool( NewPolicy );
FreePool (NewPolicy);
}
return Status;

View File

@@ -23,8 +23,10 @@ GetNonVolatileMaxVariableSize (
)
{
if (PcdGet32 (PcdHwErrStorageSize) != 0) {
return MAX (MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxAuthVariableSize)),
PcdGet32 (PcdMaxHardwareErrorVariableSize));
return MAX (
MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxAuthVariableSize)),
PcdGet32 (PcdMaxHardwareErrorVariableSize)
);
} else {
return MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxAuthVariableSize));
}
@@ -44,10 +46,10 @@ InitEmuNonVolatileVariableStore (
OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase
)
{
VARIABLE_STORE_HEADER *VariableStore;
UINT32 VariableStoreLength;
BOOLEAN FullyInitializeStore;
UINT32 HwErrStorageSize;
VARIABLE_STORE_HEADER *VariableStore;
UINT32 VariableStoreLength;
BOOLEAN FullyInitializeStore;
UINT32 HwErrStorageSize;
FullyInitializeStore = TRUE;
@@ -58,7 +60,7 @@ InitEmuNonVolatileVariableStore (
// Allocate memory for variable store.
//
if (PcdGet64 (PcdEmuVariableNvStoreReserved) == 0) {
VariableStore = (VARIABLE_STORE_HEADER *) AllocateRuntimePool (VariableStoreLength);
VariableStore = (VARIABLE_STORE_HEADER *)AllocateRuntimePool (VariableStoreLength);
if (VariableStore == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -69,14 +71,15 @@ InitEmuNonVolatileVariableStore (
// thereby providing better NV variable emulation.
//
VariableStore =
(VARIABLE_STORE_HEADER *)(VOID*)(UINTN)
PcdGet64 (PcdEmuVariableNvStoreReserved);
(VARIABLE_STORE_HEADER *)(VOID *)(UINTN)
PcdGet64 (PcdEmuVariableNvStoreReserved);
if ((VariableStore->Size == VariableStoreLength) &&
(CompareGuid (&VariableStore->Signature, &gEfiAuthenticatedVariableGuid) ||
CompareGuid (&VariableStore->Signature, &gEfiVariableGuid)) &&
(VariableStore->Format == VARIABLE_STORE_FORMATTED) &&
(VariableStore->State == VARIABLE_STORE_HEALTHY)) {
DEBUG((
(VariableStore->State == VARIABLE_STORE_HEALTHY))
{
DEBUG ((
DEBUG_INFO,
"Variable Store reserved at %p appears to be valid\n",
VariableStore
@@ -91,14 +94,14 @@ InitEmuNonVolatileVariableStore (
// Use gEfiAuthenticatedVariableGuid for potential auth variable support.
//
CopyGuid (&VariableStore->Signature, &gEfiAuthenticatedVariableGuid);
VariableStore->Size = VariableStoreLength;
VariableStore->Format = VARIABLE_STORE_FORMATTED;
VariableStore->State = VARIABLE_STORE_HEALTHY;
VariableStore->Reserved = 0;
VariableStore->Reserved1 = 0;
VariableStore->Size = VariableStoreLength;
VariableStore->Format = VARIABLE_STORE_FORMATTED;
VariableStore->State = VARIABLE_STORE_HEALTHY;
VariableStore->Reserved = 0;
VariableStore->Reserved1 = 0;
}
*VariableStoreBase = (EFI_PHYSICAL_ADDRESS) (UINTN) VariableStore;
*VariableStoreBase = (EFI_PHYSICAL_ADDRESS)(UINTN)VariableStore;
HwErrStorageSize = PcdGet32 (PcdHwErrStorageSize);
@@ -110,7 +113,7 @@ InitEmuNonVolatileVariableStore (
//
ASSERT (HwErrStorageSize < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)));
mVariableModuleGlobal->CommonVariableSpace = ((UINTN) VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize);
mVariableModuleGlobal->CommonVariableSpace = ((UINTN)VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize);
mVariableModuleGlobal->CommonMaxUserVariableSpace = mVariableModuleGlobal->CommonVariableSpace;
mVariableModuleGlobal->CommonRuntimeVariableSpace = mVariableModuleGlobal->CommonVariableSpace;
@@ -129,7 +132,7 @@ InitEmuNonVolatileVariableStore (
**/
EFI_STATUS
InitRealNonVolatileVariableStore (
OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase
OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase
)
{
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
@@ -166,7 +169,7 @@ InitRealNonVolatileVariableStore (
//
// Copy NV storage data to the memory buffer.
//
CopyMem (NvStorageData, (UINT8 *) (UINTN) NvStorageBase, NvStorageSize);
CopyMem (NvStorageData, (UINT8 *)(UINTN)NvStorageBase, NvStorageSize);
Status = GetFtwProtocol ((VOID **)&FtwProtocol);
//
@@ -178,30 +181,31 @@ InitRealNonVolatileVariableStore (
//
GuidHob = GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid);
if (GuidHob != NULL) {
FtwLastWriteData = (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *) GET_GUID_HOB_DATA (GuidHob);
FtwLastWriteData = (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *)GET_GUID_HOB_DATA (GuidHob);
if (FtwLastWriteData->TargetAddress == NvStorageBase) {
DEBUG ((DEBUG_INFO, "Variable: NV storage is backed up in spare block: 0x%x\n", (UINTN) FtwLastWriteData->SpareAddress));
DEBUG ((DEBUG_INFO, "Variable: NV storage is backed up in spare block: 0x%x\n", (UINTN)FtwLastWriteData->SpareAddress));
//
// Copy the backed up NV storage data to the memory buffer from spare block.
//
CopyMem (NvStorageData, (UINT8 *) (UINTN) (FtwLastWriteData->SpareAddress), NvStorageSize);
CopyMem (NvStorageData, (UINT8 *)(UINTN)(FtwLastWriteData->SpareAddress), NvStorageSize);
} else if ((FtwLastWriteData->TargetAddress > NvStorageBase) &&
(FtwLastWriteData->TargetAddress < (NvStorageBase + NvStorageSize))) {
(FtwLastWriteData->TargetAddress < (NvStorageBase + NvStorageSize)))
{
//
// Flash NV storage from the Offset is backed up in spare block.
//
BackUpOffset = (UINT32) (FtwLastWriteData->TargetAddress - NvStorageBase);
BackUpSize = NvStorageSize - BackUpOffset;
DEBUG ((DEBUG_INFO, "Variable: High partial NV storage from offset: %x is backed up in spare block: 0x%x\n", BackUpOffset, (UINTN) FtwLastWriteData->SpareAddress));
BackUpOffset = (UINT32)(FtwLastWriteData->TargetAddress - NvStorageBase);
BackUpSize = NvStorageSize - BackUpOffset;
DEBUG ((DEBUG_INFO, "Variable: High partial NV storage from offset: %x is backed up in spare block: 0x%x\n", BackUpOffset, (UINTN)FtwLastWriteData->SpareAddress));
//
// Copy the partial backed up NV storage data to the memory buffer from spare block.
//
CopyMem (NvStorageData + BackUpOffset, (UINT8 *) (UINTN) FtwLastWriteData->SpareAddress, BackUpSize);
CopyMem (NvStorageData + BackUpOffset, (UINT8 *)(UINTN)FtwLastWriteData->SpareAddress, BackUpSize);
}
}
}
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) NvStorageData;
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)NvStorageData;
//
// Check if the Firmware Volume is not corrupted
@@ -212,7 +216,7 @@ InitRealNonVolatileVariableStore (
return EFI_VOLUME_CORRUPTED;
}
VariableStore = (VARIABLE_STORE_HEADER *) ((UINTN) FvHeader + FvHeader->HeaderLength);
VariableStore = (VARIABLE_STORE_HEADER *)((UINTN)FvHeader + FvHeader->HeaderLength);
VariableStoreLength = NvStorageSize - FvHeader->HeaderLength;
ASSERT (sizeof (VARIABLE_STORE_HEADER) <= VariableStoreLength);
ASSERT (VariableStore->Size == VariableStoreLength);
@@ -222,16 +226,16 @@ InitRealNonVolatileVariableStore (
//
if (GetVariableStoreStatus (VariableStore) != EfiValid) {
FreePool (NvStorageData);
DEBUG((DEBUG_ERROR, "Variable Store header is corrupted\n"));
DEBUG ((DEBUG_ERROR, "Variable Store header is corrupted\n"));
return EFI_VOLUME_CORRUPTED;
}
mNvFvHeaderCache = FvHeader;
*VariableStoreBase = (EFI_PHYSICAL_ADDRESS) (UINTN) VariableStore;
*VariableStoreBase = (EFI_PHYSICAL_ADDRESS)(UINTN)VariableStore;
HwErrStorageSize = PcdGet32 (PcdHwErrStorageSize);
MaxUserNvVariableSpaceSize = PcdGet32 (PcdMaxUserNvVariableSpaceSize);
HwErrStorageSize = PcdGet32 (PcdHwErrStorageSize);
MaxUserNvVariableSpaceSize = PcdGet32 (PcdMaxUserNvVariableSpaceSize);
BoottimeReservedNvVariableSpaceSize = PcdGet32 (PcdBoottimeReservedNvVariableSpaceSize);
//
@@ -252,7 +256,7 @@ InitRealNonVolatileVariableStore (
//
ASSERT (BoottimeReservedNvVariableSpaceSize < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize));
mVariableModuleGlobal->CommonVariableSpace = ((UINTN) VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize);
mVariableModuleGlobal->CommonVariableSpace = ((UINTN)VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize);
mVariableModuleGlobal->CommonMaxUserVariableSpace = ((MaxUserNvVariableSpaceSize != 0) ? MaxUserNvVariableSpaceSize : mVariableModuleGlobal->CommonVariableSpace);
mVariableModuleGlobal->CommonRuntimeVariableSpace = mVariableModuleGlobal->CommonVariableSpace - BoottimeReservedNvVariableSpaceSize;
@@ -285,17 +289,18 @@ InitNonVolatileVariableStore (
VOID
)
{
VARIABLE_HEADER *Variable;
VARIABLE_HEADER *NextVariable;
EFI_PHYSICAL_ADDRESS VariableStoreBase;
UINTN VariableSize;
EFI_STATUS Status;
VARIABLE_HEADER *Variable;
VARIABLE_HEADER *NextVariable;
EFI_PHYSICAL_ADDRESS VariableStoreBase;
UINTN VariableSize;
EFI_STATUS Status;
if (PcdGetBool (PcdEmuVariableNvModeEnable)) {
Status = InitEmuNonVolatileVariableStore (&VariableStoreBase);
if (EFI_ERROR (Status)) {
return Status;
}
mVariableModuleGlobal->VariableGlobal.EmuNvMode = TRUE;
DEBUG ((DEBUG_INFO, "Variable driver will work at emulated non-volatile variable mode!\n"));
} else {
@@ -303,23 +308,24 @@ InitNonVolatileVariableStore (
if (EFI_ERROR (Status)) {
return Status;
}
mVariableModuleGlobal->VariableGlobal.EmuNvMode = FALSE;
}
mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase;
mNvVariableCache = (VARIABLE_STORE_HEADER *) (UINTN) VariableStoreBase;
mVariableModuleGlobal->VariableGlobal.AuthFormat = (BOOLEAN)(CompareGuid (&mNvVariableCache->Signature, &gEfiAuthenticatedVariableGuid));
mNvVariableCache = (VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase;
mVariableModuleGlobal->VariableGlobal.AuthFormat = (BOOLEAN)(CompareGuid (&mNvVariableCache->Signature, &gEfiAuthenticatedVariableGuid));
mVariableModuleGlobal->MaxVariableSize = PcdGet32 (PcdMaxVariableSize);
mVariableModuleGlobal->MaxVariableSize = PcdGet32 (PcdMaxVariableSize);
mVariableModuleGlobal->MaxAuthVariableSize = ((PcdGet32 (PcdMaxAuthVariableSize) != 0) ? PcdGet32 (PcdMaxAuthVariableSize) : mVariableModuleGlobal->MaxVariableSize);
//
// Parse non-volatile variable data and get last variable offset.
//
Variable = GetStartPointer (mNvVariableCache);
Variable = GetStartPointer (mNvVariableCache);
while (IsValidVariableHeader (Variable, GetEndPointer (mNvVariableCache))) {
NextVariable = GetNextVariablePtr (Variable, mVariableModuleGlobal->VariableGlobal.AuthFormat);
VariableSize = (UINTN) NextVariable - (UINTN) Variable;
VariableSize = (UINTN)NextVariable - (UINTN)Variable;
if ((Variable->Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
mVariableModuleGlobal->HwErrVariableTotalSize += VariableSize;
} else {
@@ -328,7 +334,8 @@ InitNonVolatileVariableStore (
Variable = NextVariable;
}
mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) Variable - (UINTN) mNvVariableCache;
mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN)Variable - (UINTN)mNvVariableCache;
return EFI_SUCCESS;
}

View File

@@ -48,7 +48,7 @@ InitEmuNonVolatileVariableStore (
**/
EFI_STATUS
InitRealNonVolatileVariableStore (
OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase
OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase
);
/**

View File

@@ -22,8 +22,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
BOOLEAN
IsValidVariableHeader (
IN VARIABLE_HEADER *Variable,
IN VARIABLE_HEADER *VariableStoreEnd
IN VARIABLE_HEADER *Variable,
IN VARIABLE_HEADER *VariableStoreEnd
)
{
if ((Variable == NULL) || (Variable >= VariableStoreEnd) || (Variable->StartId != VARIABLE_DATA)) {
@@ -50,25 +50,25 @@ IsValidVariableHeader (
**/
VARIABLE_STORE_STATUS
GetVariableStoreStatus (
IN VARIABLE_STORE_HEADER *VarStoreHeader
IN VARIABLE_STORE_HEADER *VarStoreHeader
)
{
if ((CompareGuid (&VarStoreHeader->Signature, &gEfiAuthenticatedVariableGuid) ||
CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid)) &&
VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&
VarStoreHeader->State == VARIABLE_STORE_HEALTHY
) {
(VarStoreHeader->Format == VARIABLE_STORE_FORMATTED) &&
(VarStoreHeader->State == VARIABLE_STORE_HEALTHY)
)
{
return EfiValid;
} else if (((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff &&
((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff &&
((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff &&
((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff &&
VarStoreHeader->Size == 0xffffffff &&
VarStoreHeader->Format == 0xff &&
VarStoreHeader->State == 0xff
) {
} else if ((((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff) &&
(((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff) &&
(((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff) &&
(((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff) &&
(VarStoreHeader->Size == 0xffffffff) &&
(VarStoreHeader->Format == 0xff) &&
(VarStoreHeader->State == 0xff)
)
{
return EfiRaw;
} else {
return EfiInvalid;
@@ -86,10 +86,10 @@ GetVariableStoreStatus (
**/
UINTN
GetVariableHeaderSize (
IN BOOLEAN AuthFormat
IN BOOLEAN AuthFormat
)
{
UINTN Value;
UINTN Value;
if (AuthFormat) {
Value = sizeof (AUTHENTICATED_VARIABLE_HEADER);
@@ -113,29 +113,33 @@ GetVariableHeaderSize (
**/
UINTN
NameSizeOfVariable (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
)
{
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable;
if (AuthFormat) {
if (AuthVariable->State == (UINT8) (-1) ||
AuthVariable->DataSize == (UINT32) (-1) ||
AuthVariable->NameSize == (UINT32) (-1) ||
AuthVariable->Attributes == (UINT32) (-1)) {
if ((AuthVariable->State == (UINT8)(-1)) ||
(AuthVariable->DataSize == (UINT32)(-1)) ||
(AuthVariable->NameSize == (UINT32)(-1)) ||
(AuthVariable->Attributes == (UINT32)(-1)))
{
return 0;
}
return (UINTN) AuthVariable->NameSize;
return (UINTN)AuthVariable->NameSize;
} else {
if (Variable->State == (UINT8) (-1) ||
Variable->DataSize == (UINT32) (-1) ||
Variable->NameSize == (UINT32) (-1) ||
Variable->Attributes == (UINT32) (-1)) {
if ((Variable->State == (UINT8)(-1)) ||
(Variable->DataSize == (UINT32)(-1)) ||
(Variable->NameSize == (UINT32)(-1)) ||
(Variable->Attributes == (UINT32)(-1)))
{
return 0;
}
return (UINTN) Variable->NameSize;
return (UINTN)Variable->NameSize;
}
}
@@ -150,18 +154,18 @@ NameSizeOfVariable (
**/
VOID
SetNameSizeOfVariable (
IN VARIABLE_HEADER *Variable,
IN UINTN NameSize,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN UINTN NameSize,
IN BOOLEAN AuthFormat
)
{
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable;
if (AuthFormat) {
AuthVariable->NameSize = (UINT32) NameSize;
AuthVariable->NameSize = (UINT32)NameSize;
} else {
Variable->NameSize = (UINT32) NameSize;
Variable->NameSize = (UINT32)NameSize;
}
}
@@ -178,29 +182,33 @@ SetNameSizeOfVariable (
**/
UINTN
DataSizeOfVariable (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
)
{
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable;
if (AuthFormat) {
if (AuthVariable->State == (UINT8) (-1) ||
AuthVariable->DataSize == (UINT32) (-1) ||
AuthVariable->NameSize == (UINT32) (-1) ||
AuthVariable->Attributes == (UINT32) (-1)) {
if ((AuthVariable->State == (UINT8)(-1)) ||
(AuthVariable->DataSize == (UINT32)(-1)) ||
(AuthVariable->NameSize == (UINT32)(-1)) ||
(AuthVariable->Attributes == (UINT32)(-1)))
{
return 0;
}
return (UINTN) AuthVariable->DataSize;
return (UINTN)AuthVariable->DataSize;
} else {
if (Variable->State == (UINT8) (-1) ||
Variable->DataSize == (UINT32) (-1) ||
Variable->NameSize == (UINT32) (-1) ||
Variable->Attributes == (UINT32) (-1)) {
if ((Variable->State == (UINT8)(-1)) ||
(Variable->DataSize == (UINT32)(-1)) ||
(Variable->NameSize == (UINT32)(-1)) ||
(Variable->Attributes == (UINT32)(-1)))
{
return 0;
}
return (UINTN) Variable->DataSize;
return (UINTN)Variable->DataSize;
}
}
@@ -215,18 +223,18 @@ DataSizeOfVariable (
**/
VOID
SetDataSizeOfVariable (
IN VARIABLE_HEADER *Variable,
IN UINTN DataSize,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN UINTN DataSize,
IN BOOLEAN AuthFormat
)
{
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable;
if (AuthFormat) {
AuthVariable->DataSize = (UINT32) DataSize;
AuthVariable->DataSize = (UINT32)DataSize;
} else {
Variable->DataSize = (UINT32) DataSize;
Variable->DataSize = (UINT32)DataSize;
}
}
@@ -243,11 +251,11 @@ SetDataSizeOfVariable (
**/
CHAR16 *
GetVariableNamePtr (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
)
{
return (CHAR16 *) ((UINTN) Variable + GetVariableHeaderSize (AuthFormat));
return (CHAR16 *)((UINTN)Variable + GetVariableHeaderSize (AuthFormat));
}
/**
@@ -262,13 +270,13 @@ GetVariableNamePtr (
**/
EFI_GUID *
GetVendorGuidPtr (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
)
{
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *)Variable;
if (AuthFormat) {
return &AuthVariable->VendorGuid;
} else {
@@ -289,20 +297,20 @@ GetVendorGuidPtr (
**/
UINT8 *
GetVariableDataPtr (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
)
{
UINTN Value;
UINTN Value;
//
// Be careful about pad size for alignment.
//
Value = (UINTN) GetVariableNamePtr (Variable, AuthFormat);
Value = (UINTN)GetVariableNamePtr (Variable, AuthFormat);
Value += NameSizeOfVariable (Variable, AuthFormat);
Value += GET_PAD_SIZE (NameSizeOfVariable (Variable, AuthFormat));
return (UINT8 *) Value;
return (UINT8 *)Value;
}
/**
@@ -317,16 +325,16 @@ GetVariableDataPtr (
**/
UINTN
GetVariableDataOffset (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
)
{
UINTN Value;
UINTN Value;
//
// Be careful about pad size for alignment
//
Value = GetVariableHeaderSize (AuthFormat);
Value = GetVariableHeaderSize (AuthFormat);
Value += NameSizeOfVariable (Variable, AuthFormat);
Value += GET_PAD_SIZE (NameSizeOfVariable (Variable, AuthFormat));
@@ -346,20 +354,20 @@ GetVariableDataOffset (
**/
VARIABLE_HEADER *
GetNextVariablePtr (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
)
{
UINTN Value;
UINTN Value;
Value = (UINTN) GetVariableDataPtr (Variable, AuthFormat);
Value = (UINTN)GetVariableDataPtr (Variable, AuthFormat);
Value += DataSizeOfVariable (Variable, AuthFormat);
Value += GET_PAD_SIZE (DataSizeOfVariable (Variable, AuthFormat));
//
// Be careful about pad size for alignment.
//
return (VARIABLE_HEADER *) HEADER_ALIGN (Value);
return (VARIABLE_HEADER *)HEADER_ALIGN (Value);
}
/**
@@ -373,13 +381,13 @@ GetNextVariablePtr (
**/
VARIABLE_HEADER *
GetStartPointer (
IN VARIABLE_STORE_HEADER *VarStoreHeader
IN VARIABLE_STORE_HEADER *VarStoreHeader
)
{
//
// The start of variable store.
//
return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1);
return (VARIABLE_HEADER *)HEADER_ALIGN (VarStoreHeader + 1);
}
/**
@@ -396,13 +404,13 @@ GetStartPointer (
**/
VARIABLE_HEADER *
GetEndPointer (
IN VARIABLE_STORE_HEADER *VarStoreHeader
IN VARIABLE_STORE_HEADER *VarStoreHeader
)
{
//
// The end of variable store
//
return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size);
return (VARIABLE_HEADER *)HEADER_ALIGN ((UINTN)VarStoreHeader + VarStoreHeader->Size);
}
/**
@@ -418,23 +426,23 @@ GetEndPointer (
**/
BOOLEAN
VariableCompareTimeStampInternal (
IN EFI_TIME *FirstTime,
IN EFI_TIME *SecondTime
IN EFI_TIME *FirstTime,
IN EFI_TIME *SecondTime
)
{
if (FirstTime->Year != SecondTime->Year) {
return (BOOLEAN) (FirstTime->Year < SecondTime->Year);
return (BOOLEAN)(FirstTime->Year < SecondTime->Year);
} else if (FirstTime->Month != SecondTime->Month) {
return (BOOLEAN) (FirstTime->Month < SecondTime->Month);
return (BOOLEAN)(FirstTime->Month < SecondTime->Month);
} else if (FirstTime->Day != SecondTime->Day) {
return (BOOLEAN) (FirstTime->Day < SecondTime->Day);
return (BOOLEAN)(FirstTime->Day < SecondTime->Day);
} else if (FirstTime->Hour != SecondTime->Hour) {
return (BOOLEAN) (FirstTime->Hour < SecondTime->Hour);
return (BOOLEAN)(FirstTime->Hour < SecondTime->Hour);
} else if (FirstTime->Minute != SecondTime->Minute) {
return (BOOLEAN) (FirstTime->Minute < SecondTime->Minute);
return (BOOLEAN)(FirstTime->Minute < SecondTime->Minute);
}
return (BOOLEAN) (FirstTime->Second <= SecondTime->Second);
return (BOOLEAN)(FirstTime->Second <= SecondTime->Second);
}
/**
@@ -460,39 +468,41 @@ FindVariableEx (
IN BOOLEAN AuthFormat
)
{
VARIABLE_HEADER *InDeletedVariable;
VOID *Point;
VARIABLE_HEADER *InDeletedVariable;
VOID *Point;
PtrTrack->InDeletedTransitionPtr = NULL;
//
// Find the variable by walk through HOB, volatile and non-volatile variable store.
//
InDeletedVariable = NULL;
InDeletedVariable = NULL;
for ( PtrTrack->CurrPtr = PtrTrack->StartPtr
; IsValidVariableHeader (PtrTrack->CurrPtr, PtrTrack->EndPtr)
; PtrTrack->CurrPtr = GetNextVariablePtr (PtrTrack->CurrPtr, AuthFormat)
) {
if (PtrTrack->CurrPtr->State == VAR_ADDED ||
PtrTrack->CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)
) {
; IsValidVariableHeader (PtrTrack->CurrPtr, PtrTrack->EndPtr)
; PtrTrack->CurrPtr = GetNextVariablePtr (PtrTrack->CurrPtr, AuthFormat)
)
{
if ((PtrTrack->CurrPtr->State == VAR_ADDED) ||
(PtrTrack->CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED))
)
{
if (IgnoreRtCheck || !AtRuntime () || ((PtrTrack->CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {
if (VariableName[0] == 0) {
if (PtrTrack->CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
InDeletedVariable = PtrTrack->CurrPtr;
InDeletedVariable = PtrTrack->CurrPtr;
} else {
PtrTrack->InDeletedTransitionPtr = InDeletedVariable;
return EFI_SUCCESS;
}
} else {
if (CompareGuid (VendorGuid, GetVendorGuidPtr (PtrTrack->CurrPtr, AuthFormat))) {
Point = (VOID *) GetVariableNamePtr (PtrTrack->CurrPtr, AuthFormat);
Point = (VOID *)GetVariableNamePtr (PtrTrack->CurrPtr, AuthFormat);
ASSERT (NameSizeOfVariable (PtrTrack->CurrPtr, AuthFormat) != 0);
if (CompareMem (VariableName, Point, NameSizeOfVariable (PtrTrack->CurrPtr, AuthFormat)) == 0) {
if (PtrTrack->CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
InDeletedVariable = PtrTrack->CurrPtr;
InDeletedVariable = PtrTrack->CurrPtr;
} else {
PtrTrack->InDeletedTransitionPtr = InDeletedVariable;
return EFI_SUCCESS;
@@ -532,11 +542,11 @@ FindVariableEx (
EFI_STATUS
EFIAPI
VariableServiceGetNextVariableInternal (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN VARIABLE_STORE_HEADER **VariableStoreList,
OUT VARIABLE_HEADER **VariablePtr,
IN BOOLEAN AuthFormat
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN VARIABLE_STORE_HEADER **VariableStoreList,
OUT VARIABLE_HEADER **VariablePtr,
IN BOOLEAN AuthFormat
)
{
EFI_STATUS Status;
@@ -554,14 +564,14 @@ VariableServiceGetNextVariableInternal (
ZeroMem (&Variable, sizeof (Variable));
// Check if the variable exists in the given variable store list
for (StoreType = (VARIABLE_STORE_TYPE) 0; StoreType < VariableStoreTypeMax; StoreType++) {
for (StoreType = (VARIABLE_STORE_TYPE)0; StoreType < VariableStoreTypeMax; StoreType++) {
if (VariableStoreList[StoreType] == NULL) {
continue;
}
Variable.StartPtr = GetStartPointer (VariableStoreList[StoreType]);
Variable.EndPtr = GetEndPointer (VariableStoreList[StoreType]);
Variable.Volatile = (BOOLEAN) (StoreType == VariableStoreTypeVolatile);
Variable.EndPtr = GetEndPointer (VariableStoreList[StoreType]);
Variable.Volatile = (BOOLEAN)(StoreType == VariableStoreTypeVolatile);
Status = FindVariableEx (VariableName, VendorGuid, FALSE, &Variable, AuthFormat);
if (!EFI_ERROR (Status)) {
@@ -569,7 +579,7 @@ VariableServiceGetNextVariableInternal (
}
}
if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {
if ((Variable.CurrPtr == NULL) || EFI_ERROR (Status)) {
//
// For VariableName is an empty string, FindVariableEx() will try to find and return
// the first qualified variable, and if FindVariableEx() returns error (EFI_NOT_FOUND)
@@ -583,6 +593,7 @@ VariableServiceGetNextVariableInternal (
//
Status = EFI_INVALID_PARAMETER;
}
goto Done;
}
@@ -601,11 +612,12 @@ VariableServiceGetNextVariableInternal (
//
// Find current storage index
//
for (StoreType = (VARIABLE_STORE_TYPE) 0; StoreType < VariableStoreTypeMax; StoreType++) {
for (StoreType = (VARIABLE_STORE_TYPE)0; StoreType < VariableStoreTypeMax; StoreType++) {
if ((VariableStoreList[StoreType] != NULL) && (Variable.StartPtr == GetStartPointer (VariableStoreList[StoreType]))) {
break;
}
}
ASSERT (StoreType < VariableStoreTypeMax);
//
// Switch to next storage
@@ -615,6 +627,7 @@ VariableServiceGetNextVariableInternal (
break;
}
}
//
// Capture the case that
// 1. current storage is the last one, or
@@ -624,15 +637,16 @@ VariableServiceGetNextVariableInternal (
Status = EFI_NOT_FOUND;
goto Done;
}
Variable.StartPtr = GetStartPointer (VariableStoreList[StoreType]);
Variable.EndPtr = GetEndPointer (VariableStoreList[StoreType]);
Variable.EndPtr = GetEndPointer (VariableStoreList[StoreType]);
Variable.CurrPtr = Variable.StartPtr;
}
//
// Variable is found
//
if (Variable.CurrPtr->State == VAR_ADDED || Variable.CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
if ((Variable.CurrPtr->State == VAR_ADDED) || (Variable.CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED))) {
if (!AtRuntime () || ((Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {
if (Variable.CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
//
@@ -641,15 +655,15 @@ VariableServiceGetNextVariableInternal (
// don't return it.
//
VariablePtrTrack.StartPtr = Variable.StartPtr;
VariablePtrTrack.EndPtr = Variable.EndPtr;
Status = FindVariableEx (
GetVariableNamePtr (Variable.CurrPtr, AuthFormat),
GetVendorGuidPtr (Variable.CurrPtr, AuthFormat),
FALSE,
&VariablePtrTrack,
AuthFormat
);
if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State == VAR_ADDED) {
VariablePtrTrack.EndPtr = Variable.EndPtr;
Status = FindVariableEx (
GetVariableNamePtr (Variable.CurrPtr, AuthFormat),
GetVendorGuidPtr (Variable.CurrPtr, AuthFormat),
FALSE,
&VariablePtrTrack,
AuthFormat
);
if (!EFI_ERROR (Status) && (VariablePtrTrack.CurrPtr->State == VAR_ADDED)) {
Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr, AuthFormat);
continue;
}
@@ -660,16 +674,17 @@ VariableServiceGetNextVariableInternal (
//
if ((VariableStoreList[VariableStoreTypeHob] != NULL) && (VariableStoreList[VariableStoreTypeNv] != NULL) &&
(Variable.StartPtr == GetStartPointer (VariableStoreList[VariableStoreTypeNv]))
) {
)
{
VariableInHob.StartPtr = GetStartPointer (VariableStoreList[VariableStoreTypeHob]);
VariableInHob.EndPtr = GetEndPointer (VariableStoreList[VariableStoreTypeHob]);
Status = FindVariableEx (
GetVariableNamePtr (Variable.CurrPtr, AuthFormat),
GetVendorGuidPtr (Variable.CurrPtr, AuthFormat),
FALSE,
&VariableInHob,
AuthFormat
);
VariableInHob.EndPtr = GetEndPointer (VariableStoreList[VariableStoreTypeHob]);
Status = FindVariableEx (
GetVariableNamePtr (Variable.CurrPtr, AuthFormat),
GetVendorGuidPtr (Variable.CurrPtr, AuthFormat),
FALSE,
&VariableInHob,
AuthFormat
);
if (!EFI_ERROR (Status)) {
Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr, AuthFormat);
continue;
@@ -677,7 +692,7 @@ VariableServiceGetNextVariableInternal (
}
*VariablePtr = Variable.CurrPtr;
Status = EFI_SUCCESS;
Status = EFI_SUCCESS;
goto Done;
}
}
@@ -722,12 +737,13 @@ UpdateVariableInfo (
IN OUT VARIABLE_INFO_ENTRY **VariableInfo
)
{
VARIABLE_INFO_ENTRY *Entry;
VARIABLE_INFO_ENTRY *Entry;
if (FeaturePcdGet (PcdVariableCollectStatistics)) {
if (VariableName == NULL || VendorGuid == NULL || VariableInfo == NULL) {
if ((VariableName == NULL) || (VendorGuid == NULL) || (VariableInfo == NULL)) {
return;
}
if (AtRuntime ()) {
// Don't collect statistics at runtime.
return;
@@ -744,23 +760,25 @@ UpdateVariableInfo (
CopyGuid (&(*VariableInfo)->VendorGuid, VendorGuid);
(*VariableInfo)->Name = AllocateZeroPool (StrSize (VariableName));
ASSERT ((*VariableInfo)->Name != NULL);
StrCpyS ((*VariableInfo)->Name, StrSize(VariableName)/sizeof(CHAR16), VariableName);
StrCpyS ((*VariableInfo)->Name, StrSize (VariableName)/sizeof (CHAR16), VariableName);
(*VariableInfo)->Volatile = Volatile;
}
for (Entry = (*VariableInfo); Entry != NULL; Entry = Entry->Next) {
if (CompareGuid (VendorGuid, &Entry->VendorGuid)) {
if (StrCmp (VariableName, Entry->Name) == 0) {
if (Read) {
Entry->ReadCount++;
}
if (Write) {
Entry->WriteCount++;
}
if (Delete) {
Entry->DeleteCount++;
}
if (Cache) {
Entry->CacheCount++;
}
@@ -780,7 +798,7 @@ UpdateVariableInfo (
CopyGuid (&Entry->Next->VendorGuid, VendorGuid);
Entry->Next->Name = AllocateZeroPool (StrSize (VariableName));
ASSERT (Entry->Next->Name != NULL);
StrCpyS (Entry->Next->Name, StrSize(VariableName)/sizeof(CHAR16), VariableName);
StrCpyS (Entry->Next->Name, StrSize (VariableName)/sizeof (CHAR16), VariableName);
Entry->Next->Volatile = Volatile;
}
}

View File

@@ -26,8 +26,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
BOOLEAN
IsValidVariableHeader (
IN VARIABLE_HEADER *Variable,
IN VARIABLE_HEADER *VariableStoreEnd
IN VARIABLE_HEADER *Variable,
IN VARIABLE_HEADER *VariableStoreEnd
);
/**
@@ -43,7 +43,7 @@ IsValidVariableHeader (
**/
VARIABLE_STORE_STATUS
GetVariableStoreStatus (
IN VARIABLE_STORE_HEADER *VarStoreHeader
IN VARIABLE_STORE_HEADER *VarStoreHeader
);
/**
@@ -57,7 +57,7 @@ GetVariableStoreStatus (
**/
UINTN
GetVariableHeaderSize (
IN BOOLEAN AuthFormat
IN BOOLEAN AuthFormat
);
/**
@@ -73,8 +73,8 @@ GetVariableHeaderSize (
**/
UINTN
NameSizeOfVariable (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
);
/**
@@ -88,9 +88,9 @@ NameSizeOfVariable (
**/
VOID
SetNameSizeOfVariable (
IN VARIABLE_HEADER *Variable,
IN UINTN NameSize,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN UINTN NameSize,
IN BOOLEAN AuthFormat
);
/**
@@ -106,8 +106,8 @@ SetNameSizeOfVariable (
**/
UINTN
DataSizeOfVariable (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
);
/**
@@ -121,9 +121,9 @@ DataSizeOfVariable (
**/
VOID
SetDataSizeOfVariable (
IN VARIABLE_HEADER *Variable,
IN UINTN DataSize,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN UINTN DataSize,
IN BOOLEAN AuthFormat
);
/**
@@ -139,8 +139,8 @@ SetDataSizeOfVariable (
**/
CHAR16 *
GetVariableNamePtr (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
);
/**
@@ -155,8 +155,8 @@ GetVariableNamePtr (
**/
EFI_GUID *
GetVendorGuidPtr (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
);
/**
@@ -172,8 +172,8 @@ GetVendorGuidPtr (
**/
UINT8 *
GetVariableDataPtr (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
);
/**
@@ -188,8 +188,8 @@ GetVariableDataPtr (
**/
UINTN
GetVariableDataOffset (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
);
/**
@@ -205,8 +205,8 @@ GetVariableDataOffset (
**/
VARIABLE_HEADER *
GetNextVariablePtr (
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
IN VARIABLE_HEADER *Variable,
IN BOOLEAN AuthFormat
);
/**
@@ -220,7 +220,7 @@ GetNextVariablePtr (
**/
VARIABLE_HEADER *
GetStartPointer (
IN VARIABLE_STORE_HEADER *VarStoreHeader
IN VARIABLE_STORE_HEADER *VarStoreHeader
);
/**
@@ -237,7 +237,7 @@ GetStartPointer (
**/
VARIABLE_HEADER *
GetEndPointer (
IN VARIABLE_STORE_HEADER *VarStoreHeader
IN VARIABLE_STORE_HEADER *VarStoreHeader
);
/**
@@ -253,8 +253,8 @@ GetEndPointer (
**/
BOOLEAN
VariableCompareTimeStampInternal (
IN EFI_TIME *FirstTime,
IN EFI_TIME *SecondTime
IN EFI_TIME *FirstTime,
IN EFI_TIME *SecondTime
);
/**
@@ -304,11 +304,11 @@ FindVariableEx (
EFI_STATUS
EFIAPI
VariableServiceGetNextVariableInternal (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN VARIABLE_STORE_HEADER **VariableStoreList,
OUT VARIABLE_HEADER **VariablePtr,
IN BOOLEAN AuthFormat
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN VARIABLE_STORE_HEADER **VariableStoreList,
OUT VARIABLE_HEADER **VariablePtr,
IN BOOLEAN AuthFormat
);
/**

View File

@@ -40,19 +40,20 @@ EFI_LOCK mMmCommunicationLock;
STATIC
EFI_STATUS
InternalMmCommunicate (
IN OUT VOID *CommBuffer,
IN OUT UINTN *CommSize
IN OUT VOID *CommBuffer,
IN OUT UINTN *CommSize
)
{
EFI_STATUS Status;
if (CommBuffer == NULL || CommSize == NULL) {
EFI_STATUS Status;
if ((CommBuffer == NULL) || (CommSize == NULL)) {
return EFI_INVALID_PARAMETER;
}
Status = mMmCommunication->Communicate (mMmCommunication, CommBuffer, CommBuffer, CommSize);
return Status;
}
/**
This API function disables the variable policy enforcement. If it's
already been called once, will return EFI_ALREADY_STARTED.
@@ -84,24 +85,23 @@ ProtocolDisableVariablePolicy (
AcquireLockOnlyAtBootTime (&mMmCommunicationLock);
// Set up the MM communication.
BufferSize = mMmCommunicationBufferSize;
CommHeader = mMmCommunicationBuffer;
PolicyHeader = (VAR_CHECK_POLICY_COMM_HEADER*)&CommHeader->Data;
CopyGuid( &CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid );
BufferSize = mMmCommunicationBufferSize;
CommHeader = mMmCommunicationBuffer;
PolicyHeader = (VAR_CHECK_POLICY_COMM_HEADER *)&CommHeader->Data;
CopyGuid (&CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid);
CommHeader->MessageLength = BufferSize;
PolicyHeader->Signature = VAR_CHECK_POLICY_COMM_SIG;
PolicyHeader->Revision = VAR_CHECK_POLICY_COMM_REVISION;
PolicyHeader->Command = VAR_CHECK_POLICY_COMMAND_DISABLE;
Status = InternalMmCommunicate (CommHeader, &BufferSize);
DEBUG(( DEBUG_VERBOSE, "%a - MmCommunication returned %r.\n", __FUNCTION__, Status ));
DEBUG ((DEBUG_VERBOSE, "%a - MmCommunication returned %r.\n", __FUNCTION__, Status));
ReleaseLockOnlyAtBootTime (&mMmCommunicationLock);
return (EFI_ERROR( Status )) ? Status : PolicyHeader->Result;
return (EFI_ERROR (Status)) ? Status : PolicyHeader->Result;
}
/**
This API function returns whether or not the policy engine is
currently being enforced.
@@ -117,14 +117,14 @@ STATIC
EFI_STATUS
EFIAPI
ProtocolIsVariablePolicyEnabled (
OUT BOOLEAN *State
OUT BOOLEAN *State
)
{
EFI_STATUS Status;
EFI_MM_COMMUNICATE_HEADER *CommHeader;
VAR_CHECK_POLICY_COMM_HEADER *PolicyHeader;
VAR_CHECK_POLICY_COMM_IS_ENABLED_PARAMS *CommandParams;
UINTN BufferSize;
EFI_STATUS Status;
EFI_MM_COMMUNICATE_HEADER *CommHeader;
VAR_CHECK_POLICY_COMM_HEADER *PolicyHeader;
VAR_CHECK_POLICY_COMM_IS_ENABLED_PARAMS *CommandParams;
UINTN BufferSize;
if (State == NULL) {
return EFI_INVALID_PARAMETER;
@@ -135,18 +135,18 @@ ProtocolIsVariablePolicyEnabled (
// Set up the MM communication.
BufferSize = mMmCommunicationBufferSize;
CommHeader = mMmCommunicationBuffer;
PolicyHeader = (VAR_CHECK_POLICY_COMM_HEADER*)&CommHeader->Data;
CommandParams = (VAR_CHECK_POLICY_COMM_IS_ENABLED_PARAMS*)(PolicyHeader + 1);
CopyGuid( &CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid );
PolicyHeader = (VAR_CHECK_POLICY_COMM_HEADER *)&CommHeader->Data;
CommandParams = (VAR_CHECK_POLICY_COMM_IS_ENABLED_PARAMS *)(PolicyHeader + 1);
CopyGuid (&CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid);
CommHeader->MessageLength = BufferSize;
PolicyHeader->Signature = VAR_CHECK_POLICY_COMM_SIG;
PolicyHeader->Revision = VAR_CHECK_POLICY_COMM_REVISION;
PolicyHeader->Command = VAR_CHECK_POLICY_COMMAND_IS_ENABLED;
Status = InternalMmCommunicate (CommHeader, &BufferSize);
DEBUG(( DEBUG_VERBOSE, "%a - MmCommunication returned %r.\n", __FUNCTION__, Status ));
DEBUG ((DEBUG_VERBOSE, "%a - MmCommunication returned %r.\n", __FUNCTION__, Status));
if (!EFI_ERROR( Status )) {
if (!EFI_ERROR (Status)) {
Status = PolicyHeader->Result;
*State = CommandParams->State;
}
@@ -156,7 +156,6 @@ ProtocolIsVariablePolicyEnabled (
return Status;
}
/**
This API function validates and registers a new policy with
the policy enforcement engine.
@@ -176,15 +175,15 @@ STATIC
EFI_STATUS
EFIAPI
ProtocolRegisterVariablePolicy (
IN CONST VARIABLE_POLICY_ENTRY *NewPolicy
IN CONST VARIABLE_POLICY_ENTRY *NewPolicy
)
{
EFI_STATUS Status;
EFI_MM_COMMUNICATE_HEADER *CommHeader;
VAR_CHECK_POLICY_COMM_HEADER *PolicyHeader;
VOID *PolicyBuffer;
UINTN BufferSize;
UINTN RequiredSize;
EFI_STATUS Status;
EFI_MM_COMMUNICATE_HEADER *CommHeader;
VAR_CHECK_POLICY_COMM_HEADER *PolicyHeader;
VOID *PolicyBuffer;
UINTN BufferSize;
UINTN RequiredSize;
if (NewPolicy == NULL) {
return EFI_INVALID_PARAMETER;
@@ -192,39 +191,44 @@ ProtocolRegisterVariablePolicy (
// First, make sure that the required size does not exceed the capabilities
// of the MmCommunication buffer.
RequiredSize = OFFSET_OF(EFI_MM_COMMUNICATE_HEADER, Data) + sizeof(VAR_CHECK_POLICY_COMM_HEADER);
Status = SafeUintnAdd( RequiredSize, NewPolicy->Size, &RequiredSize );
if (EFI_ERROR( Status ) || RequiredSize > mMmCommunicationBufferSize) {
DEBUG(( DEBUG_ERROR, "%a - Policy too large for buffer! %r, %d > %d \n", __FUNCTION__,
Status, RequiredSize, mMmCommunicationBufferSize ));
RequiredSize = OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data) + sizeof (VAR_CHECK_POLICY_COMM_HEADER);
Status = SafeUintnAdd (RequiredSize, NewPolicy->Size, &RequiredSize);
if (EFI_ERROR (Status) || (RequiredSize > mMmCommunicationBufferSize)) {
DEBUG ((
DEBUG_ERROR,
"%a - Policy too large for buffer! %r, %d > %d \n",
__FUNCTION__,
Status,
RequiredSize,
mMmCommunicationBufferSize
));
return EFI_OUT_OF_RESOURCES;
}
AcquireLockOnlyAtBootTime (&mMmCommunicationLock);
// Set up the MM communication.
BufferSize = mMmCommunicationBufferSize;
CommHeader = mMmCommunicationBuffer;
PolicyHeader = (VAR_CHECK_POLICY_COMM_HEADER*)&CommHeader->Data;
PolicyBuffer = (VOID*)(PolicyHeader + 1);
CopyGuid( &CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid );
BufferSize = mMmCommunicationBufferSize;
CommHeader = mMmCommunicationBuffer;
PolicyHeader = (VAR_CHECK_POLICY_COMM_HEADER *)&CommHeader->Data;
PolicyBuffer = (VOID *)(PolicyHeader + 1);
CopyGuid (&CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid);
CommHeader->MessageLength = BufferSize;
PolicyHeader->Signature = VAR_CHECK_POLICY_COMM_SIG;
PolicyHeader->Revision = VAR_CHECK_POLICY_COMM_REVISION;
PolicyHeader->Command = VAR_CHECK_POLICY_COMMAND_REGISTER;
// Copy the policy into place. This copy is safe because we've already tested above.
CopyMem( PolicyBuffer, NewPolicy, NewPolicy->Size );
CopyMem (PolicyBuffer, NewPolicy, NewPolicy->Size);
Status = InternalMmCommunicate (CommHeader, &BufferSize);
DEBUG(( DEBUG_VERBOSE, "%a - MmCommunication returned %r.\n", __FUNCTION__, Status ));
DEBUG ((DEBUG_VERBOSE, "%a - MmCommunication returned %r.\n", __FUNCTION__, Status));
ReleaseLockOnlyAtBootTime (&mMmCommunicationLock);
return (EFI_ERROR( Status )) ? Status : PolicyHeader->Result;
return (EFI_ERROR (Status)) ? Status : PolicyHeader->Result;
}
/**
This helper function takes care of the overhead of formatting, sending, and interpreting
the results for a single DumpVariablePolicy request.
@@ -243,29 +247,29 @@ ProtocolRegisterVariablePolicy (
STATIC
EFI_STATUS
DumpVariablePolicyHelper (
IN UINT32 PageRequested,
OUT UINT32 *TotalSize,
OUT UINT32 *PageSize,
OUT BOOLEAN *HasMore,
OUT UINT8 **Buffer
IN UINT32 PageRequested,
OUT UINT32 *TotalSize,
OUT UINT32 *PageSize,
OUT BOOLEAN *HasMore,
OUT UINT8 **Buffer
)
{
EFI_STATUS Status;
EFI_MM_COMMUNICATE_HEADER *CommHeader;
VAR_CHECK_POLICY_COMM_HEADER *PolicyHeader;
VAR_CHECK_POLICY_COMM_DUMP_PARAMS *CommandParams;
UINTN BufferSize;
EFI_STATUS Status;
EFI_MM_COMMUNICATE_HEADER *CommHeader;
VAR_CHECK_POLICY_COMM_HEADER *PolicyHeader;
VAR_CHECK_POLICY_COMM_DUMP_PARAMS *CommandParams;
UINTN BufferSize;
if (TotalSize == NULL || PageSize == NULL || HasMore == NULL || Buffer == NULL) {
if ((TotalSize == NULL) || (PageSize == NULL) || (HasMore == NULL) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER;
}
// Set up the MM communication.
BufferSize = mMmCommunicationBufferSize;
CommHeader = mMmCommunicationBuffer;
PolicyHeader = (VAR_CHECK_POLICY_COMM_HEADER*)&CommHeader->Data;
CommandParams = (VAR_CHECK_POLICY_COMM_DUMP_PARAMS*)(PolicyHeader + 1);
CopyGuid( &CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid );
PolicyHeader = (VAR_CHECK_POLICY_COMM_HEADER *)&CommHeader->Data;
CommandParams = (VAR_CHECK_POLICY_COMM_DUMP_PARAMS *)(PolicyHeader + 1);
CopyGuid (&CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid);
CommHeader->MessageLength = BufferSize;
PolicyHeader->Signature = VAR_CHECK_POLICY_COMM_SIG;
PolicyHeader->Revision = VAR_CHECK_POLICY_COMM_REVISION;
@@ -274,20 +278,19 @@ DumpVariablePolicyHelper (
CommandParams->PageRequested = PageRequested;
Status = InternalMmCommunicate (CommHeader, &BufferSize);
DEBUG(( DEBUG_VERBOSE, "%a - MmCommunication returned %r.\n", __FUNCTION__, Status ));
DEBUG ((DEBUG_VERBOSE, "%a - MmCommunication returned %r.\n", __FUNCTION__, Status));
if (!EFI_ERROR( Status )) {
Status = PolicyHeader->Result;
if (!EFI_ERROR (Status)) {
Status = PolicyHeader->Result;
*TotalSize = CommandParams->TotalSize;
*PageSize = CommandParams->PageSize;
*HasMore = CommandParams->HasMore;
*Buffer = (UINT8*)(CommandParams + 1);
*PageSize = CommandParams->PageSize;
*HasMore = CommandParams->HasMore;
*Buffer = (UINT8 *)(CommandParams + 1);
}
return Status;
}
/**
This API function will dump the entire contents of the variable policy table.
@@ -307,19 +310,19 @@ STATIC
EFI_STATUS
EFIAPI
ProtocolDumpVariablePolicy (
OUT UINT8 *Policy OPTIONAL,
IN OUT UINT32 *Size
OUT UINT8 *Policy OPTIONAL,
IN OUT UINT32 *Size
)
{
EFI_STATUS Status;
UINT8 *Source;
UINT8 *Destination;
UINT32 PolicySize;
UINT32 PageSize;
BOOLEAN HasMore;
UINT32 PageIndex;
EFI_STATUS Status;
UINT8 *Source;
UINT8 *Destination;
UINT32 PolicySize;
UINT32 PageSize;
BOOLEAN HasMore;
UINT32 PageIndex;
if (Size == NULL || (*Size > 0 && Policy == NULL)) {
if ((Size == NULL) || ((*Size > 0) && (Policy == NULL))) {
return EFI_INVALID_PARAMETER;
}
@@ -330,16 +333,16 @@ ProtocolDumpVariablePolicy (
// First, we must check the zero page to determine the buffer size and
// reset the internal state.
PolicySize = 0;
PageSize = 0;
HasMore = FALSE;
Status = DumpVariablePolicyHelper (0, &PolicySize, &PageSize, &HasMore, &Source);
PageSize = 0;
HasMore = FALSE;
Status = DumpVariablePolicyHelper (0, &PolicySize, &PageSize, &HasMore, &Source);
if (EFI_ERROR (Status)) {
break;
}
// If we're good, we can at least check the required size now.
if (*Size < PolicySize) {
*Size = PolicySize;
*Size = PolicySize;
Status = EFI_BUFFER_TOO_SMALL;
break;
}
@@ -367,7 +370,6 @@ ProtocolDumpVariablePolicy (
return Status;
}
/**
This API function locks the interface so that no more policy updates
can be performed or changes made to the enforcement until the next boot.
@@ -391,24 +393,23 @@ ProtocolLockVariablePolicy (
AcquireLockOnlyAtBootTime (&mMmCommunicationLock);
// Set up the MM communication.
BufferSize = mMmCommunicationBufferSize;
CommHeader = mMmCommunicationBuffer;
PolicyHeader = (VAR_CHECK_POLICY_COMM_HEADER*)&CommHeader->Data;
CopyGuid( &CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid );
BufferSize = mMmCommunicationBufferSize;
CommHeader = mMmCommunicationBuffer;
PolicyHeader = (VAR_CHECK_POLICY_COMM_HEADER *)&CommHeader->Data;
CopyGuid (&CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid);
CommHeader->MessageLength = BufferSize;
PolicyHeader->Signature = VAR_CHECK_POLICY_COMM_SIG;
PolicyHeader->Revision = VAR_CHECK_POLICY_COMM_REVISION;
PolicyHeader->Command = VAR_CHECK_POLICY_COMMAND_LOCK;
Status = InternalMmCommunicate (CommHeader, &BufferSize);
DEBUG(( DEBUG_VERBOSE, "%a - MmCommunication returned %r.\n", __FUNCTION__, Status ));
DEBUG ((DEBUG_VERBOSE, "%a - MmCommunication returned %r.\n", __FUNCTION__, Status));
ReleaseLockOnlyAtBootTime (&mMmCommunicationLock);
return (EFI_ERROR( Status )) ? Status : PolicyHeader->Result;
return (EFI_ERROR (Status)) ? Status : PolicyHeader->Result;
}
/**
This helper function locates the shared comm buffer and assigns it to input pointers.
@@ -424,23 +425,23 @@ ProtocolLockVariablePolicy (
STATIC
EFI_STATUS
InitMmCommonCommBuffer (
IN OUT UINTN *BufferSize,
OUT VOID **LocatedBuffer
IN OUT UINTN *BufferSize,
OUT VOID **LocatedBuffer
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = EFI_SUCCESS;
// Make sure that we're working with good pointers.
if (BufferSize == NULL || LocatedBuffer == NULL) {
if ((BufferSize == NULL) || (LocatedBuffer == NULL)) {
return EFI_INVALID_PARAMETER;
}
// Allocate the runtime memory for the comm buffer.
*LocatedBuffer = AllocateRuntimePool (*BufferSize);
if (*LocatedBuffer == NULL) {
Status = EFI_OUT_OF_RESOURCES;
Status = EFI_OUT_OF_RESOURCES;
*BufferSize = 0;
}
@@ -449,7 +450,6 @@ InitMmCommonCommBuffer (
return Status;
}
/**
Convert internal pointer addresses to virtual addresses.
@@ -461,15 +461,14 @@ STATIC
VOID
EFIAPI
VariablePolicyVirtualAddressCallback (
IN EFI_EVENT Event,
IN VOID *Context
IN EFI_EVENT Event,
IN VOID *Context
)
{
EfiConvertPointer (0, (VOID **)&mMmCommunication);
EfiConvertPointer (0, (VOID **)&mMmCommunicationBuffer);
}
/**
The driver's entry point.
@@ -483,34 +482,34 @@ VariablePolicyVirtualAddressCallback (
EFI_STATUS
EFIAPI
VariablePolicySmmDxeMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
BOOLEAN ProtocolInstalled;
BOOLEAN VirtualAddressChangeRegistered;
EFI_EVENT VirtualAddressChangeEvent;
EFI_STATUS Status;
BOOLEAN ProtocolInstalled;
BOOLEAN VirtualAddressChangeRegistered;
EFI_EVENT VirtualAddressChangeEvent;
Status = EFI_SUCCESS;
ProtocolInstalled = FALSE;
Status = EFI_SUCCESS;
ProtocolInstalled = FALSE;
VirtualAddressChangeRegistered = FALSE;
// Update the minimum buffer size.
mMmCommunicationBufferSize = VAR_CHECK_POLICY_MM_COMM_BUFFER_SIZE;
// Locate the shared comm buffer to use for sending MM commands.
Status = InitMmCommonCommBuffer( &mMmCommunicationBufferSize, &mMmCommunicationBuffer );
if (EFI_ERROR( Status )) {
DEBUG((DEBUG_ERROR, "%a - Failed to locate a viable MM comm buffer! %r\n", __FUNCTION__, Status));
ASSERT_EFI_ERROR( Status );
Status = InitMmCommonCommBuffer (&mMmCommunicationBufferSize, &mMmCommunicationBuffer);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a - Failed to locate a viable MM comm buffer! %r\n", __FUNCTION__, Status));
ASSERT_EFI_ERROR (Status);
return Status;
}
// Locate the MmCommunication protocol.
Status = gBS->LocateProtocol( &gEfiMmCommunication2ProtocolGuid, NULL, (VOID**)&mMmCommunication );
if (EFI_ERROR( Status )) {
DEBUG((DEBUG_ERROR, "%a - Failed to locate MmCommunication protocol! %r\n", __FUNCTION__, Status));
ASSERT_EFI_ERROR( Status );
Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **)&mMmCommunication);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a - Failed to locate MmCommunication protocol! %r\n", __FUNCTION__, Status));
ASSERT_EFI_ERROR (Status);
return Status;
}
@@ -523,14 +522,16 @@ VariablePolicySmmDxeMain (
mVariablePolicyProtocol.LockVariablePolicy = ProtocolLockVariablePolicy;
// Register all the protocols and return the status.
Status = gBS->InstallMultipleProtocolInterfaces( &ImageHandle,
&gEdkiiVariablePolicyProtocolGuid, &mVariablePolicyProtocol,
NULL );
if (EFI_ERROR( Status )) {
DEBUG(( DEBUG_ERROR, "%a - Failed to install protocol! %r\n", __FUNCTION__, Status ));
Status = gBS->InstallMultipleProtocolInterfaces (
&ImageHandle,
&gEdkiiVariablePolicyProtocolGuid,
&mVariablePolicyProtocol,
NULL
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a - Failed to install protocol! %r\n", __FUNCTION__, Status));
goto Exit;
}
else {
} else {
ProtocolInstalled = TRUE;
}
@@ -541,31 +542,32 @@ VariablePolicySmmDxeMain (
//
// Register a VirtualAddressChange callback for the MmComm protocol and Comm buffer.
Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
VariablePolicyVirtualAddressCallback,
NULL,
&gEfiEventVirtualAddressChangeGuid,
&VirtualAddressChangeEvent);
if (EFI_ERROR( Status )) {
DEBUG(( DEBUG_ERROR, "%a - Failed to create VirtualAddressChange event! %r\n", __FUNCTION__, Status ));
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
VariablePolicyVirtualAddressCallback,
NULL,
&gEfiEventVirtualAddressChangeGuid,
&VirtualAddressChangeEvent
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a - Failed to create VirtualAddressChange event! %r\n", __FUNCTION__, Status));
goto Exit;
}
else {
} else {
VirtualAddressChangeRegistered = TRUE;
}
Exit:
//
// If we're about to return a failed status (and unload this driver), we must first undo anything that
// has been successfully done.
if (EFI_ERROR( Status )) {
if (EFI_ERROR (Status)) {
if (ProtocolInstalled) {
gBS->UninstallProtocolInterface( &ImageHandle, &gEdkiiVariablePolicyProtocolGuid, &mVariablePolicyProtocol );
gBS->UninstallProtocolInterface (&ImageHandle, &gEdkiiVariablePolicyProtocolGuid, &mVariablePolicyProtocol);
}
if (VirtualAddressChangeRegistered) {
gBS->CloseEvent( VirtualAddressChangeEvent );
gBS->CloseEvent (VirtualAddressChangeEvent);
}
}

View File

@@ -15,8 +15,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "VariableParsing.h"
#include "VariableRuntimeCache.h"
extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;
extern VARIABLE_STORE_HEADER *mNvVariableCache;
extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;
extern VARIABLE_STORE_HEADER *mNvVariableCache;
/**
Copies any pending updates to runtime variable caches.
@@ -30,28 +30,30 @@ FlushPendingRuntimeVariableCacheUpdates (
VOID
)
{
VARIABLE_RUNTIME_CACHE_CONTEXT *VariableRuntimeCacheContext;
VARIABLE_RUNTIME_CACHE_CONTEXT *VariableRuntimeCacheContext;
VariableRuntimeCacheContext = &mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext;
if (VariableRuntimeCacheContext->VariableRuntimeNvCache.Store == NULL ||
VariableRuntimeCacheContext->VariableRuntimeVolatileCache.Store == NULL ||
VariableRuntimeCacheContext->PendingUpdate == NULL) {
if ((VariableRuntimeCacheContext->VariableRuntimeNvCache.Store == NULL) ||
(VariableRuntimeCacheContext->VariableRuntimeVolatileCache.Store == NULL) ||
(VariableRuntimeCacheContext->PendingUpdate == NULL))
{
return EFI_UNSUPPORTED;
}
if (*(VariableRuntimeCacheContext->PendingUpdate)) {
if (VariableRuntimeCacheContext->VariableRuntimeHobCache.Store != NULL &&
mVariableModuleGlobal->VariableGlobal.HobVariableBase > 0) {
if ((VariableRuntimeCacheContext->VariableRuntimeHobCache.Store != NULL) &&
(mVariableModuleGlobal->VariableGlobal.HobVariableBase > 0))
{
CopyMem (
(VOID *) (
((UINT8 *) (UINTN) VariableRuntimeCacheContext->VariableRuntimeHobCache.Store) +
VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateOffset
),
(VOID *) (
((UINT8 *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase) +
VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateOffset
),
(VOID *)(
((UINT8 *)(UINTN)VariableRuntimeCacheContext->VariableRuntimeHobCache.Store) +
VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateOffset
),
(VOID *)(
((UINT8 *)(UINTN)mVariableModuleGlobal->VariableGlobal.HobVariableBase) +
VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateOffset
),
VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateLength
);
VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateLength = 0;
@@ -59,33 +61,33 @@ FlushPendingRuntimeVariableCacheUpdates (
}
CopyMem (
(VOID *) (
((UINT8 *) (UINTN) VariableRuntimeCacheContext->VariableRuntimeNvCache.Store) +
VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateOffset
),
(VOID *) (
((UINT8 *) (UINTN) mNvVariableCache) +
VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateOffset
),
(VOID *)(
((UINT8 *)(UINTN)VariableRuntimeCacheContext->VariableRuntimeNvCache.Store) +
VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateOffset
),
(VOID *)(
((UINT8 *)(UINTN)mNvVariableCache) +
VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateOffset
),
VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateLength
);
VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateLength = 0;
VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateOffset = 0;
CopyMem (
(VOID *) (
((UINT8 *) (UINTN) VariableRuntimeCacheContext->VariableRuntimeVolatileCache.Store) +
VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdateOffset
),
(VOID *) (
((UINT8 *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase) +
VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdateOffset
),
(VOID *)(
((UINT8 *)(UINTN)VariableRuntimeCacheContext->VariableRuntimeVolatileCache.Store) +
VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdateOffset
),
(VOID *)(
((UINT8 *)(UINTN)mVariableModuleGlobal->VariableGlobal.VolatileVariableBase) +
VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdateOffset
),
VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdateLength
);
VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdateLength = 0;
VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdateOffset = 0;
*(VariableRuntimeCacheContext->PendingUpdate) = FALSE;
*(VariableRuntimeCacheContext->PendingUpdate) = FALSE;
}
return EFI_SUCCESS;
@@ -110,9 +112,9 @@ FlushPendingRuntimeVariableCacheUpdates (
**/
EFI_STATUS
SynchronizeRuntimeVariableCache (
IN VARIABLE_RUNTIME_CACHE *VariableRuntimeCache,
IN UINTN Offset,
IN UINTN Length
IN VARIABLE_RUNTIME_CACHE *VariableRuntimeCache,
IN UINTN Offset,
IN UINTN Length
)
{
if (VariableRuntimeCache == NULL) {
@@ -123,26 +125,29 @@ SynchronizeRuntimeVariableCache (
return EFI_SUCCESS;
}
if (mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.PendingUpdate == NULL ||
mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.ReadLock == NULL) {
if ((mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.PendingUpdate == NULL) ||
(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.ReadLock == NULL))
{
return EFI_UNSUPPORTED;
}
if (*(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.PendingUpdate) &&
VariableRuntimeCache->PendingUpdateLength > 0) {
(VariableRuntimeCache->PendingUpdateLength > 0))
{
VariableRuntimeCache->PendingUpdateLength =
(UINT32) (
MAX (
(UINTN) (VariableRuntimeCache->PendingUpdateOffset + VariableRuntimeCache->PendingUpdateLength),
Offset + Length
) - MIN ((UINTN) VariableRuntimeCache->PendingUpdateOffset, Offset)
);
(UINT32)(
MAX (
(UINTN)(VariableRuntimeCache->PendingUpdateOffset + VariableRuntimeCache->PendingUpdateLength),
Offset + Length
) - MIN ((UINTN)VariableRuntimeCache->PendingUpdateOffset, Offset)
);
VariableRuntimeCache->PendingUpdateOffset =
(UINT32) MIN ((UINTN) VariableRuntimeCache->PendingUpdateOffset, Offset);
(UINT32)MIN ((UINTN)VariableRuntimeCache->PendingUpdateOffset, Offset);
} else {
VariableRuntimeCache->PendingUpdateLength = (UINT32) Length;
VariableRuntimeCache->PendingUpdateOffset = (UINT32) Offset;
VariableRuntimeCache->PendingUpdateLength = (UINT32)Length;
VariableRuntimeCache->PendingUpdateOffset = (UINT32)Offset;
}
*(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.PendingUpdate) = TRUE;
if (*(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.ReadLock) == FALSE) {

View File

@@ -43,9 +43,9 @@ FlushPendingRuntimeVariableCacheUpdates (
**/
EFI_STATUS
SynchronizeRuntimeVariableCache (
IN VARIABLE_RUNTIME_CACHE *VariableRuntimeCache,
IN UINTN Offset,
IN UINTN Length
IN VARIABLE_RUNTIME_CACHE *VariableRuntimeCache,
IN UINTN Offset,
IN UINTN Length
);
#endif

View File

@@ -34,11 +34,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "VariableParsing.h"
#include "VariableRuntimeCache.h"
extern VARIABLE_STORE_HEADER *mNvVariableCache;
extern VARIABLE_STORE_HEADER *mNvVariableCache;
BOOLEAN mAtRuntime = FALSE;
UINT8 *mVariableBufferPayload = NULL;
UINTN mVariableBufferPayloadSize;
BOOLEAN mAtRuntime = FALSE;
UINT8 *mVariableBufferPayload = NULL;
UINTN mVariableBufferPayloadSize;
/**
SecureBoot Hook for SetVariable.
@@ -50,11 +50,11 @@ UINTN mVariableBufferPayloadSize;
VOID
EFIAPI
SecureBootHook (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
)
{
return ;
return;
}
/**
@@ -78,14 +78,14 @@ SecureBootHook (
EFI_STATUS
EFIAPI
SmmVariableSetVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
)
{
EFI_STATUS Status;
EFI_STATUS Status;
//
// Disable write protection when the calling SetVariable() through EFI_SMM_VARIABLE_PROTOCOL.
@@ -102,16 +102,18 @@ SmmVariableSetVariable (
return Status;
}
EFI_SMM_VARIABLE_PROTOCOL gSmmVariable = {
EFI_SMM_VARIABLE_PROTOCOL gSmmVariable = {
VariableServiceGetVariable,
VariableServiceGetNextVariableName,
SmmVariableSetVariable,
VariableServiceQueryVariableInfo
};
EDKII_SMM_VAR_CHECK_PROTOCOL mSmmVarCheck = { VarCheckRegisterSetVariableCheckHandler,
VarCheckVariablePropertySet,
VarCheckVariablePropertyGet };
EDKII_SMM_VAR_CHECK_PROTOCOL mSmmVarCheck = {
VarCheckRegisterSetVariableCheckHandler,
VarCheckVariablePropertySet,
VarCheckVariablePropertyGet
};
/**
Return TRUE if ExitBootServices () has been called.
@@ -144,8 +146,8 @@ AtRuntime (
**/
EFI_LOCK *
InitializeLock (
IN OUT EFI_LOCK *Lock,
IN EFI_TPL Priority
IN OUT EFI_LOCK *Lock,
IN EFI_TPL Priority
)
{
return Lock;
@@ -165,13 +167,11 @@ InitializeLock (
**/
VOID
AcquireLockOnlyAtBootTime (
IN EFI_LOCK *Lock
IN EFI_LOCK *Lock
)
{
}
/**
Releases lock only at boot time. Simply returns at runtime.
@@ -186,10 +186,9 @@ AcquireLockOnlyAtBootTime (
**/
VOID
ReleaseLockOnlyAtBootTime (
IN EFI_LOCK *Lock
IN EFI_LOCK *Lock
)
{
}
/**
@@ -204,10 +203,10 @@ ReleaseLockOnlyAtBootTime (
**/
EFI_STATUS
GetFtwProtocol (
OUT VOID **FtwProtocol
OUT VOID **FtwProtocol
)
{
EFI_STATUS Status;
EFI_STATUS Status;
//
// Locate Smm Fault Tolerent Write protocol
@@ -220,7 +219,6 @@ GetFtwProtocol (
return Status;
}
/**
Retrieve the SMM FVB protocol interface by HANDLE.
@@ -245,11 +243,10 @@ GetFvbByHandle (
return gMmst->MmHandleProtocol (
FvBlockHandle,
&gEfiSmmFirmwareVolumeBlockProtocolGuid,
(VOID **) FvBlock
(VOID **)FvBlock
);
}
/**
Function returns an array of handles that support the SMM FVB protocol
in a buffer allocated from pool.
@@ -267,12 +264,12 @@ GetFvbByHandle (
**/
EFI_STATUS
GetFvbCountAndBuffer (
OUT UINTN *NumberHandles,
OUT EFI_HANDLE **Buffer
OUT UINTN *NumberHandles,
OUT EFI_HANDLE **Buffer
)
{
EFI_STATUS Status;
UINTN BufferSize;
EFI_STATUS Status;
UINTN BufferSize;
if ((NumberHandles == NULL) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER;
@@ -281,14 +278,14 @@ GetFvbCountAndBuffer (
BufferSize = 0;
*NumberHandles = 0;
*Buffer = NULL;
Status = gMmst->MmLocateHandle (
ByProtocol,
&gEfiSmmFirmwareVolumeBlockProtocolGuid,
NULL,
&BufferSize,
*Buffer
);
if (EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL) {
Status = gMmst->MmLocateHandle (
ByProtocol,
&gEfiSmmFirmwareVolumeBlockProtocolGuid,
NULL,
&BufferSize,
*Buffer
);
if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
return EFI_NOT_FOUND;
}
@@ -305,8 +302,8 @@ GetFvbCountAndBuffer (
*Buffer
);
*NumberHandles = BufferSize / sizeof(EFI_HANDLE);
if (EFI_ERROR(Status)) {
*NumberHandles = BufferSize / sizeof (EFI_HANDLE);
if (EFI_ERROR (Status)) {
*NumberHandles = 0;
FreePool (*Buffer);
*Buffer = NULL;
@@ -315,7 +312,6 @@ GetFvbCountAndBuffer (
return Status;
}
/**
Get the variable statistics information from the information buffer pointed by gVariableInfo.
@@ -338,16 +334,16 @@ GetFvbCountAndBuffer (
**/
EFI_STATUS
SmmVariableGetStatistics (
IN OUT VARIABLE_INFO_ENTRY *InfoEntry,
IN OUT UINTN *InfoSize
IN OUT VARIABLE_INFO_ENTRY *InfoEntry,
IN OUT UINTN *InfoSize
)
{
VARIABLE_INFO_ENTRY *VariableInfo;
UINTN NameSize;
UINTN StatisticsInfoSize;
CHAR16 *InfoName;
UINTN InfoNameMaxSize;
EFI_GUID VendorGuid;
VARIABLE_INFO_ENTRY *VariableInfo;
UINTN NameSize;
UINTN StatisticsInfoSize;
CHAR16 *InfoName;
UINTN InfoNameMaxSize;
EFI_GUID VendorGuid;
if (InfoEntry == NULL) {
return EFI_INVALID_PARAMETER;
@@ -363,7 +359,8 @@ SmmVariableGetStatistics (
*InfoSize = StatisticsInfoSize;
return EFI_BUFFER_TOO_SMALL;
}
InfoName = (CHAR16 *)(InfoEntry + 1);
InfoName = (CHAR16 *)(InfoEntry + 1);
InfoNameMaxSize = (*InfoSize - sizeof (VARIABLE_INFO_ENTRY));
CopyGuid (&VendorGuid, &InfoEntry->VendorGuid);
@@ -372,12 +369,13 @@ SmmVariableGetStatistics (
//
// Return the first variable info
//
NameSize = StrSize (VariableInfo->Name);
NameSize = StrSize (VariableInfo->Name);
StatisticsInfoSize = sizeof (VARIABLE_INFO_ENTRY) + NameSize;
if (*InfoSize < StatisticsInfoSize) {
*InfoSize = StatisticsInfoSize;
return EFI_BUFFER_TOO_SMALL;
}
CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY));
CopyMem (InfoName, VariableInfo->Name, NameSize);
*InfoSize = StatisticsInfoSize;
@@ -400,8 +398,9 @@ SmmVariableGetStatistics (
}
}
}
VariableInfo = VariableInfo->Next;
};
}
if (VariableInfo == NULL) {
*InfoSize = 0;
@@ -411,7 +410,7 @@ SmmVariableGetStatistics (
//
// Output the new variable info
//
NameSize = StrSize (VariableInfo->Name);
NameSize = StrSize (VariableInfo->Name);
StatisticsInfoSize = sizeof (VARIABLE_INFO_ENTRY) + NameSize;
if (*InfoSize < StatisticsInfoSize) {
*InfoSize = StatisticsInfoSize;
@@ -425,7 +424,6 @@ SmmVariableGetStatistics (
return EFI_SUCCESS;
}
/**
Communication service SMI Handler entry.
@@ -455,34 +453,34 @@ SmmVariableGetStatistics (
EFI_STATUS
EFIAPI
SmmVariableHandler (
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *RegisterContext,
IN OUT VOID *CommBuffer,
IN OUT UINTN *CommBufferSize
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *RegisterContext,
IN OUT VOID *CommBuffer,
IN OUT UINTN *CommBufferSize
)
{
EFI_STATUS Status;
SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;
SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *SmmVariableHeader;
SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *GetNextVariableName;
SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *QueryVariableInfo;
SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *GetPayloadSize;
SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *RuntimeVariableCacheContext;
SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO *GetRuntimeCacheInfo;
SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *VariableToLock;
SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *CommVariableProperty;
VARIABLE_INFO_ENTRY *VariableInfo;
VARIABLE_RUNTIME_CACHE_CONTEXT *VariableCacheContext;
VARIABLE_STORE_HEADER *VariableCache;
UINTN InfoSize;
UINTN NameBufferSize;
UINTN CommBufferPayloadSize;
UINTN TempCommBufferSize;
EFI_STATUS Status;
SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;
SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *SmmVariableHeader;
SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *GetNextVariableName;
SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *QueryVariableInfo;
SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *GetPayloadSize;
SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *RuntimeVariableCacheContext;
SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO *GetRuntimeCacheInfo;
SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *VariableToLock;
SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *CommVariableProperty;
VARIABLE_INFO_ENTRY *VariableInfo;
VARIABLE_RUNTIME_CACHE_CONTEXT *VariableCacheContext;
VARIABLE_STORE_HEADER *VariableCache;
UINTN InfoSize;
UINTN NameBufferSize;
UINTN CommBufferPayloadSize;
UINTN TempCommBufferSize;
//
// If input is invalid, stop processing this SMI
//
if (CommBuffer == NULL || CommBufferSize == NULL) {
if ((CommBuffer == NULL) || (CommBufferSize == NULL)) {
return EFI_SUCCESS;
}
@@ -492,6 +490,7 @@ SmmVariableHandler (
DEBUG ((DEBUG_ERROR, "SmmVariableHandler: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
CommBufferPayloadSize = TempCommBufferSize - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
if (CommBufferPayloadSize > mVariableBufferPayloadSize) {
DEBUG ((DEBUG_ERROR, "SmmVariableHandler: SMM communication buffer payload size invalid!\n"));
@@ -506,24 +505,27 @@ SmmVariableHandler (
SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)CommBuffer;
switch (SmmVariableFunctionHeader->Function) {
case SMM_VARIABLE_FUNCTION_GET_VARIABLE:
if (CommBufferPayloadSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) {
if (CommBufferPayloadSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) {
DEBUG ((DEBUG_ERROR, "GetVariable: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
//
// Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.
//
CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);
SmmVariableHeader = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *) mVariableBufferPayload;
if (((UINTN)(~0) - SmmVariableHeader->DataSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) ||
((UINTN)(~0) - SmmVariableHeader->NameSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + SmmVariableHeader->DataSize)) {
SmmVariableHeader = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *)mVariableBufferPayload;
if (((UINTN)(~0) - SmmVariableHeader->DataSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) ||
((UINTN)(~0) - SmmVariableHeader->NameSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + SmmVariableHeader->DataSize))
{
//
// Prevent InfoSize overflow happen
//
Status = EFI_ACCESS_DENIED;
goto EXIT;
}
InfoSize = OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)
InfoSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)
+ SmmVariableHeader->DataSize + SmmVariableHeader->NameSize;
//
@@ -541,7 +543,7 @@ SmmVariableHandler (
// subsequent consumption of the CommBuffer content.
//
VariableSpeculationBarrier ();
if (SmmVariableHeader->NameSize < sizeof (CHAR16) || SmmVariableHeader->Name[SmmVariableHeader->NameSize/sizeof (CHAR16) - 1] != L'\0') {
if ((SmmVariableHeader->NameSize < sizeof (CHAR16)) || (SmmVariableHeader->Name[SmmVariableHeader->NameSize/sizeof (CHAR16) - 1] != L'\0')) {
//
// Make sure VariableName is A Null-terminated string.
//
@@ -560,23 +562,25 @@ SmmVariableHandler (
break;
case SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME:
if (CommBufferPayloadSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {
if (CommBufferPayloadSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {
DEBUG ((DEBUG_ERROR, "GetNextVariableName: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
//
// Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.
//
CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);
GetNextVariableName = (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *) mVariableBufferPayload;
if ((UINTN)(~0) - GetNextVariableName->NameSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {
GetNextVariableName = (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *)mVariableBufferPayload;
if ((UINTN)(~0) - GetNextVariableName->NameSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {
//
// Prevent InfoSize overflow happen
//
Status = EFI_ACCESS_DENIED;
goto EXIT;
}
InfoSize = OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name) + GetNextVariableName->NameSize;
InfoSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name) + GetNextVariableName->NameSize;
//
// SMRAM range check already covered before
@@ -587,8 +591,8 @@ SmmVariableHandler (
goto EXIT;
}
NameBufferSize = CommBufferPayloadSize - OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name);
if (NameBufferSize < sizeof (CHAR16) || GetNextVariableName->Name[NameBufferSize/sizeof (CHAR16) - 1] != L'\0') {
NameBufferSize = CommBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name);
if ((NameBufferSize < sizeof (CHAR16)) || (GetNextVariableName->Name[NameBufferSize/sizeof (CHAR16) - 1] != L'\0')) {
//
// Make sure input VariableName is A Null-terminated string.
//
@@ -605,24 +609,27 @@ SmmVariableHandler (
break;
case SMM_VARIABLE_FUNCTION_SET_VARIABLE:
if (CommBufferPayloadSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) {
if (CommBufferPayloadSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) {
DEBUG ((DEBUG_ERROR, "SetVariable: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
//
// Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.
//
CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);
SmmVariableHeader = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *) mVariableBufferPayload;
if (((UINTN)(~0) - SmmVariableHeader->DataSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) ||
((UINTN)(~0) - SmmVariableHeader->NameSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + SmmVariableHeader->DataSize)) {
SmmVariableHeader = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *)mVariableBufferPayload;
if (((UINTN)(~0) - SmmVariableHeader->DataSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) ||
((UINTN)(~0) - SmmVariableHeader->NameSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + SmmVariableHeader->DataSize))
{
//
// Prevent InfoSize overflow happen
//
Status = EFI_ACCESS_DENIED;
goto EXIT;
}
InfoSize = OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)
InfoSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)
+ SmmVariableHeader->DataSize + SmmVariableHeader->NameSize;
//
@@ -641,7 +648,7 @@ SmmVariableHandler (
// subsequent consumption of the CommBuffer content.
//
VariableSpeculationBarrier ();
if (SmmVariableHeader->NameSize < sizeof (CHAR16) || SmmVariableHeader->Name[SmmVariableHeader->NameSize/sizeof (CHAR16) - 1] != L'\0') {
if ((SmmVariableHeader->NameSize < sizeof (CHAR16)) || (SmmVariableHeader->Name[SmmVariableHeader->NameSize/sizeof (CHAR16) - 1] != L'\0')) {
//
// Make sure VariableName is A Null-terminated string.
//
@@ -663,7 +670,8 @@ SmmVariableHandler (
DEBUG ((DEBUG_ERROR, "QueryVariableInfo: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
QueryVariableInfo = (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *) SmmVariableFunctionHeader->Data;
QueryVariableInfo = (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *)SmmVariableFunctionHeader->Data;
Status = VariableServiceQueryVariableInfo (
QueryVariableInfo->Attributes,
@@ -678,16 +686,18 @@ SmmVariableHandler (
DEBUG ((DEBUG_ERROR, "GetPayloadSize: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
GetPayloadSize = (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *) SmmVariableFunctionHeader->Data;
GetPayloadSize = (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *)SmmVariableFunctionHeader->Data;
GetPayloadSize->VariablePayloadSize = mVariableBufferPayloadSize;
Status = EFI_SUCCESS;
Status = EFI_SUCCESS;
break;
case SMM_VARIABLE_FUNCTION_READY_TO_BOOT:
if (AtRuntime()) {
if (AtRuntime ()) {
Status = EFI_UNSUPPORTED;
break;
}
if (!mEndOfDxe) {
MorLockInitAtEndOfDxe ();
Status = LockVariablePolicy ();
@@ -699,18 +709,19 @@ SmmVariableHandler (
//
InitializeVariableQuota ();
}
ReclaimForOS ();
Status = EFI_SUCCESS;
break;
case SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE:
mAtRuntime = TRUE;
Status = EFI_SUCCESS;
Status = EFI_SUCCESS;
break;
case SMM_VARIABLE_FUNCTION_GET_STATISTICS:
VariableInfo = (VARIABLE_INFO_ENTRY *) SmmVariableFunctionHeader->Data;
InfoSize = TempCommBufferSize - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
VariableInfo = (VARIABLE_INFO_ENTRY *)SmmVariableFunctionHeader->Data;
InfoSize = TempCommBufferSize - SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
//
// Do not need to check SmmVariableFunctionHeader->Data in SMRAM here.
@@ -722,7 +733,7 @@ SmmVariableHandler (
// that was used by SMM core to cache CommSize from SmmCommunication protocol.
//
Status = SmmVariableGetStatistics (VariableInfo, &InfoSize);
Status = SmmVariableGetStatistics (VariableInfo, &InfoSize);
*CommBufferSize = InfoSize + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
break;
@@ -730,43 +741,47 @@ SmmVariableHandler (
if (mEndOfDxe) {
Status = EFI_ACCESS_DENIED;
} else {
VariableToLock = (SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *) SmmVariableFunctionHeader->Data;
Status = VariableLockRequestToLock (
NULL,
VariableToLock->Name,
&VariableToLock->Guid
);
VariableToLock = (SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *)SmmVariableFunctionHeader->Data;
Status = VariableLockRequestToLock (
NULL,
VariableToLock->Name,
&VariableToLock->Guid
);
}
break;
case SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET:
if (mEndOfDxe) {
Status = EFI_ACCESS_DENIED;
} else {
CommVariableProperty = (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *) SmmVariableFunctionHeader->Data;
Status = VarCheckVariablePropertySet (
CommVariableProperty->Name,
&CommVariableProperty->Guid,
&CommVariableProperty->VariableProperty
);
CommVariableProperty = (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *)SmmVariableFunctionHeader->Data;
Status = VarCheckVariablePropertySet (
CommVariableProperty->Name,
&CommVariableProperty->Guid,
&CommVariableProperty->VariableProperty
);
}
break;
case SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET:
if (CommBufferPayloadSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {
DEBUG ((DEBUG_ERROR, "VarCheckVariablePropertyGet: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
//
// Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.
//
CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);
CommVariableProperty = (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *) mVariableBufferPayload;
if ((UINTN) (~0) - CommVariableProperty->NameSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {
CommVariableProperty = (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *)mVariableBufferPayload;
if ((UINTN)(~0) - CommVariableProperty->NameSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {
//
// Prevent InfoSize overflow happen
//
Status = EFI_ACCESS_DENIED;
goto EXIT;
}
InfoSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) + CommVariableProperty->NameSize;
//
@@ -784,7 +799,7 @@ SmmVariableHandler (
// subsequent consumption of the CommBuffer content.
//
VariableSpeculationBarrier ();
if (CommVariableProperty->NameSize < sizeof (CHAR16) || CommVariableProperty->Name[CommVariableProperty->NameSize/sizeof (CHAR16) - 1] != L'\0') {
if ((CommVariableProperty->NameSize < sizeof (CHAR16)) || (CommVariableProperty->Name[CommVariableProperty->NameSize/sizeof (CHAR16) - 1] != L'\0')) {
//
// Make sure VariableName is A Null-terminated string.
//
@@ -805,6 +820,7 @@ SmmVariableHandler (
Status = EFI_ACCESS_DENIED;
goto EXIT;
}
if (mEndOfDxe) {
DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Cannot init context after end of DXE!\n"));
Status = EFI_ACCESS_DENIED;
@@ -815,16 +831,17 @@ SmmVariableHandler (
// Copy the input communicate buffer payload to the pre-allocated SMM variable payload buffer.
//
CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);
RuntimeVariableCacheContext = (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *) mVariableBufferPayload;
RuntimeVariableCacheContext = (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *)mVariableBufferPayload;
//
// Verify required runtime cache buffers are provided.
//
if (RuntimeVariableCacheContext->RuntimeVolatileCache == NULL ||
RuntimeVariableCacheContext->RuntimeNvCache == NULL ||
RuntimeVariableCacheContext->PendingUpdate == NULL ||
RuntimeVariableCacheContext->ReadLock == NULL ||
RuntimeVariableCacheContext->HobFlushComplete == NULL) {
if ((RuntimeVariableCacheContext->RuntimeVolatileCache == NULL) ||
(RuntimeVariableCacheContext->RuntimeNvCache == NULL) ||
(RuntimeVariableCacheContext->PendingUpdate == NULL) ||
(RuntimeVariableCacheContext->ReadLock == NULL) ||
(RuntimeVariableCacheContext->HobFlushComplete == NULL))
{
DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Required runtime cache buffer is NULL!\n"));
Status = EFI_ACCESS_DENIED;
goto EXIT;
@@ -833,10 +850,11 @@ SmmVariableHandler (
//
// Verify minimum size requirements for the runtime variable store buffers.
//
if ((RuntimeVariableCacheContext->RuntimeHobCache != NULL &&
RuntimeVariableCacheContext->RuntimeHobCache->Size < sizeof (VARIABLE_STORE_HEADER)) ||
RuntimeVariableCacheContext->RuntimeVolatileCache->Size < sizeof (VARIABLE_STORE_HEADER) ||
RuntimeVariableCacheContext->RuntimeNvCache->Size < sizeof (VARIABLE_STORE_HEADER)) {
if (((RuntimeVariableCacheContext->RuntimeHobCache != NULL) &&
(RuntimeVariableCacheContext->RuntimeHobCache->Size < sizeof (VARIABLE_STORE_HEADER))) ||
(RuntimeVariableCacheContext->RuntimeVolatileCache->Size < sizeof (VARIABLE_STORE_HEADER)) ||
(RuntimeVariableCacheContext->RuntimeNvCache->Size < sizeof (VARIABLE_STORE_HEADER)))
{
DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: A runtime cache buffer size is invalid!\n"));
Status = EFI_ACCESS_DENIED;
goto EXIT;
@@ -845,51 +863,68 @@ SmmVariableHandler (
//
// Verify runtime buffers do not overlap with SMRAM ranges.
//
if (RuntimeVariableCacheContext->RuntimeHobCache != NULL &&
if ((RuntimeVariableCacheContext->RuntimeHobCache != NULL) &&
!VariableSmmIsBufferOutsideSmmValid (
(UINTN) RuntimeVariableCacheContext->RuntimeHobCache,
(UINTN) RuntimeVariableCacheContext->RuntimeHobCache->Size)) {
(UINTN)RuntimeVariableCacheContext->RuntimeHobCache,
(UINTN)RuntimeVariableCacheContext->RuntimeHobCache->Size
))
{
DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Runtime HOB cache buffer in SMRAM or overflow!\n"));
Status = EFI_ACCESS_DENIED;
goto EXIT;
}
if (!VariableSmmIsBufferOutsideSmmValid (
(UINTN) RuntimeVariableCacheContext->RuntimeVolatileCache,
(UINTN) RuntimeVariableCacheContext->RuntimeVolatileCache->Size)) {
(UINTN)RuntimeVariableCacheContext->RuntimeVolatileCache,
(UINTN)RuntimeVariableCacheContext->RuntimeVolatileCache->Size
))
{
DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Runtime volatile cache buffer in SMRAM or overflow!\n"));
Status = EFI_ACCESS_DENIED;
goto EXIT;
}
if (!VariableSmmIsBufferOutsideSmmValid (
(UINTN) RuntimeVariableCacheContext->RuntimeNvCache,
(UINTN) RuntimeVariableCacheContext->RuntimeNvCache->Size)) {
(UINTN)RuntimeVariableCacheContext->RuntimeNvCache,
(UINTN)RuntimeVariableCacheContext->RuntimeNvCache->Size
))
{
DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Runtime non-volatile cache buffer in SMRAM or overflow!\n"));
Status = EFI_ACCESS_DENIED;
goto EXIT;
}
if (!VariableSmmIsBufferOutsideSmmValid (
(UINTN) RuntimeVariableCacheContext->PendingUpdate,
sizeof (*(RuntimeVariableCacheContext->PendingUpdate)))) {
(UINTN)RuntimeVariableCacheContext->PendingUpdate,
sizeof (*(RuntimeVariableCacheContext->PendingUpdate))
))
{
DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Runtime cache pending update buffer in SMRAM or overflow!\n"));
Status = EFI_ACCESS_DENIED;
goto EXIT;
}
if (!VariableSmmIsBufferOutsideSmmValid (
(UINTN) RuntimeVariableCacheContext->ReadLock,
sizeof (*(RuntimeVariableCacheContext->ReadLock)))) {
(UINTN)RuntimeVariableCacheContext->ReadLock,
sizeof (*(RuntimeVariableCacheContext->ReadLock))
))
{
DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Runtime cache read lock buffer in SMRAM or overflow!\n"));
Status = EFI_ACCESS_DENIED;
goto EXIT;
}
if (!VariableSmmIsBufferOutsideSmmValid (
(UINTN) RuntimeVariableCacheContext->HobFlushComplete,
sizeof (*(RuntimeVariableCacheContext->HobFlushComplete)))) {
(UINTN)RuntimeVariableCacheContext->HobFlushComplete,
sizeof (*(RuntimeVariableCacheContext->HobFlushComplete))
))
{
DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Runtime cache HOB flush complete buffer in SMRAM or overflow!\n"));
Status = EFI_ACCESS_DENIED;
goto EXIT;
}
VariableCacheContext = &mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext;
VariableCacheContext = &mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext;
VariableCacheContext->VariableRuntimeHobCache.Store = RuntimeVariableCacheContext->RuntimeHobCache;
VariableCacheContext->VariableRuntimeVolatileCache.Store = RuntimeVariableCacheContext->RuntimeVolatileCache;
VariableCacheContext->VariableRuntimeNvCache.Store = RuntimeVariableCacheContext->RuntimeNvCache;
@@ -900,24 +935,26 @@ SmmVariableHandler (
// Set up the intial pending request since the RT cache needs to be in sync with SMM cache
VariableCacheContext->VariableRuntimeHobCache.PendingUpdateOffset = 0;
VariableCacheContext->VariableRuntimeHobCache.PendingUpdateLength = 0;
if (mVariableModuleGlobal->VariableGlobal.HobVariableBase > 0 &&
VariableCacheContext->VariableRuntimeHobCache.Store != NULL) {
VariableCache = (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase;
VariableCacheContext->VariableRuntimeHobCache.PendingUpdateLength = (UINT32) ((UINTN) GetEndPointer (VariableCache) - (UINTN) VariableCache);
if ((mVariableModuleGlobal->VariableGlobal.HobVariableBase > 0) &&
(VariableCacheContext->VariableRuntimeHobCache.Store != NULL))
{
VariableCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableModuleGlobal->VariableGlobal.HobVariableBase;
VariableCacheContext->VariableRuntimeHobCache.PendingUpdateLength = (UINT32)((UINTN)GetEndPointer (VariableCache) - (UINTN)VariableCache);
CopyGuid (&(VariableCacheContext->VariableRuntimeHobCache.Store->Signature), &(VariableCache->Signature));
}
VariableCache = (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;
VariableCacheContext->VariableRuntimeVolatileCache.PendingUpdateOffset = 0;
VariableCacheContext->VariableRuntimeVolatileCache.PendingUpdateLength = (UINT32) ((UINTN) GetEndPointer (VariableCache) - (UINTN) VariableCache);
VariableCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;
VariableCacheContext->VariableRuntimeVolatileCache.PendingUpdateOffset = 0;
VariableCacheContext->VariableRuntimeVolatileCache.PendingUpdateLength = (UINT32)((UINTN)GetEndPointer (VariableCache) - (UINTN)VariableCache);
CopyGuid (&(VariableCacheContext->VariableRuntimeVolatileCache.Store->Signature), &(VariableCache->Signature));
VariableCache = (VARIABLE_STORE_HEADER *) (UINTN) mNvVariableCache;
VariableCache = (VARIABLE_STORE_HEADER *)(UINTN)mNvVariableCache;
VariableCacheContext->VariableRuntimeNvCache.PendingUpdateOffset = 0;
VariableCacheContext->VariableRuntimeNvCache.PendingUpdateLength = (UINT32) ((UINTN) GetEndPointer (VariableCache) - (UINTN) VariableCache);
VariableCacheContext->VariableRuntimeNvCache.PendingUpdateLength = (UINT32)((UINTN)GetEndPointer (VariableCache) - (UINTN)VariableCache);
CopyGuid (&(VariableCacheContext->VariableRuntimeNvCache.Store->Signature), &(VariableCache->Signature));
*(VariableCacheContext->PendingUpdate) = TRUE;
*(VariableCacheContext->ReadLock) = FALSE;
*(VariableCacheContext->PendingUpdate) = TRUE;
*(VariableCacheContext->ReadLock) = FALSE;
*(VariableCacheContext->HobFlushComplete) = FALSE;
Status = EFI_SUCCESS;
@@ -930,19 +967,20 @@ SmmVariableHandler (
DEBUG ((DEBUG_ERROR, "GetRuntimeCacheInfo: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
GetRuntimeCacheInfo = (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO *) SmmVariableFunctionHeader->Data;
GetRuntimeCacheInfo = (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO *)SmmVariableFunctionHeader->Data;
if (mVariableModuleGlobal->VariableGlobal.HobVariableBase > 0) {
VariableCache = (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase;
VariableCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableModuleGlobal->VariableGlobal.HobVariableBase;
GetRuntimeCacheInfo->TotalHobStorageSize = VariableCache->Size;
} else {
GetRuntimeCacheInfo->TotalHobStorageSize = 0;
}
VariableCache = (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;
GetRuntimeCacheInfo->TotalVolatileStorageSize = VariableCache->Size;
VariableCache = (VARIABLE_STORE_HEADER *) (UINTN) mNvVariableCache;
GetRuntimeCacheInfo->TotalNvStorageSize = (UINTN) VariableCache->Size;
VariableCache = (VARIABLE_STORE_HEADER *)(UINTN)mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;
GetRuntimeCacheInfo->TotalVolatileStorageSize = VariableCache->Size;
VariableCache = (VARIABLE_STORE_HEADER *)(UINTN)mNvVariableCache;
GetRuntimeCacheInfo->TotalNvStorageSize = (UINTN)VariableCache->Size;
GetRuntimeCacheInfo->AuthenticatedVariableUsage = mVariableModuleGlobal->VariableGlobal.AuthFormat;
Status = EFI_SUCCESS;
@@ -972,12 +1010,12 @@ EXIT:
EFI_STATUS
EFIAPI
SmmEndOfDxeCallback (
IN CONST EFI_GUID *Protocol,
IN VOID *Interface,
IN EFI_HANDLE Handle
IN CONST EFI_GUID *Protocol,
IN VOID *Interface,
IN EFI_HANDLE Handle
)
{
EFI_STATUS Status;
EFI_STATUS Status;
DEBUG ((DEBUG_INFO, "[Variable]SMM_END_OF_DXE is signaled\n"));
MorLockInitAtEndOfDxe ();
@@ -1005,7 +1043,7 @@ VariableWriteServiceInitializeSmm (
VOID
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = VariableWriteServiceInitialize ();
if (EFI_ERROR (Status)) {
@@ -1035,9 +1073,9 @@ VariableWriteServiceInitializeSmm (
EFI_STATUS
EFIAPI
SmmFtwNotificationEvent (
IN CONST EFI_GUID *Protocol,
IN VOID *Interface,
IN EFI_HANDLE Handle
IN CONST EFI_GUID *Protocol,
IN VOID *Interface,
IN EFI_HANDLE Handle
)
{
EFI_STATUS Status;
@@ -1065,7 +1103,7 @@ SmmFtwNotificationEvent (
}
NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;
VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
//
// Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.
@@ -1090,7 +1128,6 @@ SmmFtwNotificationEvent (
return EFI_SUCCESS;
}
/**
Variable Driver main entry point. The Variable driver places the 4 EFI
runtime services in the EFI System Table and installs arch protocols
@@ -1106,10 +1143,10 @@ MmVariableServiceInitialize (
VOID
)
{
EFI_STATUS Status;
EFI_HANDLE VariableHandle;
VOID *SmmFtwRegistration;
VOID *SmmEndOfDxeRegistration;
EFI_STATUS Status;
EFI_HANDLE VariableHandle;
VOID *SmmFtwRegistration;
VOID *SmmEndOfDxeRegistration;
//
// Variable initialize.
@@ -1121,12 +1158,12 @@ MmVariableServiceInitialize (
// Install the Smm Variable Protocol on a new handle.
//
VariableHandle = NULL;
Status = gMmst->MmInstallProtocolInterface (
&VariableHandle,
&gEfiSmmVariableProtocolGuid,
EFI_NATIVE_INTERFACE,
&gSmmVariable
);
Status = gMmst->MmInstallProtocolInterface (
&VariableHandle,
&gEfiSmmVariableProtocolGuid,
EFI_NATIVE_INTERFACE,
&gSmmVariable
);
ASSERT_EFI_ERROR (Status);
Status = gMmst->MmInstallProtocolInterface (
@@ -1138,8 +1175,8 @@ MmVariableServiceInitialize (
ASSERT_EFI_ERROR (Status);
mVariableBufferPayloadSize = GetMaxVariableSize () +
OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) -
GetVariableHeaderSize (mVariableModuleGlobal->VariableGlobal.AuthFormat);
OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) -
GetVariableHeaderSize (mVariableModuleGlobal->VariableGlobal.AuthFormat);
Status = gMmst->MmAllocatePool (
EfiRuntimeServicesData,
@@ -1152,7 +1189,7 @@ MmVariableServiceInitialize (
/// Register SMM variable SMI handler
///
VariableHandle = NULL;
Status = gMmst->MmiHandlerRegister (SmmVariableHandler, &gEfiSmmVariableProtocolGuid, &VariableHandle);
Status = gMmst->MmiHandlerRegister (SmmVariableHandler, &gEfiSmmVariableProtocolGuid, &VariableHandle);
ASSERT_EFI_ERROR (Status);
//

View File

@@ -63,8 +63,8 @@ VariableNotifySmmWriteReady (
EFI_STATUS
EFIAPI
VariableServiceInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
IN EFI_HANDLE ImageHandle,
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
)
{
return MmVariableServiceInitialize ();

View File

@@ -41,8 +41,8 @@ VariableNotifySmmReady (
VOID
)
{
EFI_STATUS Status;
EFI_HANDLE Handle;
EFI_STATUS Status;
EFI_HANDLE Handle;
Handle = NULL;
Status = gBS->InstallProtocolInterface (
@@ -62,8 +62,8 @@ VariableNotifySmmWriteReady (
VOID
)
{
EFI_STATUS Status;
EFI_HANDLE Handle;
EFI_STATUS Status;
EFI_HANDLE Handle;
Handle = NULL;
Status = gBS->InstallProtocolInterface (
@@ -87,8 +87,8 @@ VariableNotifySmmWriteReady (
EFI_STATUS
EFIAPI
VariableServiceInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return MmVariableServiceInitialize ();
@@ -109,8 +109,8 @@ VariableHaveTcgProtocols (
VOID
)
{
EFI_STATUS Status;
VOID *Interface;
EFI_STATUS Status;
VOID *Interface;
Status = gBS->LocateProtocol (
&gEfiTcg2ProtocolGuid,