X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=SecurityPkg%2FVariableAuthenticated%2FRuntimeDxe%2FVariable.h;h=8e292f36b21968ef24aad63ad255c281d6502e78;hb=23b06935797ef44b4e68ad1f07eee5d3019e0269;hp=91c7b4aac0142dbc982b35a6cfe42bb18ba0c536;hpb=9a000b464fe3c03489a68a60dc5f1f9abbe92a12;p=mirror_edk2.git diff --git a/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h b/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h index 91c7b4aac0..8e292f36b2 100644 --- a/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h +++ b/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h @@ -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 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.
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 @@ -39,8 +39,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include +#include #define VARIABLE_RECLAIM_THRESHOLD (1024) +#define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE | \ + EFI_VARIABLE_BOOTSERVICE_ACCESS | \ + EFI_VARIABLE_RUNTIME_ACCESS | \ + EFI_VARIABLE_HARDWARE_ERROR_RECORD | \ + EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \ + EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \ + EFI_VARIABLE_APPEND_WRITE) /// /// The size of a 3 character ISO639 language code. @@ -56,6 +65,13 @@ typedef enum { typedef struct { 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; @@ -90,6 +106,19 @@ typedef struct { VOID *Data; } VARIABLE_CACHE_ENTRY; +/** + Flush the HOB variable to flash. + + @param[in] VariableName Name of variable has been updated or deleted. + @param[in] VendorGuid Guid of variable has been updated or deleted. + +**/ +VOID +FlushHobVariableToFlash ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid + ); + /** Writes a buffer to variable storage space, in the working block. @@ -119,20 +148,24 @@ FtwVariableSpace ( This code finds variable in storage blocks of volatile and non-volatile storage areas. If VariableName is an empty string, then we just return the first qualified variable without comparing VariableName and VendorGuid. - Otherwise, VariableName and VendorGuid are compared. + If IgnoreRtCheck is TRUE, then we ignore the EFI_VARIABLE_RUNTIME_ACCESS attribute check + at runtime when searching existing variable, only VariableName and VendorGuid are compared. + Otherwise, variables without EFI_VARIABLE_RUNTIME_ACCESS are not visible at runtime. - @param VariableName Name of the variable to be found. - @param VendorGuid Vendor GUID to be found. - @param PtrTrack VARIABLE_POINTER_TRACK structure for output, + @param[in] VariableName Name of the variable to be found. + @param[in] VendorGuid Vendor GUID to be found. + @param[out] PtrTrack VARIABLE_POINTER_TRACK structure for output, including the range searched and the target position. - @param Global Pointer to VARIABLE_GLOBAL structure, including + @param[in] Global Pointer to VARIABLE_GLOBAL structure, including base of volatile variable storage area, base of NV variable storage area, and a lock. + @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS attribute + check at runtime when searching variable. @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while VendorGuid is NULL. @retval EFI_SUCCESS Variable successfully found. - @retval EFI_INVALID_PARAMETER Variable not found. + @retval EFI_NOT_FOUND Variable not found **/ EFI_STATUS @@ -140,7 +173,8 @@ FindVariable ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack, - IN VARIABLE_GLOBAL *Global + IN VARIABLE_GLOBAL *Global, + IN BOOLEAN IgnoreRtCheck ); /** @@ -182,7 +216,7 @@ DataSizeOfVariable ( @param[in] Attributes Attributes of the variable. @param[in] KeyIndex Index of associated public key. @param[in] MonotonicCount Value of associated monotonic count. - @param[in] Variable The variable information that is used to keep track of variable usage. + @param[in, out] Variable The variable information that is used to keep track of variable usage. @param[in] TimeStamp Value of associated TimeStamp. @@ -199,7 +233,7 @@ UpdateVariable ( IN UINT32 Attributes OPTIONAL, IN UINT32 KeyIndex OPTIONAL, IN UINT64 MonotonicCount OPTIONAL, - IN VARIABLE_POINTER_TRACK *Variable, + IN OUT VARIABLE_POINTER_TRACK *Variable, IN EFI_TIME *TimeStamp OPTIONAL ); @@ -339,6 +373,37 @@ VariableCommonInitialize ( VOID ); +/** + + Variable store garbage collection and reclaim operation. + + If ReclaimPubKeyStore is FALSE, reclaim variable space by deleting the obsoleted varaibles. + If ReclaimPubKeyStore is TRUE, reclaim invalid key in public key database and update the PubKeyIndex + for all the count-based authenticate variable in NV storage. + + @param[in] VariableBase Base address of variable store. + @param[out] LastVariableOffset Offset of last variable. + @param[in] IsVolatile The variable store is volatile or not; + if it is non-volatile, need FTW. + @param[in, out] UpdatingPtrTrack Pointer to updating variable pointer track structure. + @param[in] ReclaimPubKeyStore Reclaim for public key database or not. + @param[in] ReclaimAnyway If TRUE, do reclaim anyway. + + @return EFI_OUT_OF_RESOURCES No enough memory resources. + @return EFI_SUCCESS Reclaim operation has finished successfully. + @return Others Unexpect error happened during reclaim operation. + +**/ +EFI_STATUS +Reclaim ( + IN EFI_PHYSICAL_ADDRESS VariableBase, + OUT UINTN *LastVariableOffset, + IN BOOLEAN IsVolatile, + IN OUT VARIABLE_POINTER_TRACK *UpdatingPtrTrack, + IN BOOLEAN ReclaimPubKeyStore, + IN BOOLEAN ReclaimAnyway + ); + /** This function reclaims variable storage if free size is below the threshold. @@ -395,6 +460,10 @@ GetFvbInfoByAddress ( This code finds variable in storage blocks (Volatile or Non-Volatile). + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode, and datasize and data are external input. + This function will do basic validation, before parse the data. + @param VariableName Name of Variable to be found. @param VendorGuid Variable vendor GUID. @param Attributes Attribute value of the variable found. @@ -422,6 +491,9 @@ VariableServiceGetVariable ( This code Finds the Next available variable. + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode. This function will do basic validation, before parse the data. + @param VariableNameSize Size of the variable name. @param VariableName Pointer to variable name. @param VendorGuid Variable Vendor Guid. @@ -444,6 +516,13 @@ VariableServiceGetNextVariableName ( This code sets variable in storage blocks (Volatile or Non-Volatile). + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode, and datasize and data are external input. + This function will do basic validation, before parse the data. + This function will parse the authentication carefully to avoid security issues, like + buffer overflow, integer overflow. + This function will check attribute carefully to avoid authentication bypass. + @param VariableName Name of Variable to be found. @param VendorGuid Variable vendor GUID. @param Attributes Attribute value of the variable found @@ -472,6 +551,9 @@ VariableServiceSetVariable ( This code returns information about the EFI variables. + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode. This function will do basic validation, before parse the data. + @param Attributes Attributes bitmask to specify the type of variables on which to return information. @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available