mirror of https://github.com/acidanthera/audk.git
SecurityPkg Variable: Implement VarCheck PROTOCOL
and follow UEFI spec to check UEFI defined variables. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16580 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
efb01a104d
commit
17409b7aad
File diff suppressed because it is too large
Load Diff
|
@ -16,7 +16,7 @@
|
|||
VariableServiceSetVariable() should also check authenticate data to avoid buffer overflow,
|
||||
integer overflow. It should also check attribute to avoid authentication bypass.
|
||||
|
||||
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -58,52 +58,6 @@ BOOLEAN mEndOfDxe = FALSE;
|
|||
///
|
||||
BOOLEAN mEnableLocking = TRUE;
|
||||
|
||||
//
|
||||
// To prevent name collisions with possible future globally defined variables,
|
||||
// other internal firmware data variables that are not defined here must be
|
||||
// saved with a unique VendorGuid other than EFI_GLOBAL_VARIABLE or
|
||||
// any other GUID defined by the UEFI Specification. Implementations must
|
||||
// only permit the creation of variables with a UEFI Specification-defined
|
||||
// VendorGuid when these variables are documented in the UEFI Specification.
|
||||
//
|
||||
GLOBAL_VARIABLE_ENTRY mGlobalVariableList[] = {
|
||||
{EFI_LANG_CODES_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_LANG_VARIABLE_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{EFI_TIME_OUT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{EFI_PLATFORM_LANG_CODES_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_PLATFORM_LANG_VARIABLE_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{EFI_CON_IN_VARIABLE_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{EFI_CON_OUT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{EFI_ERR_OUT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{EFI_CON_IN_DEV_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_CON_OUT_DEV_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_ERR_OUT_DEV_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_BOOT_ORDER_VARIABLE_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{EFI_BOOT_NEXT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{EFI_BOOT_CURRENT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_DRIVER_ORDER_VARIABLE_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{EFI_SETUP_MODE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_KEY_EXCHANGE_KEY_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT_AT},
|
||||
{EFI_PLATFORM_KEY_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT_AT},
|
||||
{EFI_SIGNATURE_SUPPORT_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_SECURE_BOOT_MODE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_KEK_DEFAULT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_PK_DEFAULT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_DB_DEFAULT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_DBX_DEFAULT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_DBT_DEFAULT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
{EFI_OS_INDICATIONS_VARIABLE_NAME, VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{EFI_VENDOR_KEYS_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},
|
||||
};
|
||||
GLOBAL_VARIABLE_ENTRY mGlobalVariableList2[] = {
|
||||
{L"Boot####", VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{L"Driver####", VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
{L"Key####", VARIABLE_ATTRIBUTE_NV_BS_RT},
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
SecureBoot Hook for auth variable update.
|
||||
|
@ -891,8 +845,8 @@ Reclaim (
|
|||
HwErrVariableTotalSize += VariableSize;
|
||||
} else if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
|
||||
CommonVariableTotalSize += VariableSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
Variable = NextVariable;
|
||||
}
|
||||
|
||||
|
@ -926,8 +880,8 @@ Reclaim (
|
|||
HwErrVariableTotalSize += VariableSize;
|
||||
} else if ((!IsVolatile) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
|
||||
CommonVariableTotalSize += VariableSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
Variable = NextVariable;
|
||||
}
|
||||
|
||||
|
@ -974,9 +928,9 @@ Reclaim (
|
|||
HwErrVariableTotalSize += VariableSize;
|
||||
} else if ((!IsVolatile) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
|
||||
CommonVariableTotalSize += VariableSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Variable = NextVariable;
|
||||
}
|
||||
|
@ -997,7 +951,7 @@ Reclaim (
|
|||
HwErrVariableTotalSize += NewVariableSize;
|
||||
} else if ((NewVariable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
|
||||
CommonVariableTotalSize += NewVariableSize;
|
||||
}
|
||||
}
|
||||
if ((HwErrVariableTotalSize > PcdGet32 (PcdHwErrStorageSize)) ||
|
||||
(CommonVariableTotalSize > VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER) - PcdGet32 (PcdHwErrStorageSize))) {
|
||||
//
|
||||
|
@ -1046,7 +1000,7 @@ Reclaim (
|
|||
mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VariableSize);
|
||||
} else if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
|
||||
mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN (VariableSize);
|
||||
}
|
||||
}
|
||||
|
||||
NextVariable = GetNextVariablePtr (NextVariable);
|
||||
}
|
||||
|
@ -2329,7 +2283,7 @@ UpdateVariable (
|
|||
}
|
||||
UpdateVariableInfo (VariableName, VendorGuid, FALSE, FALSE, TRUE, FALSE, FALSE);
|
||||
FlushHobVariableToFlash (VariableName, VendorGuid);
|
||||
}
|
||||
}
|
||||
goto Done;
|
||||
}
|
||||
//
|
||||
|
@ -2414,7 +2368,7 @@ UpdateVariable (
|
|||
mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VarSize);
|
||||
} else {
|
||||
mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN (VarSize);
|
||||
}
|
||||
}
|
||||
//
|
||||
// update the memory copy of Flash region.
|
||||
//
|
||||
|
@ -2585,63 +2539,6 @@ IsHwErrRecVariable (
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
This code checks if variable guid is global variable guid first.
|
||||
If yes, further check if variable name is in mGlobalVariableList or mGlobalVariableList2 and attributes matched.
|
||||
|
||||
@param[in] VariableName Pointer to variable name.
|
||||
@param[in] VendorGuid Variable Vendor Guid.
|
||||
@param[in] Attributes Attributes of the variable.
|
||||
|
||||
@retval EFI_SUCCESS Variable is not global variable, or Variable is global variable, variable name is in the lists and attributes matched.
|
||||
@retval EFI_INVALID_PARAMETER Variable is global variable, but variable name is not in the lists or attributes unmatched.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CheckEfiGlobalVariable (
|
||||
IN CHAR16 *VariableName,
|
||||
IN EFI_GUID *VendorGuid,
|
||||
IN UINT32 Attributes
|
||||
)
|
||||
{
|
||||
UINTN Index;
|
||||
UINTN NameLength;
|
||||
|
||||
if (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid)){
|
||||
//
|
||||
// Try list 1, exactly match.
|
||||
//
|
||||
for (Index = 0; Index < sizeof (mGlobalVariableList)/sizeof (mGlobalVariableList[0]); Index++) {
|
||||
if ((StrCmp (mGlobalVariableList[Index].Name, VariableName) == 0) &&
|
||||
(Attributes == 0 || (Attributes & (~EFI_VARIABLE_APPEND_WRITE)) == mGlobalVariableList[Index].Attributes)) {
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Try list 2.
|
||||
//
|
||||
NameLength = StrLen (VariableName) - 4;
|
||||
for (Index = 0; Index < sizeof (mGlobalVariableList2)/sizeof (mGlobalVariableList2[0]); Index++) {
|
||||
if ((StrLen (VariableName) == StrLen (mGlobalVariableList2[Index].Name)) &&
|
||||
(StrnCmp (mGlobalVariableList2[Index].Name, VariableName, NameLength) == 0) &&
|
||||
IsHexaDecimalDigitCharacter (VariableName[NameLength]) &&
|
||||
IsHexaDecimalDigitCharacter (VariableName[NameLength + 1]) &&
|
||||
IsHexaDecimalDigitCharacter (VariableName[NameLength + 2]) &&
|
||||
IsHexaDecimalDigitCharacter (VariableName[NameLength + 3]) &&
|
||||
(Attributes == 0 || (Attributes & (~EFI_VARIABLE_APPEND_WRITE)) == mGlobalVariableList2[Index].Attributes)) {
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG ((EFI_D_INFO, "[Variable]: set global variable with invalid variable name or attributes - %g:%s:%x\n", VendorGuid, VariableName, Attributes));
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
Mark a variable that will become read-only after leaving the DXE phase of execution.
|
||||
|
||||
|
@ -2666,6 +2563,7 @@ VariableLockRequestToLock (
|
|||
)
|
||||
{
|
||||
VARIABLE_ENTRY *Entry;
|
||||
CHAR16 *Name;
|
||||
|
||||
if (VariableName == NULL || VariableName[0] == 0 || VendorGuid == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
|
@ -2675,7 +2573,7 @@ VariableLockRequestToLock (
|
|||
return EFI_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
Entry = AllocateRuntimePool (sizeof (*Entry) + StrSize (VariableName));
|
||||
Entry = AllocateRuntimeZeroPool (sizeof (*Entry) + StrSize (VariableName));
|
||||
if (Entry == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
@ -2684,8 +2582,8 @@ VariableLockRequestToLock (
|
|||
|
||||
AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
|
||||
|
||||
Entry->Name = (CHAR16 *) (Entry + 1);
|
||||
StrCpy (Entry->Name, VariableName);
|
||||
Name = (CHAR16 *) ((UINTN) Entry + sizeof (*Entry));
|
||||
StrnCpy (Name, VariableName, StrLen (VariableName));
|
||||
CopyGuid (&Entry->Guid, VendorGuid);
|
||||
InsertTailList (&mLockedVariableList, &Entry->Link);
|
||||
|
||||
|
@ -2694,39 +2592,6 @@ VariableLockRequestToLock (
|
|||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
This code checks if variable should be treated as read-only variable.
|
||||
|
||||
@param[in] VariableName Name of the Variable.
|
||||
@param[in] VendorGuid GUID of the Variable.
|
||||
|
||||
@retval TRUE This variable is read-only variable.
|
||||
@retval FALSE This variable is NOT read-only variable.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
IsReadOnlyVariable (
|
||||
IN CHAR16 *VariableName,
|
||||
IN EFI_GUID *VendorGuid
|
||||
)
|
||||
{
|
||||
if (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid)) {
|
||||
if ((StrCmp (VariableName, EFI_SETUP_MODE_NAME) == 0) ||
|
||||
(StrCmp (VariableName, EFI_SIGNATURE_SUPPORT_NAME) == 0) ||
|
||||
(StrCmp (VariableName, EFI_SECURE_BOOT_MODE_NAME) == 0) ||
|
||||
(StrCmp (VariableName, EFI_VENDOR_KEYS_VARIABLE_NAME) == 0) ||
|
||||
(StrCmp (VariableName, EFI_KEK_DEFAULT_VARIABLE_NAME) == 0) ||
|
||||
(StrCmp (VariableName, EFI_PK_DEFAULT_VARIABLE_NAME) == 0) ||
|
||||
(StrCmp (VariableName, EFI_DB_DEFAULT_VARIABLE_NAME) == 0) ||
|
||||
(StrCmp (VariableName, EFI_DBX_DEFAULT_VARIABLE_NAME) == 0) ||
|
||||
(StrCmp (VariableName, EFI_DBT_DEFAULT_VARIABLE_NAME) == 0)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
This code finds variable in storage blocks (Volatile or Non-Volatile).
|
||||
|
@ -3015,6 +2880,7 @@ VariableServiceSetVariable (
|
|||
UINTN PayloadSize;
|
||||
LIST_ENTRY *Link;
|
||||
VARIABLE_ENTRY *Entry;
|
||||
CHAR16 *Name;
|
||||
|
||||
//
|
||||
// Check input parameters.
|
||||
|
@ -3023,10 +2889,6 @@ VariableServiceSetVariable (
|
|||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (IsReadOnlyVariable (VariableName, VendorGuid)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
if (DataSize != 0 && Data == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
@ -3105,11 +2967,6 @@ VariableServiceSetVariable (
|
|||
}
|
||||
}
|
||||
|
||||
Status = CheckEfiGlobalVariable (VariableName, VendorGuid, Attributes);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
|
||||
|
||||
//
|
||||
|
@ -3136,7 +2993,8 @@ VariableServiceSetVariable (
|
|||
; Link = GetNextNode (&mLockedVariableList, Link)
|
||||
) {
|
||||
Entry = BASE_CR (Link, VARIABLE_ENTRY, Link);
|
||||
if (CompareGuid (&Entry->Guid, VendorGuid) && (StrCmp (Entry->Name, VariableName) == 0)) {
|
||||
Name = (CHAR16 *) ((UINTN) Entry + sizeof (*Entry));
|
||||
if (CompareGuid (&Entry->Guid, VendorGuid) && (StrCmp (Name, VariableName) == 0)) {
|
||||
Status = EFI_WRITE_PROTECTED;
|
||||
DEBUG ((EFI_D_INFO, "[Variable]: Changing readonly variable after leaving DXE phase - %g:%s\n", VendorGuid, VariableName));
|
||||
goto Done;
|
||||
|
@ -3144,6 +3002,11 @@ VariableServiceSetVariable (
|
|||
}
|
||||
}
|
||||
|
||||
Status = InternalVarCheckSetVariableCheck (VariableName, VendorGuid, Attributes, PayloadSize, (VOID *) ((UINTN) Data + DataSize - PayloadSize));
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
//
|
||||
// Check whether the input variable is already existed.
|
||||
//
|
||||
|
@ -3161,6 +3024,7 @@ VariableServiceSetVariable (
|
|||
// 2. The only attribute differing is EFI_VARIABLE_APPEND_WRITE
|
||||
//
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
DEBUG ((EFI_D_INFO, "[Variable]: Rewritten a preexisting variable with different attributes - %g:%s\n", VendorGuid, VariableName));
|
||||
goto Done;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
The internal header file includes the common header files, defines
|
||||
internal structure and functions used by Variable modules.
|
||||
|
||||
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -22,6 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
#include <Protocol/FirmwareVolumeBlock.h>
|
||||
#include <Protocol/Variable.h>
|
||||
#include <Protocol/VariableLock.h>
|
||||
#include <Protocol/VarCheck.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/HobLib.h>
|
||||
#include <Library/UefiDriverEntryPoint.h>
|
||||
|
@ -52,15 +53,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
|
||||
EFI_VARIABLE_APPEND_WRITE)
|
||||
|
||||
#define VARIABLE_ATTRIBUTE_NV_BS (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS)
|
||||
#define VARIABLE_ATTRIBUTE_BS_RT (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)
|
||||
#define VARIABLE_ATTRIBUTE_NV_BS_RT (VARIABLE_ATTRIBUTE_BS_RT | EFI_VARIABLE_NON_VOLATILE)
|
||||
#define VARIABLE_ATTRIBUTE_NV_BS_RT_AT (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)
|
||||
|
||||
typedef struct {
|
||||
CHAR16 *Name;
|
||||
UINT32 Attributes;
|
||||
} GLOBAL_VARIABLE_ENTRY;
|
||||
|
||||
#define VARIABLE_ATTRIBUTE_NV_BS_RT_HR (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_HARDWARE_ERROR_RECORD)
|
||||
#define VARIABLE_ATTRIBUTE_NV_BS_RT_AW (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
|
||||
|
||||
///
|
||||
/// The size of a 3 character ISO639 language code.
|
||||
///
|
||||
|
@ -115,9 +114,9 @@ typedef struct {
|
|||
} VARIABLE_ENTRY_CONSISTENCY;
|
||||
|
||||
typedef struct {
|
||||
EFI_GUID Guid;
|
||||
CHAR16 *Name;
|
||||
LIST_ENTRY Link;
|
||||
EFI_GUID Guid;
|
||||
//CHAR16 *Name;
|
||||
} VARIABLE_ENTRY;
|
||||
|
||||
/**
|
||||
|
@ -669,6 +668,116 @@ VariableLockRequestToLock (
|
|||
IN EFI_GUID *VendorGuid
|
||||
);
|
||||
|
||||
/**
|
||||
Check if a Unicode character is a hexadecimal character.
|
||||
|
||||
This function checks if a Unicode character is a
|
||||
hexadecimal character. The valid hexadecimal character is
|
||||
L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
|
||||
|
||||
|
||||
@param Char The character to check against.
|
||||
|
||||
@retval TRUE If the Char is a hexadecmial character.
|
||||
@retval FALSE If the Char is not a hexadecmial character.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
IsHexaDecimalDigitCharacter (
|
||||
IN CHAR16 Char
|
||||
);
|
||||
|
||||
/**
|
||||
Internal SetVariable check.
|
||||
|
||||
@param[in] VariableName Name of Variable to set.
|
||||
@param[in] VendorGuid Variable vendor GUID.
|
||||
@param[in] Attributes Attribute value of the variable.
|
||||
@param[in] DataSize Size of Data to set.
|
||||
@param[in] Data Data pointer.
|
||||
|
||||
@retval EFI_SUCCESS The SetVariable check result was success.
|
||||
@retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID were supplied,
|
||||
or the DataSize exceeds the minimum or maximum allowed,
|
||||
or the Data value is not following UEFI spec for UEFI defined variables.
|
||||
@retval EFI_WRITE_PROTECTED The variable in question is read-only.
|
||||
@retval Others The return status from check handler.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InternalVarCheckSetVariableCheck (
|
||||
IN CHAR16 *VariableName,
|
||||
IN EFI_GUID *VendorGuid,
|
||||
IN UINT32 Attributes,
|
||||
IN UINTN DataSize,
|
||||
IN VOID *Data
|
||||
);
|
||||
|
||||
/**
|
||||
Register SetVariable check handler.
|
||||
|
||||
@param[in] Handler Pointer to check handler.
|
||||
|
||||
@retval EFI_SUCCESS The SetVariable check handler was registered successfully.
|
||||
@retval EFI_INVALID_PARAMETER Handler is NULL.
|
||||
@retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has
|
||||
already been signaled.
|
||||
@retval EFI_OUT_OF_RESOURCES There is not enough resource for the SetVariable check handler register request.
|
||||
@retval EFI_UNSUPPORTED This interface is not implemented.
|
||||
For example, it is unsupported in VarCheck protocol if both VarCheck and SmmVarCheck protocols are present.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
VarCheckRegisterSetVariableCheckHandler (
|
||||
IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler
|
||||
);
|
||||
|
||||
/**
|
||||
Variable property set.
|
||||
|
||||
@param[in] Name Pointer to the variable name.
|
||||
@param[in] Guid Pointer to the vendor GUID.
|
||||
@param[in] VariableProperty Pointer to the input variable property.
|
||||
|
||||
@retval EFI_SUCCESS The property of variable specified by the Name and Guid was set successfully.
|
||||
@retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string,
|
||||
or the fields of VariableProperty are not valid.
|
||||
@retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has
|
||||
already been signaled.
|
||||
@retval EFI_OUT_OF_RESOURCES There is not enough resource for the variable property set request.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
VarCheckVariablePropertySet (
|
||||
IN CHAR16 *Name,
|
||||
IN EFI_GUID *Guid,
|
||||
IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
|
||||
);
|
||||
|
||||
/**
|
||||
Variable property get.
|
||||
|
||||
@param[in] Name Pointer to the variable name.
|
||||
@param[in] Guid Pointer to the vendor GUID.
|
||||
@param[out] VariableProperty Pointer to the output variable property.
|
||||
|
||||
@retval EFI_SUCCESS The property of variable specified by the Name and Guid was got successfully.
|
||||
@retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string.
|
||||
@retval EFI_NOT_FOUND The property of variable specified by the Name and Guid was not found.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
VarCheckVariablePropertyGet (
|
||||
IN CHAR16 *Name,
|
||||
IN EFI_GUID *Guid,
|
||||
OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
|
||||
);
|
||||
|
||||
extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
and volatile storage space and install variable architecture protocol.
|
||||
|
||||
Copyright (C) 2013, Red Hat, Inc.
|
||||
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -23,8 +23,14 @@ EFI_HANDLE mHandle = NULL;
|
|||
EFI_EVENT mVirtualAddressChangeEvent = NULL;
|
||||
EFI_EVENT mFtwRegistration = NULL;
|
||||
extern LIST_ENTRY mLockedVariableList;
|
||||
extern LIST_ENTRY mVarCheckVariableList;
|
||||
extern UINT32 mNumberOfHandler;
|
||||
extern VAR_CHECK_SET_VARIABLE_CHECK_HANDLER *mHandlerTable;
|
||||
extern BOOLEAN mEndOfDxe;
|
||||
EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock = { VariableLockRequestToLock };
|
||||
EDKII_VAR_CHECK_PROTOCOL mVarCheck = { VarCheckRegisterSetVariableCheckHandler,
|
||||
VarCheckVariablePropertySet,
|
||||
VarCheckVariablePropertyGet };
|
||||
|
||||
/**
|
||||
Return TRUE if ExitBootServices () has been called.
|
||||
|
@ -222,9 +228,8 @@ VariableClassAddressChangeEvent (
|
|||
IN VOID *Context
|
||||
)
|
||||
{
|
||||
LIST_ENTRY *Link;
|
||||
VARIABLE_ENTRY *Entry;
|
||||
EFI_STATUS Status;
|
||||
UINTN Index;
|
||||
|
||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetBlockSize);
|
||||
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);
|
||||
|
@ -239,29 +244,23 @@ VariableClassAddressChangeEvent (
|
|||
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 **) &mHashCtx);
|
||||
EfiConvertPointer (0x0, (VOID **) &mSerializationRuntimeBuffer);
|
||||
EfiConvertPointer (0x0, (VOID **) &mNvVariableCache);
|
||||
EfiConvertPointer (0x0, (VOID **) &mPubKeyStore);
|
||||
EfiConvertPointer (0x0, (VOID **) &mCertDbStore);
|
||||
|
||||
//
|
||||
// in the list of locked variables, convert the name pointers first
|
||||
//
|
||||
for ( Link = GetFirstNode (&mLockedVariableList)
|
||||
; !IsNull (&mLockedVariableList, Link)
|
||||
; Link = GetNextNode (&mLockedVariableList, Link)
|
||||
) {
|
||||
Entry = BASE_CR (Link, VARIABLE_ENTRY, Link);
|
||||
Status = EfiConvertPointer (0x0, (VOID **) &Entry->Name);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
EfiConvertPointer (0x0, (VOID **) &mHandlerTable);
|
||||
for (Index = 0; Index < mNumberOfHandler; Index++) {
|
||||
EfiConvertPointer (0x0, (VOID **) &mHandlerTable[Index]);
|
||||
}
|
||||
//
|
||||
// second, convert the list itself using UefiRuntimeLib
|
||||
//
|
||||
|
||||
Status = EfiConvertList (0x0, &mLockedVariableList);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = EfiConvertList (0x0, &mVarCheckVariableList);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
|
||||
|
||||
|
@ -447,6 +446,14 @@ VariableServiceInitialize (
|
|||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&mHandle,
|
||||
&gEdkiiVarCheckProtocolGuid,
|
||||
&mVarCheck,
|
||||
NULL
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
SystemTable->RuntimeServices->GetVariable = VariableServiceGetVariable;
|
||||
SystemTable->RuntimeServices->GetNextVariableName = VariableServiceGetNextVariableName;
|
||||
SystemTable->RuntimeServices->SetVariable = VariableServiceSetVariable;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
# This external input must be validated carefully to avoid security issues such as
|
||||
# buffer overflow or integer overflow.
|
||||
#
|
||||
# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -44,6 +44,7 @@
|
|||
AuthService.c
|
||||
AuthService.h
|
||||
Measurement.c
|
||||
VarCheck.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
|
@ -67,6 +68,7 @@
|
|||
PlatformSecureLib
|
||||
HobLib
|
||||
TpmMeasurementLib
|
||||
DevicePathLib
|
||||
|
||||
[Protocols]
|
||||
gEfiFirmwareVolumeBlockProtocolGuid ## CONSUMES
|
||||
|
@ -76,6 +78,7 @@
|
|||
gEfiVariableWriteArchProtocolGuid ## PRODUCES
|
||||
gEfiVariableArchProtocolGuid ## PRODUCES
|
||||
gEdkiiVariableLockProtocolGuid ## PRODUCES
|
||||
gEdkiiVarCheckProtocolGuid ## PRODUCES
|
||||
|
||||
|
||||
[Guids]
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
VariableServiceSetVariable(), VariableServiceQueryVariableInfo(), ReclaimForOS(),
|
||||
SmmVariableGetStatistics() should also do validation based on its own knowledge.
|
||||
|
||||
Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -30,6 +30,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
#include <Protocol/SmmFaultTolerantWrite.h>
|
||||
#include <Protocol/SmmAccess2.h>
|
||||
#include <Protocol/SmmEndOfDxe.h>
|
||||
#include <Protocol/SmmVarCheck.h>
|
||||
|
||||
#include <Library/SmmServicesTableLib.h>
|
||||
|
||||
|
@ -119,6 +120,10 @@ EFI_SMM_VARIABLE_PROTOCOL gSmmVariable = {
|
|||
VariableServiceQueryVariableInfo
|
||||
};
|
||||
|
||||
EDKII_SMM_VAR_CHECK_PROTOCOL mSmmVarCheck = { VarCheckRegisterSetVariableCheckHandler,
|
||||
VarCheckVariablePropertySet,
|
||||
VarCheckVariablePropertyGet };
|
||||
|
||||
/**
|
||||
Return TRUE if ExitBootServices () has been called.
|
||||
|
||||
|
@ -520,6 +525,7 @@ SmmVariableHandler (
|
|||
SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *QueryVariableInfo;
|
||||
VARIABLE_INFO_ENTRY *VariableInfo;
|
||||
SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *VariableToLock;
|
||||
SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *CommVariableProperty;
|
||||
UINTN InfoSize;
|
||||
UINTN NameBufferSize;
|
||||
UINTN CommBufferPayloadSize;
|
||||
|
@ -754,6 +760,61 @@ SmmVariableHandler (
|
|||
);
|
||||
}
|
||||
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
|
||||
);
|
||||
}
|
||||
break;
|
||||
case SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET:
|
||||
if (CommBufferPayloadSize < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {
|
||||
DEBUG ((EFI_D_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)) {
|
||||
//
|
||||
// Prevent InfoSize overflow happen
|
||||
//
|
||||
Status = EFI_ACCESS_DENIED;
|
||||
goto EXIT;
|
||||
}
|
||||
InfoSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) + CommVariableProperty->NameSize;
|
||||
|
||||
//
|
||||
// SMRAM range check already covered before
|
||||
//
|
||||
if (InfoSize > CommBufferPayloadSize) {
|
||||
DEBUG ((EFI_D_ERROR, "VarCheckVariablePropertyGet: Data size exceed communication buffer size limit!\n"));
|
||||
Status = EFI_ACCESS_DENIED;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
if (CommVariableProperty->NameSize < sizeof (CHAR16) || CommVariableProperty->Name[CommVariableProperty->NameSize/sizeof (CHAR16) - 1] != L'\0') {
|
||||
//
|
||||
// Make sure VariableName is A Null-terminated string.
|
||||
//
|
||||
Status = EFI_ACCESS_DENIED;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
Status = VarCheckVariablePropertyGet (
|
||||
CommVariableProperty->Name,
|
||||
&CommVariableProperty->Guid,
|
||||
&CommVariableProperty->VariableProperty
|
||||
);
|
||||
CopyMem (SmmVariableFunctionHeader->Data, mVariableBufferPayload, CommBufferPayloadSize);
|
||||
break;
|
||||
|
||||
default:
|
||||
Status = EFI_UNSUPPORTED;
|
||||
|
@ -911,6 +972,14 @@ VariableServiceInitialize (
|
|||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = gSmst->SmmInstallProtocolInterface (
|
||||
&VariableHandle,
|
||||
&gEdkiiSmmVarCheckProtocolGuid,
|
||||
EFI_NATIVE_INTERFACE,
|
||||
&mSmmVarCheck
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
//
|
||||
// Get SMRAM information
|
||||
//
|
||||
|
@ -934,7 +1003,7 @@ VariableServiceInitialize (
|
|||
mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);
|
||||
|
||||
mVariableBufferPayloadSize = MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxHardwareErrorVariableSize)) +
|
||||
OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) - sizeof (VARIABLE_HEADER);
|
||||
OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - sizeof (VARIABLE_HEADER);
|
||||
|
||||
Status = gSmst->SmmAllocatePool (
|
||||
EfiRuntimeServicesData,
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# may not be modified without authorization. If platform fails to protect these resources,
|
||||
# the authentication service provided in this driver will be broken, and the behavior is undefined.
|
||||
#
|
||||
# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -50,6 +50,7 @@
|
|||
Variable.c
|
||||
VariableSmm.c
|
||||
AuthService.c
|
||||
VarCheck.c
|
||||
Variable.h
|
||||
AuthService.h
|
||||
|
||||
|
@ -72,6 +73,8 @@
|
|||
BaseCryptLib
|
||||
PlatformSecureLib
|
||||
HobLib
|
||||
PcdLib
|
||||
DevicePathLib
|
||||
|
||||
[Protocols]
|
||||
gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES
|
||||
|
@ -84,7 +87,8 @@
|
|||
## CONSUMES
|
||||
## NOTIFY
|
||||
gEfiSmmFaultTolerantWriteProtocolGuid
|
||||
gEfiSmmEndOfDxeProtocolGuid ## NOTIFY
|
||||
gEfiSmmEndOfDxeProtocolGuid ## NOTIFY
|
||||
gEdkiiSmmVarCheckProtocolGuid ## PRODUCES
|
||||
|
||||
[Guids]
|
||||
## PRODUCES ## GUID # Variable store header
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
InitCommunicateBuffer() is really function to check the variable data size.
|
||||
|
||||
Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -30,6 +30,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
#include <Protocol/SmmCommunication.h>
|
||||
#include <Protocol/SmmVariable.h>
|
||||
#include <Protocol/VariableLock.h>
|
||||
#include <Protocol/VarCheck.h>
|
||||
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
|
@ -56,6 +57,7 @@ UINTN mVariableBufferSize;
|
|||
UINTN mVariableBufferPayloadSize;
|
||||
EFI_LOCK mVariableServicesLock;
|
||||
EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock;
|
||||
EDKII_VAR_CHECK_PROTOCOL mVarCheck;
|
||||
|
||||
/**
|
||||
SecureBoot Hook for SetVariable.
|
||||
|
@ -258,6 +260,180 @@ Done:
|
|||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
Register SetVariable check handler.
|
||||
|
||||
@param[in] Handler Pointer to check handler.
|
||||
|
||||
@retval EFI_SUCCESS The SetVariable check handler was registered successfully.
|
||||
@retval EFI_INVALID_PARAMETER Handler is NULL.
|
||||
@retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has
|
||||
already been signaled.
|
||||
@retval EFI_OUT_OF_RESOURCES There is not enough resource for the SetVariable check handler register request.
|
||||
@retval EFI_UNSUPPORTED This interface is not implemented.
|
||||
For example, it is unsupported in VarCheck protocol if both VarCheck and SmmVarCheck protocols are present.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
VarCheckRegisterSetVariableCheckHandler (
|
||||
IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler
|
||||
)
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Variable property set.
|
||||
|
||||
@param[in] Name Pointer to the variable name.
|
||||
@param[in] Guid Pointer to the vendor GUID.
|
||||
@param[in] VariableProperty Pointer to the input variable property.
|
||||
|
||||
@retval EFI_SUCCESS The property of variable specified by the Name and Guid was set successfully.
|
||||
@retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string,
|
||||
or the fields of VariableProperty are not valid.
|
||||
@retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has
|
||||
already been signaled.
|
||||
@retval EFI_OUT_OF_RESOURCES There is not enough resource for the variable property set request.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
VarCheckVariablePropertySet (
|
||||
IN CHAR16 *Name,
|
||||
IN EFI_GUID *Guid,
|
||||
IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN VariableNameSize;
|
||||
UINTN PayloadSize;
|
||||
SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *CommVariableProperty;
|
||||
|
||||
if (Name == NULL || Name[0] == 0 || Guid == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (VariableProperty == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (VariableProperty->Revision != VAR_CHECK_VARIABLE_PROPERTY_REVISION) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
VariableNameSize = StrSize (Name);
|
||||
CommVariableProperty = NULL;
|
||||
|
||||
//
|
||||
// If VariableName exceeds SMM payload limit. Return failure
|
||||
//
|
||||
if (VariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
AcquireLockOnlyAtBootTime (&mVariableServicesLock);
|
||||
|
||||
//
|
||||
// Init the communicate buffer. The buffer data size is:
|
||||
// SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.
|
||||
//
|
||||
PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) + VariableNameSize;
|
||||
Status = InitCommunicateBuffer ((VOID **) &CommVariableProperty, PayloadSize, SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
ASSERT (CommVariableProperty != NULL);
|
||||
|
||||
CopyGuid (&CommVariableProperty->Guid, Guid);
|
||||
CopyMem (&CommVariableProperty->VariableProperty, VariableProperty, sizeof (*VariableProperty));
|
||||
CommVariableProperty->NameSize = VariableNameSize;
|
||||
CopyMem (CommVariableProperty->Name, Name, CommVariableProperty->NameSize);
|
||||
|
||||
//
|
||||
// Send data to SMM.
|
||||
//
|
||||
Status = SendCommunicateBuffer (PayloadSize);
|
||||
|
||||
Done:
|
||||
ReleaseLockOnlyAtBootTime (&mVariableServicesLock);
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
Variable property get.
|
||||
|
||||
@param[in] Name Pointer to the variable name.
|
||||
@param[in] Guid Pointer to the vendor GUID.
|
||||
@param[out] VariableProperty Pointer to the output variable property.
|
||||
|
||||
@retval EFI_SUCCESS The property of variable specified by the Name and Guid was got successfully.
|
||||
@retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string.
|
||||
@retval EFI_NOT_FOUND The property of variable specified by the Name and Guid was not found.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
VarCheckVariablePropertyGet (
|
||||
IN CHAR16 *Name,
|
||||
IN EFI_GUID *Guid,
|
||||
OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN VariableNameSize;
|
||||
UINTN PayloadSize;
|
||||
SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *CommVariableProperty;
|
||||
|
||||
if (Name == NULL || Name[0] == 0 || Guid == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (VariableProperty == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
VariableNameSize = StrSize (Name);
|
||||
CommVariableProperty = NULL;
|
||||
|
||||
//
|
||||
// If VariableName exceeds SMM payload limit. Return failure
|
||||
//
|
||||
if (VariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
AcquireLockOnlyAtBootTime (&mVariableServicesLock);
|
||||
|
||||
//
|
||||
// Init the communicate buffer. The buffer data size is:
|
||||
// SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.
|
||||
//
|
||||
PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) + VariableNameSize;
|
||||
Status = InitCommunicateBuffer ((VOID **) &CommVariableProperty, PayloadSize, SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
ASSERT (CommVariableProperty != NULL);
|
||||
|
||||
CopyGuid (&CommVariableProperty->Guid, Guid);
|
||||
CommVariableProperty->NameSize = VariableNameSize;
|
||||
CopyMem (CommVariableProperty->Name, Name, CommVariableProperty->NameSize);
|
||||
|
||||
//
|
||||
// Send data to SMM.
|
||||
//
|
||||
Status = SendCommunicateBuffer (PayloadSize);
|
||||
if (Status == EFI_SUCCESS) {
|
||||
CopyMem (VariableProperty, &CommVariableProperty->VariableProperty, sizeof (*VariableProperty));
|
||||
}
|
||||
|
||||
Done:
|
||||
ReleaseLockOnlyAtBootTime (&mVariableServicesLock);
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
This code finds variable in storage blocks (Volatile or Non-Volatile).
|
||||
|
||||
|
@ -756,7 +932,7 @@ SmmVariableReady (
|
|||
// Allocate memory for variable communicate buffer.
|
||||
//
|
||||
mVariableBufferPayloadSize = MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxHardwareErrorVariableSize)) +
|
||||
OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) - sizeof (VARIABLE_HEADER);
|
||||
OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - sizeof (VARIABLE_HEADER);
|
||||
mVariableBufferSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + mVariableBufferPayloadSize;
|
||||
mVariableBuffer = AllocateRuntimePool (mVariableBufferSize);
|
||||
ASSERT (mVariableBuffer != NULL);
|
||||
|
@ -855,6 +1031,17 @@ VariableSmmRuntimeInitialize (
|
|||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
mVarCheck.RegisterSetVariableCheckHandler = VarCheckRegisterSetVariableCheckHandler;
|
||||
mVarCheck.VariablePropertySet = VarCheckVariablePropertySet;
|
||||
mVarCheck.VariablePropertyGet = VarCheckVariablePropertyGet;
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&mHandle,
|
||||
&gEdkiiVarCheckProtocolGuid,
|
||||
&mVarCheck,
|
||||
NULL
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
//
|
||||
// Smm variable service is ready
|
||||
//
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# may not be modified without authorization. If platform fails to protect these resources,
|
||||
# the authentication service provided in this driver will be broken, and the behavior is undefined.
|
||||
#
|
||||
# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -70,6 +70,7 @@
|
|||
## NOTIFY
|
||||
## UNDEFINED # Used to do smm communication
|
||||
gEfiSmmVariableProtocolGuid
|
||||
gEdkiiVarCheckProtocolGuid ## PRODUCES
|
||||
|
||||
[Guids]
|
||||
gEfiEventVirtualAddressChangeGuid ## CONSUMES ## Event
|
||||
|
@ -92,7 +93,6 @@
|
|||
[Pcd]
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize ## CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## CONSUMES
|
||||
|
||||
[Depex]
|
||||
gEfiSmmCommunicationProtocolGuid
|
||||
|
|
Loading…
Reference in New Issue