summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Universal/Variable
Commit message (Collapse)AuthorAgeFilesLines
* MdeModulePkg: VariableSmmRuntimeDxe: Added request unblock memory interfaceKun Qin2021-03-052-0/+43
| | | | | | | | | | | | | | | | This changes added usage of MmUnblockMemoryLib to explicitly request runtime cache regions(and its indicators) to be accessible from MM environment when PcdEnableVariableRuntimeCache is enabled. It will bring in compatibility with architectures that supports full memory blockage inside MM. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Signed-off-by: Kun Qin <kun.q@outlook.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com> Message-Id: <MWHPR06MB31026EA41F28F2CE12B68574F3969@MWHPR06MB3102.namprd06.prod.outlook.com>
* MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase to PcdIlias Apalodimas2021-02-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | Instead of running StMM in SPM, OP-TEE creates a new secure partition, which emulates SPM and isolates StMM from the rest of the Trusted Applications (TAs). We can then compile StMM as an FD image and run it in OP-TEE. With the addition of a new RPMB driver, we can leverage OP-TEE and store variables to an RPMB device. Since EDK2 upper layers expect byte addressable code, for the RPMB to work, we need to allocate memory and sync it with the hardware on read/writes. Since DynamicPCDs are not supported in that context we can only use PatchablePCDs. So let's switch them to Pcd instead of FixedPcd and accomodate the new driver. While at it, move the rest of the variables under Pcd section, instead of FixedPcd -- this is in line with how the variables are defined in the other Variable modules. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Acked-by: Ard Biesheuvel <ardb@kernel.org>
* MdeModulePkg/Variable/RuntimeDxe: Add Variable Lock Protocol Unit TestsMichael D Kinney2020-12-152-0/+601
| | | | | | | | | | | | | | | | https://bugzilla.tianocore.org/show_bug.cgi?id=3111 Add host based unit tests for the multiple lock case using Variable Lock Protocol, Variable Policy Protocol, and mixes of Variable Lock Protocol and Variable Policy Protocol. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Signed-off-by: Bret Barkelew <Bret.Barkelew@microsoft.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
* MdeModulePkg/Variable/RuntimeDxe: Restore Variable Lock Protocol behaviorBret Barkelew2020-12-151-36/+59
| | | | | | | | | | | | | | | | | | | | | | | https://bugzilla.tianocore.org/show_bug.cgi?id=3111 The VariableLock shim currently fails if called twice because the underlying Variable Policy engine returns an error if a policy is set on an existing variable. This breaks existing code which expect it to silently pass if a variable is locked multiple times (because it should "be locked"). Refactor the shim to confirm that the variable is indeed locked and then change the error to EFI_SUCCESS and generate a DEBUG_ERROR message so the duplicate lock can be reported in a debug log and removed. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Signed-off-by: Bret Barkelew <Bret.Barkelew@microsoft.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
* MdeModulePkg: Drop VarLock from RuntimeDxe variable driverBret Barkelew2020-11-175-48/+75
| | | | | | | | | | | | | | | | | https://bugzilla.tianocore.org/show_bug.cgi?id=2522 Now that everything should be moved to VariablePolicy, drop support for the deprecated VarLock SMI interface and associated functions from variable RuntimeDxe. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Bret Barkelew <brbarkel@microsoft.com> Signed-off-by: Bret Barkelew <brbarkel@microsoft.com> Reviewed-by: Dandan Bi <dandan.bi@intel.com> Acked-by: Jian J Wang <jian.j.wang@intel.com>
* MdeModulePkg: Change TCG MOR variables to use VariablePolicyBret Barkelew2020-11-174-25/+82
| | | | | | | | | | | | | | | https://bugzilla.tianocore.org/show_bug.cgi?id=2522 These were previously using VarLock, which is being deprecated. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Bret Barkelew <brbarkel@microsoft.com> Signed-off-by: Bret Barkelew <brbarkel@microsoft.com> Reviewed-by: Dandan Bi <dandan.bi@intel.com> Acked-by: Jian J Wang <jian.j.wang@intel.com>
* MdeModulePkg: Allow VariablePolicy state to delete protected variablesBret Barkelew2020-11-172-0/+12
| | | | | | | | | | | | | | | | | | | | https://bugzilla.tianocore.org/show_bug.cgi?id=2522 TcgMorLockSmm provides special protections for the TCG MOR variables. This will check IsVariablePolicyEnabled() before enforcing them to allow variable deletion when policy engine is disabled. Only allows deletion, not modification. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Bret Barkelew <brbarkel@microsoft.com> Signed-off-by: Bret Barkelew <brbarkel@microsoft.com> Reviewed-by: Dandan Bi <dandan.bi@intel.com> Acked-by: Jian J Wang <jian.j.wang@intel.com>
* MdeModulePkg: Connect VariablePolicy business logic to VariableServicesBret Barkelew2020-11-177-0/+670
| | | | | | | | | | | | | | | | | | | | https://bugzilla.tianocore.org/show_bug.cgi?id=2522 VariablePolicy is an updated interface to replace VarLock and VarCheckProtocol. Add connective code to publish the VariablePolicy protocol and wire it to either the SMM communication interface or directly into the VariablePolicyLib business logic. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Bret Barkelew <brbarkel@microsoft.com> Signed-off-by: Bret Barkelew <brbarkel@microsoft.com> Reviewed-by: Dandan Bi <dandan.bi@intel.com> Acked-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
* MdeModulePkg/Variable/RuntimeDxe: Fix return status from Reclaim()Michael D Kinney2020-07-141-12/+18
| | | | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2844 Update Reclaim() to return the error status from the reclaim operation and not the status of SynchronizeRuntimeVariableCache() that can be EFI_SUCCESS even through the status from reclaim is an error. Without this change, the return status from SetVariable() can be EFI_SUCCESS even though the variable was not actually set. This occurs if the variable store is full and a Reclaim() is invoked to free up space and even after all possible space is freed, there is still not enough room for the variable being set. This condition should return EFI_OUT_OF_RESOURCES. Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Liming Gao <liming.gao@intel.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
* MdeModulePkg/VariableSmmRuntimeDxe: switch to MM communicate 2Ard Biesheuvel2020-05-122-20/+23
| | | | | | | | | Switch to the new MM communicate 2 protocol which supports both traditional and standalone MM. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
* MdeModulePkg VariablePei: Return GetVariable() attr if EFI_BUFFER_TOO_SMALLMichael Kubacki2020-04-071-9/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2062 This commit makes the behavior for PeiGetVariable() match the following specification-defined behavior. It is now consistent with the DXE/SMM variable driver implementation. The UEFI specification v2.8 Errata A Section 8.2 "GetVariable()" "Attributes" parameter description states: "If not NULL, a pointer to the memory location to return the attributes bitmask for the variable. See 'Related Definitions.' If not NULL, then Attributes is set on output both when EFI_SUCCESS and when EFI_BUFFER_TOO_SMALL is returned." The attributes were previously only returned from the implementation in Variable.c on EFI_SUCCESS. They are now returned on EFI_SUCCESS or EFI_BUFFER_TOO_SMALL according to spec. Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Guomin Jiang <guomin.jiang@intel.com>
* MdeModulePkg Variable: Return GetVariable() attr if EFI_BUFFER_TOO_SMALLMichael Kubacki2020-04-072-7/+13
| | | | | | | | | | | | | | | | | | | | | | | | | REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2062 The UEFI specification v2.8 Errata A Section 8.2 "GetVariable()" "Attributes" parameter description states: "If not NULL, a pointer to the memory location to return the attributes bitmask for the variable. See 'Related Definitions.' If not NULL, then Attributes is set on output both when EFI_SUCCESS and when EFI_BUFFER_TOO_SMALL is returned." The attributes were previously only returned from the implementation in Variable.c on EFI_SUCCESS. They are now returned on EFI_SUCCESS or EFI_BUFFER_TOO_SMALL according to spec. Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Guomin Jiang <guomin.jiang@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
* MdeModulePkg/Variable: Fix VarErrorFlag RT cache offset calculationMichael Kubacki2020-01-171-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2457 This commit fixes an offset calculation that is used to write the VarErrorFlag UEFI variable to the UEFI variable runtime cache. Currently a physical address is used instead of an offset. This commit changes the offset to zero with a length of the entire non-volatile variable store so the entire non-volatile variable store buffer in SMRAM (with the variable update modification) is copied to the runtime variable cache. This follows the same pattern used in other SynchronizeRuntimeVariableCache () calls for consistency. * Observable symptom: An exception in SMM will most likely occur due to the invalid memory reference when the VarErrorFlag variable is written. The variable is most commonly written when the UEFI variable store is full. * The issue only occurs when the variable runtime cache is enabled by the following PCD being set to TRUE: gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache Fixes: aab3b9b9a1e5e1f3fa966fb1667fc3e6c47e7706 Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Michael Turner <michael.turner@microsoft.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
* MdeModulePkg/VariableSmmRuntimeDxe.inf: list local header "Variable.h"Laszlo Ersek2019-12-021-0/+1
| | | | | | | | | | | | | | | | | | | | Commit aab3b9b9a1e5 ("MdeModulePkg/Variable: Add RT GetVariable() cache support", 2019-11-05) added "VariableParsing.h" to "VariableSmmRuntimeDxe.inf". "VariableParsing.h" includes "Variable.h", so the "build" utility is right to warn us that "Variable.h" should be listed in [Sources] too. Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Leif Lindholm <leif.lindholm@linaro.org> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael Kubacki <michael.a.kubacki@intel.com> Fixes: aab3b9b9a1e5e1f3fa966fb1667fc3e6c47e7706 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
* MdeModulePkg/Variable: Initialize local variable "RtPtrTrack"edk2-stable201911Kubacki, Michael A2019-11-251-0/+2
| | | | | | | | | | | | | | | | | | | | | REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2364 Fixes a new build warning in VS2012 introduced in f8ff4cca7c. This patch initializes the local variable "RtPtrTrack" in FindVariableInRuntimeCache (). This ensures the pointers in the structure are initialized in the case no variable stores exist in the list of variable stores. Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
* MdeModulePkg/Variable: Initialize local variable "Variable"Kubacki, Michael A2019-11-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2364 Fixes a new build warning in VS2012 introduced in f8ff4cca7c. This patch initializes the local variable "Variable" in VariableServiceGetNextVariableInternal (). This ensures the pointers in the structure are initialized in the case no variable stores exist in the list of variable stores. Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
* MdeModulePkg/Variable: Fix volatile variable RT cache update logicMichael Kubacki2019-11-151-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2333 During a SetVariable () invocation, UpdateVariable () is called. UpdateVariable () contains logic to determine whether a volatile or non-volatile UEFI variable was set so the corresponding runtime cache can be updated to reflect the change. The current logic simply evaluates Variable->Volatile to determine which runtime cache should be updated. The problem is Variable->Volatile does not always reflect whether a volatile variable is being set. Variable->Volatile is set to TRUE only in the case a pre-existing variable is found in the volatile variable store. Therefore, the value is FALSE when a new volatile variable is written. This change updates the logic to take this into account. If a new variable is written successfully, the Attributes will accurately reflect whether the variable is non-volatile. If a pre-existing variable is modified, the Volatile field will reflect the type of variable (Attributes are not reliable; e.g. 0x0 indicates deletion). * Observable symptom: A volatile variable that was set successfully might return EFI_NOT_FOUND when the variable should be found. * The issue is a regression introduced to the variable services only when the variable runtime cache is enabled by the following PCD being set to TRUE: gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache * The issue was implemented in commit aab3b9b9a1 but the PCD was not set to TRUE by default enabling the issue until commit e07b7d024a. Fixes: aab3b9b9a1e5e1f3fa966fb1667fc3e6c47e7706 Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
* MdeModulePkg/Variable: Add RT GetNextVariableName() cache supportMichael Kubacki2019-11-051-9/+128
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://bugzilla.tianocore.org/show_bug.cgi?id=2220 This change implements the Runtime Service GetNextVariableName() using the runtime cache in VariableSmmRuntimeDxe. Runtime Service calls to GetNextVariableName() will no longer trigger a SW SMI when gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache is set to TRUE (default value). Overall system performance and stability will be improved by eliminating an SMI for these calls as they typically result in a relatively large number of invocations to retrieve all variable names in all variable stores present. Cc: Dandan Bi <dandan.bi@intel.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Eric Dong <eric.dong@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
* MdeModulePkg/Variable: Add RT GetVariable() cache supportMichael Kubacki2019-11-0510-40/+971
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2220 This change reduces SMIs for GetVariable () by maintaining a UEFI variable cache in Runtime DXE in addition to the pre- existing cache in SMRAM. When the Runtime Service GetVariable() is invoked, a Runtime DXE cache is used instead of triggering an SMI to VariableSmm. This can improve overall system performance by servicing variable read requests without rendezvousing all cores into SMM. The runtime cache can be disabled with by setting the FeaturePCD gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache to FALSE. If the PCD is set to FALSE, the runtime cache will not be used and an SMI will be triggered for Runtime Service GetVariable () and GetNextVariableName () invocations. The following are important points regarding the behavior of the variable drivers when the variable runtime cache is enabled. 1. All of the non-volatile storage contents are loaded into the cache upon driver load. This one time load operation from storage is preferred as opposed to building the cache on demand. An on- demand cache would require a fallback SMI to load data into the cache as variables are requested. 2. SetVariable () requests will continue to always trigger an SMI. This occurs regardless of whether the variable is volatile or non-volatile. 3. Both volatile and non-volatile variables are cached in a runtime buffer. As is the case in the current EDK II variable driver, they continue to be cached in separate buffers. 4. The cache in Runtime DXE and SMM are intended to be exact copies of one another. All SMM variable accesses only return data from the SMM cache. The runtime caches are only updated after the variable I/O operation is successful in SMM. The runtime caches are only updated from SMM. 5. Synchronization mechanisms are in place to ensure the runtime cache content integrity with the SMM cache. These may result in updates to runtime cache that are the same in content but different in offset and size from updates to the SMM cache. When using SMM variables with runtime cache enabled, two caches will now be present. 1. "Runtime Cache" - Maintained in VariableSmmRuntimeDxe. Used to service Runtime Services GetVariable () and GetNextVariableName () callers. 2. "SMM Cache" - Maintained in VariableSmm to service SMM GetVariable () and GetNextVariableName () callers. a. This cache is retained so SMM modules do not operate on data outside SMRAM. Because a race condition can occur if an SMI occurs during the execution of runtime code reading from the runtime cache, a runtime cache read lock is introduced that explicitly moves pending updates from SMM to the runtime cache if an SMM update occurs while the runtime cache is locked. Note that it is not expected a Runtime services call will interrupt SMM processing since all CPU cores rendezvous in SMM. It is possible to view UEFI variable read and write statistics by setting the gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics FeaturePcd to TRUE and using the VariableInfo UEFI application in MdeModulePkg to dump variable statistics to the console. By doing so, a user can view the number of GetVariable () hits from the Runtime DXE variable driver (Runtime Cache hits) and the SMM variable driver (SMM Cache hits). SMM Cache hits for GetVariable () will occur when SMM modules invoke GetVariable (). Cc: Dandan Bi <dandan.bi@intel.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Eric Dong <eric.dong@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
* MdeModulePkg/Variable: Add a file for NV variable functionsMichael Kubacki2019-11-056-316/+408
| | | | | | | | | | | | | | | | | | | | This change adds a dedicated file for variable operations specific to non-volatile variables. This decreases the overall length of the relatively large Variable.c file. Cc: Dandan Bi <dandan.bi@intel.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Eric Dong <eric.dong@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
* MdeModulePkg/Variable: Parameterize auth status in VariableParsingMichael Kubacki2019-11-055-167/+339
| | | | | | | | | | | | | | | | | | | | | | | | | | The file VariableParsing.c provides generic functionality related to parsing variable related structures and information. In order to calculate offsets for certain operations, the functions must know if authenticated variables are enabled as this increases the size of variable headers. This change removes linking against a global variable in an external file in favor of passing the authenticated variable status as a parameter to the variable parsing functions. Cc: Dandan Bi <dandan.bi@intel.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Eric Dong <eric.dong@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
* MdeModulePkg/Variable: Parameterize VARIABLE_INFO_ENTRY bufferMichael Kubacki2019-11-053-35/+40
| | | | | | | | | | | | | | | | | | | | | UpdateVariableInfo () currently accepts parameters regarding updates to be made to a global variable of type VARIABLE_INFO_ENTRY. This change passes the structure by pointer to UpdateVariableInfo () so structures other than the fixed global variable can be updated. Cc: Dandan Bi <dandan.bi@intel.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Eric Dong <eric.dong@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
* MdeModulePkg/Variable: Parameterize GetNextVariableInternal () storesMichael Kubacki2019-11-054-40/+73
| | | | | | | | | | | | | | | | | | | | | | | The majority of logic related to GetNextVariableName () is currently implemented in VariableServiceGetNextVariableInternal (). The list of variable stores to search for the given variable name and variable GUID is defined in the function body. This change adds a new parameter so that the caller must pass in the list of variable stores to be used in the variable search. Cc: Dandan Bi <dandan.bi@intel.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Eric Dong <eric.dong@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
* MdeModulePkg/Variable: Consolidate common parsing functionsMichael Kubacki2019-11-059-845/+1047
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change moves the following functions into a dedicated file so they may be used in other variable files as needed. These are commonly needed for basic variable data structure parsing operations. The functions are grouped together in VariableParsing.c to support cohesiveness for these operations in the file. Furthermore, it reduces the overall size of the common Variable.c file. * DataSizeOfVariable () * FindVariableEx () * GetEndPointer () * GetNextVariablePtr () * GetStartPointer () * GetVariableDataOffset () * GetVariableDataPtr () * GetVariableHeaderSize () * GetVariableNamePtr () * GetVariableStoreStatus () * GetVendorGuidPtr () * IsValidVariableHeader () * NameSizeOfVariable () * SetDataSizeOfVariable () * SetNameSizeOfVariable () * UpdateVariableInfo () * VariableCompareTimeStampInternal () * VariableServiceGetNextVariableInternal () Cc: Dandan Bi <dandan.bi@intel.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Eric Dong <eric.dong@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
* MdeModulePkg/Variable/Pei: Update the condition in if statementShenglei Zhang2019-11-041-1/+1
| | | | | | | | | | | IndexTable->Length is used as index in array IndexTable->Index[]. So IndexTable->Length needs to be checked, which should be less than the array size. Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Liming Gao <liming.gao@intel.com> Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
* MdeModulePkg: stop abusing EFI_EVENT for protocol notify registrationLaszlo Ersek2019-10-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | EfiCreateProtocolNotifyEvent() takes a (VOID**) for "Registration", similarly to gBS->RegisterProtocolNotify(). We should pass the address of an actual pointer-to-VOID, and not the address of an EFI_EVENT. EFI_EVENT just happens to be specified as (VOID*), and has nothing to do with the registration. The same applies to gMmst->MmRegisterProtocolNotify(). "mFtwRegistration", "mFvRegistration", and "mFvbRegistration" are used for nothing else. This change is a no-op in practice; it's a semantic improvement. Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Zhichao Gao <zhichao.gao@intel.com> Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
* MdeModulePkg: Replace BSD License with BSD+Patent LicenseMichael D Kinney2019-04-0931-207/+31
| | | | | | | | | | | | | | | | | | | | | https://bugzilla.tianocore.org/show_bug.cgi?id=1373 Replace BSD 2-Clause License with BSD+Patent License. This change is based on the following emails: https://lists.01.org/pipermail/edk2-devel/2019-February/036260.html https://lists.01.org/pipermail/edk2-devel/2018-October/030385.html RFCs with detailed process for the license change: V3: https://lists.01.org/pipermail/edk2-devel/2019-March/038116.html V2: https://lists.01.org/pipermail/edk2-devel/2019-March/037669.html V1: https://lists.01.org/pipermail/edk2-devel/2019-March/037500.html Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
* MdeModulePkg: Remove EmuVariableRuntimeDxeStar Zeng2019-02-196-2485/+0
| | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1323 Merge EmuVariable and Real variable driver. The real variable driver has been updated to support emulated variable NV mode. This patch removes EmuVariableRuntimeDxe after platforms are migrated to use the merged variable driver. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Tested-by: Julien Grall <julien.grall@arm.com> Acked-by: Julien Grall <julien.grall@arm.com>
* MdeModulePkg: Fix coding style issuesDandan Bi2019-02-023-7/+7
| | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1479 Fix issues that reported by Edk2 coding style check tool(ECC) that: Comment description should end with period '.' Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi <dandan.bi@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
* MdeModulePkg VariableStandaloneMm: Add PcdEmuVariableNvModeEnable in infStar Zeng2019-01-251-1/+3
| | | | | | | | | | | | | | | It was missed in 7cd69959463ac9c761163ed8e8a93907b68e70da when rebasing the patches after 688b2cad7b712493f2cf8b6948ab795545e13961 added VariableStandaloneMm. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Dandan Bi <dandan.bi@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Dandan Bi <dandan.bi@intel.com>
* MdeModulePkg VariablePei: Don't check BOOT_IN_RECOVERY_MODEStar Zeng2019-01-242-4/+7
| | | | | | | | | | | | | | Don't check BOOT_IN_RECOVERY_MODE, but check PcdEmuVariableNvModeEnable which platform can configure flexibly. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Tested-by: Julien Grall <julien.grall@arm.com> Acked-by: Julien Grall <julien.grall@arm.com>
* MdeModulePkg Variable: Add emulated variable NV mode supportStar Zeng2019-01-246-120/+281
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1323 Merge EmuVariable and Real variable driver. Add emulated variable NV mode support in real variable driver. Platform can configure PcdEmuVariableNvModeEnable statically (build time) or dynamically (boot time) to support emulated variable NV mode. If PcdEmuVariableNvModeEnable is configured to dynamic, its value should be set before Variable driver starts to work, otherwise default value will take effect. Then EmuVariableRuntimeDxe could be removed, the removal of EmuVariableRuntimeDxe will be done after platforms are migrated to use the merged variable driver. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Acked-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Tested-by: Julien Grall <julien.grall@arm.com> Acked-by: Julien Grall <julien.grall@arm.com>
* MdeModulePkg Variable: type case VolatileBase to UINTN directlyStar Zeng2019-01-241-1/+1
| | | | | | | | | | | | | | | | | | | | | Simplify ((UINTN) ((UINT8 *) VolatileBase + VolatileBase->Size)) to ((UINTN) VolatileBase + VolatileBase->Size) This patch prepares for adding emulated variable NV mode support in VariableRuntimeDxe. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Julien Grall <julien.grall@arm.com> Acked-by: Julien Grall <julien.grall@arm.com>
* MdeModulePkg Variable: Remove CacheOffset in UpdateVariable()Star Zeng2019-01-241-6/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1323 Merge EmuVariable and Real variable driver. CacheOffset could be removed in UpdateVariable() after // // update the memory copy of Flash region. // CopyMem ( (UINT8 *)mNvVariableCache + CacheOffset, (UINT8 *)NextVariable, VarSize ); is moved to be before mVariableModuleGlobal->NonVolatileLastVariableOffset value is updated, like right before mVariableModuleGlobal->NonVolatileLastVariableOffset += HEADER_ALIGN (VarSize); Except for the movement above, the patch also capitalizes the first character of "update the memory copy of Flash region". This patch prepares for adding emulated variable NV mode support in VariableRuntimeDxe. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Julien Grall <julien.grall@arm.com> Acked-by: Julien Grall <julien.grall@arm.com>
* MdeModulePkg Variable: Abstract VariableWriteServiceInitializeDxe/SmmStar Zeng2019-01-242-26/+60
| | | | | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1323 Merge EmuVariable and Real variable driver. Abstract VariableWriteServiceInitializeDxe/Smm from FtwNotificationEvent/SmmFtwNotificationEvent, then VariableWriteServiceInitializeDxe/Smm could be not aware the NV storage is real or emulated. This patch prepares for adding emulated variable NV mode support in VariableRuntimeDxe. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Tested-by: Julien Grall <julien.grall@arm.com> Acked-by: Julien Grall <julien.grall@arm.com>
* MdeModulePkg Variable: Not get NV PCD in VariableWriteServiceInitializeStar Zeng2019-01-244-30/+27
| | | | | | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1323 Merge EmuVariable and Real variable driver. Add macro NV_STORAGE_VARIABLE_BASE. Not get NV PCD in VariableWriteServiceInitialize, but in FtwNotificationEvent/SmmFtwNotificationEvent, then VariableWriteServiceInitialize could be not aware the NV storage is real or emulated. This patch prepares for adding emulated variable NV mode support in VariableRuntimeDxe. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Tested-by: Julien Grall <julien.grall@arm.com> Acked-by: Julien Grall <julien.grall@arm.com>
* MdeModulePkg Variable: Move "extern XXX" to Variable.hStar Zeng2019-01-243-10/+8
| | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1323 Merge EmuVariable and Real variable driver. Move "extern XXX" to Variable.h from VariableDxe.c/VariableSmm.c. This patch prepares for adding emulated variable NV mode support in VariableRuntimeDxe. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Tested-by: Julien Grall <julien.grall@arm.com> Acked-by: Julien Grall <julien.grall@arm.com>
* MdeModulePkg Variable: Abstract InitRealNonVolatileVariableStoreStar Zeng2019-01-241-28/+58
| | | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1323 Merge EmuVariable and Real variable driver. Abstract InitRealNonVolatileVariableStore from InitNonVolatileVariableStore. This patch prepares for adding emulated variable NV mode support in VariableRuntimeDxe. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Tested-by: Julien Grall <julien.grall@arm.com> Acked-by: Julien Grall <julien.grall@arm.com>
* MdeModulePkg Variable: Add some missing changes for 9b18845Star Zeng2019-01-242-10/+8
| | | | | | | | | | | | | | | | | | | | | | To improve performance 9b18845a4b4cd1d2cf004cbc1cadf8a93ccb37ea changed the code which read from physical MMIO address to read from memory cache, but it missed some places that could be updated the same away for performance optimization. The patch updates these places as supplementary. I found them when updating code for https://bugzilla.tianocore.org/show_bug.cgi?id=1323 Merge EmuVariable and Real variable driver. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao Wu <hao.a.wu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Tested-by: Julien Grall <julien.grall@arm.com> Acked-by: Julien Grall <julien.grall@arm.com>
* MdeModulePkg/VariableRuntimeDxe: implement standalone MM versionArd Biesheuvel2019-01-162-0/+231
| | | | | | | | | | | Reuse most of the existing code to implement a variable runtime driver that will be able to execute in the context of standalone MM. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Star Zeng <star.zeng@intel.com>
* MdeModulePkg/VariableRuntimeDxe: factor out boot service accessesArd Biesheuvel2019-01-165-56/+222
| | | | | | | | | | | | | | In preparation of providing a standalone MM based variable runtime driver, move the existing SMM driver to the new MM services table, and factor out some pieces that are specific to the traditional driver, mainly related to the use of UEFI boot services, which are not accessible to standalone MM drivers. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Regression-tested-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Star Zeng <star.zeng@intel.com>
* MdeModulePkg/Variable: Update to consume SpeculationBarrierHao Wu2018-12-257-32/+38
| | | | | | | | | | | | | | | | | | | | REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1417 Since BaseLib API AsmLfence() is a x86 arch specific API and should be avoided using in generic codes, this commit replaces the usage of AsmLfence() with arch-generic API SpeculationBarrier(). Please note that speculation execution barriers are intended to be asserted for SMM codes, hence, this commit still preserve an empty implementation of the speculation execution barrier for the DXE codes. Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Star Zeng <star.zeng@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
* MdeModulePkg/Variable: add debug logs in VariableServiceSetVariableVijayenthiran Subramaniam2018-11-231-0/+30
| | | | | | | | | | | | | | Print debug messages if size of the VariableName plus DataSize exceeds Max(Auth|Voltaile)VariableSize bytes. The messages will be useful if any platform specific value of Max(Auth|Voltaile)VariableSize PCDs have to be changed. Cc: Star Zeng <star.zeng@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Ruiyu Ni <ruiyu.ni@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Vijayenthiran Subramaniam <vijayenthiran.subramaniam@arm.com> Reviewed-by: Star Zeng <star.zeng@intel.com>
* MdeModulePkg Variable: Fix Timestamp zeroing issue on APPEND_WRITEStar Zeng2018-10-171-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=415 When SetVariable() to a time based auth variable with APPEND_WRITE attribute, and if the EFI_VARIABLE_AUTHENTICATION_2.TimeStamp in the input Data is earlier than current value, it will cause timestamp zeroing. This issue may bring time based auth variable downgrade problem. For example: A vendor released three certs at 2014, 2015, and 2016, and system integrated the 2016 cert. User can SetVariable() with 2015 cert and APPEND_WRITE attribute to cause timestamp zeroing first, then SetVariable() with 2014 cert to downgrade the cert. This patch fixes this issue. Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Chao Zhang <chao.b.zhang@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
* MdeModulePkg/Variable: [CVE-2017-5753] Fix bounds check bypassHao Wu2018-09-307-1/+99
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1194 Speculative execution is used by processor to avoid having to wait for data to arrive from memory, or for previous operations to finish, the processor may speculate as to what will be executed. If the speculation is incorrect, the speculatively executed instructions might leave hints such as which memory locations have been brought into cache. Malicious actors can use the bounds check bypass method (code gadgets with controlled external inputs) to infer data values that have been used in speculative operations to reveal secrets which should not otherwise be accessed. This commit will focus on the SMI handler(s) registered within the Variable\RuntimeDxe driver and insert AsmLfence API to mitigate the bounds check bypass issue. For SMI handler SmmVariableHandler(): Under "case SMM_VARIABLE_FUNCTION_GET_VARIABLE:", 'SmmVariableHeader->NameSize' can be a potential cross boundary access of the 'CommBuffer' (controlled external input) during speculative execution. This cross boundary access is later used as the index to access array 'SmmVariableHeader->Name' by code: "SmmVariableHeader->Name[SmmVariableHeader->NameSize/sizeof (CHAR16) - 1]" One can observe which part of the content within array was brought into cache to possibly reveal the value of 'SmmVariableHeader->NameSize'. Hence, this commit adds a AsmLfence() after the boundary/range checks of 'CommBuffer' to prevent the speculative execution. And there are 2 similar cases under "case SMM_VARIABLE_FUNCTION_SET_VARIABLE:" and "case SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET:" as well. This commits also handles them. Also, under "case SMM_VARIABLE_FUNCTION_SET_VARIABLE:", '(UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize' points to the 'CommBuffer' (with some offset) and then passed as parameter 'Data' to function VariableServiceSetVariable(). Within function VariableServiceSetVariable(), there is a sanity check for EFI_VARIABLE_AUTHENTICATION_2 descriptor for the data pointed by 'Data'. If this check is speculatively bypassed, potential cross-boundary data access for 'Data' is possible to be revealed via the below function calls sequence during speculative execution: AuthVariableLibProcessVariable() ProcessVarWithPk() or ProcessVarWithKek() Within function ProcessVarWithPk() or ProcessVarWithKek(), for the code "PayloadSize = DataSize - AUTHINFO2_SIZE (Data);", 'AUTHINFO2_SIZE (Data)' can be a cross boundary access during speculative execution. Then, 'PayloadSize' is possible to be revealed by the function call sequence: AuthServiceInternalUpdateVariableWithTimeStamp() mAuthVarLibContextIn->UpdateVariable() VariableExLibUpdateVariable() UpdateVariable() CopyMem() Hence, this commit adds a AsmLfence() after the sanity check for EFI_VARIABLE_AUTHENTICATION_2 descriptor upon 'Data' within function VariableServiceSetVariable() to prevent the speculative execution. Also, please note that the change made within function VariableServiceSetVariable() will affect DXE as well. However, since we only focuses on the SMM codes, the commit will introduce a new module internal function called VariableLoadFence() to handle this. This internal function will have 2 implementations (1 for SMM, 1 for DXE). For the SMM implementation, it is a wrapper to call the AsmLfence() API; for the DXE implementation, it is empty. A more detailed explanation of the purpose of commit is under the 'Bounds check bypass mitigation' section of the below link: https://software.intel.com/security-software-guidance/insights/host-firmware-speculative-execution-side-channel-mitigation And the document at: https://software.intel.com/security-software-guidance/api-app/sites/default/files/337879-analyzing-potential-bounds-Check-bypass-vulnerabilities.pdf Cc: Jiewen Yao <jiewen.yao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Star Zeng <star.zeng@intel.com> Acked-by: Laszlo Ersek <lersek@redhat.com> Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
* MdeModulePkg Variable: Fix comment typo 'end' to 'start'Star Zeng2018-09-282-6/+10
| | | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1214 This patch only updates comment and function description, so has no functionality impact. This patch fixes comment typo 'end' to 'start' in GetStartPointer. GetStartPointer for PEI and DXE has aligned function description, but GetEndPointer does not. This patch also aligns GetEndPointer's function description for PEI and DXE. Cc: Liming Gao <liming.gao@intel.com> Cc: Ruiyu Ni <ruiyu.ni@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
* MdeModulePkg: Removing ipf which is no longer supported from edk2.Chen A Chen2018-09-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Removing rules for Ipf sources file: * Remove the source file which path with "ipf" and also listed in [Sources.IPF] section of INF file. * Remove the source file which listed in [Components.IPF] section of DSC file and not listed in any other [Components] section. * Remove the embedded Ipf code for MDE_CPU_IPF. Removing rules for Inf file: * Remove IPF from VALID_ARCHITECTURES comments. * Remove DXE_SAL_DRIVER from LIBRARY_CLASS in [Defines] section. * Remove the INF which only listed in [Components.IPF] section in DSC. * Remove statements from [BuildOptions] that provide IPF specific flags. * Remove any IPF sepcific sections. Removing rules for Dec file: * Remove [Includes.IPF] section from Dec. Removing rules for Dsc file: * Remove IPF from SUPPORTED_ARCHITECTURES in [Defines] section of DSC. * Remove any IPF specific sections. * Remove statements from [BuildOptions] that provide IPF specific flags. Cc: Star Zeng <star.zeng@intel.com> Cc: Eric Dong <eric.dong@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Chen A Chen <chen.a.chen@intel.com> Reviewed-by: Star Zeng <star.zeng@intel.com>
* MdeModulePkg: Variable: Re-prioritize TCG/TCG2 protocolZhang, Chao B2018-07-231-5/+5
| | | | | | | | | | | TPM1.2 is obsoleted by TPM2.0. switch TCG/TCG2 protocol check to apply this trend Cc: Long, Qin <qin.long@intel.com> Cc: Yao, Jiewen <jiewen.yao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhang, Chao B <chao.b.zhang@intel.com> Reviewed-by: Yao, Jiewen <jiewen.yao@intel.com>
* MdeModulePkg/Variable: Check EFI_MEMORY_RUNTIME attribute before setting itBrijesh Singh2018-07-041-7/+9
| | | | | | | | | | | | | | Set the EFI_MEMORY_RUNTIME attribute in FtwNotificationEvent() only if the attribute is not already present. This will ensure that the attributes set by the platform drivers (e.g Ovmf pflash) is not lost. Cc: Dong Eric <eric.dong@intel.com> Cc: Justen Jordan L <jordan.l.justen@intel.com> Cc: Zeng Star <star.zeng@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Contributed-under: TianoCore Contribution Agreement 1.1 Reviewed-by: Star Zeng <star.zeng@intel.com> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
* MdeModulePkg Variable: Add/Correct GetHobVariableStore para descriptionStar Zeng2018-07-032-1/+4
| | | | | | | | | | | It is caused by 09808bd39b0c76559354253639766458ec24da79. Cc: Liming Gao <liming.gao@intel.com> Cc: Dandan Bi <dandan.bi@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Dandan Bi <dandan.bi@intel.com>