TianoCore EDK2 master
|
#include <Protocol/SmmVariable.h>
#include <Protocol/SmmFirmwareVolumeBlock.h>
#include <Protocol/SmmFaultTolerantWrite.h>
#include <Protocol/MmEndOfDxe.h>
#include <Protocol/SmmVarCheck.h>
#include <Library/MmServicesTableLib.h>
#include <Library/VariablePolicyLib.h>
#include <Guid/SmmVariableCommon.h>
#include "Variable.h"
#include "VariableParsing.h"
#include "VariableRuntimeCache.h"
Go to the source code of this file.
The sample implementation for SMM variable protocol. And this driver implements an SMI handler to communicate with the DXE runtime driver to provide variable services.
Caution: This module requires additional review when modified. This driver will have external input - variable data and communicate buffer in SMM mode. This external input must be validated carefully to avoid security issue like buffer overflow, integer overflow.
SmmVariableHandler() will receive untrusted input and do basic validation.
Each sub function VariableServiceGetVariable(), VariableServiceGetNextVariableName(), VariableServiceSetVariable(), VariableServiceQueryVariableInfo(), ReclaimForOS(), SmmVariableGetStatistics() should also do validation based on its own knowledge.
Copyright (c) 2010 - 2024, Intel Corporation. All rights reserved.
Copyright (c) 2018, Linaro, Ltd. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file VariableSmm.c.
Acquires lock only at boot time. Simply returns at runtime.
This is a temperary function that will be removed when EfiAcquireLock() in UefiLib can handle the call in UEFI Runtimer driver in RT phase. It calls EfiAcquireLock() at boot time, and simply returns at runtime.
Lock | A pointer to the lock to acquire. |
Definition at line 169 of file VariableSmm.c.
BOOLEAN AtRuntime | ( | VOID | ) |
Return TRUE if ExitBootServices () has been called.
TRUE | If ExitBootServices () has been called. |
Definition at line 124 of file VariableSmm.c.
EFI_STATUS GetFtwProtocol | ( | OUT VOID ** | FtwProtocol | ) |
Retrieve the SMM Fault Tolerent Write protocol interface.
[out] | FtwProtocol | The interface of SMM Ftw protocol |
EFI_SUCCESS | The SMM FTW protocol instance was found and returned in FtwProtocol. |
EFI_NOT_FOUND | The SMM FTW protocol instance was not found. |
EFI_INVALID_PARAMETER | SarProtocol is NULL. |
Definition at line 205 of file VariableSmm.c.
EFI_STATUS GetFvbByHandle | ( | IN EFI_HANDLE | FvBlockHandle, |
OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL ** | FvBlock | ||
) |
Retrieve the SMM FVB protocol interface by HANDLE.
[in] | FvBlockHandle | The handle of SMM FVB protocol that provides services for reading, writing, and erasing the target block. |
[out] | FvBlock | The interface of SMM FVB protocol |
EFI_SUCCESS | The interface information for the specified protocol was returned. |
EFI_UNSUPPORTED | The device does not support the SMM FVB protocol. |
EFI_INVALID_PARAMETER | FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL. |
Definition at line 235 of file VariableSmm.c.
EFI_STATUS GetFvbCountAndBuffer | ( | OUT UINTN * | NumberHandles, |
OUT EFI_HANDLE ** | Buffer | ||
) |
Function returns an array of handles that support the SMM FVB protocol in a buffer allocated from pool.
[out] | NumberHandles | The number of handles returned in Buffer. |
[out] | Buffer | A pointer to the buffer to return the requested array of handles that support SMM FVB protocol. |
EFI_SUCCESS | The array of handles was returned in Buffer, and the number of handles in Buffer was returned in NumberHandles. |
EFI_NOT_FOUND | No SMM FVB handle was found. |
EFI_OUT_OF_RESOURCES | There is not enough pool memory to store the matching results. |
EFI_INVALID_PARAMETER | NumberHandles is NULL or Buffer is NULL. |
Definition at line 266 of file VariableSmm.c.
Initializes a basic mutual exclusion lock.
This function initializes a basic mutual exclusion lock to the released state and returns the lock. Each lock provides mutual exclusion access at its task priority level. Since there is no preemption or multiprocessor support in EFI, acquiring the lock only consists of raising to the locks TPL. If Lock is NULL, then ASSERT(). If Priority is not a valid TPL value, then ASSERT().
Lock | A pointer to the lock data structure to initialize. |
Priority | EFI TPL is associated with the lock. |
Definition at line 148 of file VariableSmm.c.
EFI_STATUS EFIAPI MmVariableServiceInitialize | ( | VOID | ) |
Variable Driver main entry point. The Variable driver places the 4 EFI runtime services in the EFI System Table and installs arch protocols for variable read and write services being available. It also registers a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
EFI_SUCCESS | Variable service successfully initialized. |
Register SMM variable SMI handler
Definition at line 1151 of file VariableSmm.c.
Releases lock only at boot time. Simply returns at runtime.
This is a temperary function which will be removed when EfiReleaseLock() in UefiLib can handle the call in UEFI Runtimer driver in RT phase. It calls EfiReleaseLock() at boot time and simply returns at runtime.
Lock | A pointer to the lock to release. |
Definition at line 188 of file VariableSmm.c.
SecureBoot Hook for SetVariable.
[in] | VariableName | Name of Variable to be found. |
[in] | VendorGuid | Variable vendor GUID. |
Definition at line 52 of file VariableSmm.c.
EFI_STATUS EFIAPI SmmEndOfDxeCallback | ( | IN CONST EFI_GUID * | Protocol, |
IN VOID * | Interface, | ||
IN EFI_HANDLE | Handle | ||
) |
SMM END_OF_DXE protocol notification event handler.
Protocol | Points to the protocol's unique identifier |
Interface | Points to the interface instance |
Handle | The handle on which the interface was installed |
EFI_SUCCESS | SmmEndOfDxeCallback runs successfully |
Definition at line 1012 of file VariableSmm.c.
EFI_STATUS EFIAPI SmmFtwNotificationEvent | ( | IN CONST EFI_GUID * | Protocol, |
IN VOID * | Interface, | ||
IN EFI_HANDLE | Handle | ||
) |
SMM Fault Tolerant Write protocol notification event handler.
Non-Volatile variable write may needs FTW protocol to reclaim when writting variable.
Protocol | Points to the protocol's unique identifier |
Interface | Points to the interface instance |
Handle | The handle on which the interface was installed |
EFI_SUCCESS | SmmEventCallback runs successfully |
EFI_NOT_FOUND | The Fvb protocol for variable is not found. |
Definition at line 1075 of file VariableSmm.c.
EFI_STATUS SmmVariableGetStatistics | ( | IN OUT VARIABLE_INFO_ENTRY * | InfoEntry, |
IN OUT UINTN * | InfoSize | ||
) |
Get the variable statistics information from the information buffer pointed by gVariableInfo.
Caution: This function may be invoked at SMM runtime. InfoEntry and InfoSize are external input. Care must be taken to make sure not security issue at runtime.
[in,out] | InfoEntry | A pointer to the buffer of variable information entry. On input, point to the variable information returned last time. if InfoEntry->VendorGuid is zero, return the first information. On output, point to the next variable information. |
[in,out] | InfoSize | On input, the size of the variable information buffer. On output, the returned variable information size. |
EFI_SUCCESS | The variable information is found and returned successfully. |
EFI_UNSUPPORTED | No variable inoformation exists in variable driver. The PcdVariableCollectStatistics should be set TRUE to support it. |
EFI_BUFFER_TOO_SMALL | The buffer is too small to hold the next variable information. |
EFI_INVALID_PARAMETER | Input parameter is invalid. |
Definition at line 336 of file VariableSmm.c.
EFI_STATUS EFIAPI SmmVariableHandler | ( | IN EFI_HANDLE | DispatchHandle, |
IN CONST VOID * | RegisterContext, | ||
IN OUT VOID * | CommBuffer, | ||
IN OUT UINTN * | CommBufferSize | ||
) |
Communication service SMI Handler entry.
This SMI handler provides services for the variable wrapper driver.
Caution: This function may receive untrusted input. This variable data and communicate buffer are external input, so this function will do basic validation. Each sub function VariableServiceGetVariable(), VariableServiceGetNextVariableName(), VariableServiceSetVariable(), VariableServiceQueryVariableInfo(), ReclaimForOS(), SmmVariableGetStatistics() should also do validation based on its own knowledge.
[in] | DispatchHandle | The unique handle assigned to this handler by SmiHandlerRegister(). |
[in] | RegisterContext | Points to an optional handler context which was specified when the handler was registered. |
[in,out] | CommBuffer | A pointer to a collection of data in memory that will be conveyed from a non-SMM environment into an SMM environment. |
[in,out] | CommBufferSize | The size of the CommBuffer. |
EFI_SUCCESS | The interrupt was handled and quiesced. No other handlers should still be called. |
EFI_WARN_INTERRUPT_SOURCE_QUIESCED | The interrupt has been quiesced but other handlers should still be called. |
EFI_WARN_INTERRUPT_SOURCE_PENDING | The interrupt is still pending and other handlers should still be called. |
EFI_INTERRUPT_PENDING | The interrupt could not be quiesced. |
Definition at line 455 of file VariableSmm.c.
EFI_STATUS EFIAPI SmmVariableSetVariable | ( | IN CHAR16 * | VariableName, |
IN EFI_GUID * | VendorGuid, | ||
IN UINT32 | Attributes, | ||
IN UINTN | DataSize, | ||
IN VOID * | Data | ||
) |
This code sets variable in storage blocks (Volatile or Non-Volatile).
VariableName | Name of Variable to be found. |
VendorGuid | Variable vendor GUID. |
Attributes | Attribute value of the variable found |
DataSize | Size of Data found. If size is less than the data, this value contains the required size. |
Data | Data pointer. |
Definition at line 80 of file VariableSmm.c.
VOID VariableWriteServiceInitializeSmm | ( | VOID | ) |
Initializes variable write service for SMM.
Definition at line 1042 of file VariableSmm.c.
EFI_SMM_VARIABLE_PROTOCOL gSmmVariable |
Definition at line 105 of file VariableSmm.c.
BOOLEAN mAtRuntime = FALSE |
Definition at line 39 of file VariableSmm.c.
|
extern |
Define a memory cache that improves the search performance for a variable. For EmuNvMode == TRUE, it will be equal to NonVolatileVariableBase.
Definition at line 39 of file Variable.c.
EDKII_SMM_VAR_CHECK_PROTOCOL mSmmVarCheck |
Definition at line 112 of file VariableSmm.c.
UINT8* mVariableBufferPayload = NULL |
Definition at line 40 of file VariableSmm.c.
UINTN mVariableBufferPayloadSize |
Definition at line 41 of file VariableSmm.c.