summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Fan <jeff.fan@intel.com>2014-04-09 03:21:23 +0000
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2014-04-09 03:21:23 +0000
commitc3d087c0f4f94ca9cbd881f7ab92c51a4aed553d (patch)
tree9c7fcb16208f2adf5dd7778a36fd84ee7045f392
parent00983ad9c96424417543be294db24929f8e87d6c (diff)
downloadedk2-c3d087c0f4f94ca9cbd881f7ab92c51a4aed553d.tar.gz
edk2-c3d087c0f4f94ca9cbd881f7ab92c51a4aed553d.tar.bz2
edk2-c3d087c0f4f94ca9cbd881f7ab92c51a4aed553d.zip
Sync patches r15357, r15360, r15376, r15385, r15386, r15387, r15388, r15391 and r15393 from main trunk.
1. MdeModulePkg PCD: Fix PCD driver to return default data if size mismatch. 2. Fix current TPM device string missing. Use efivarstore instead of varstor, remove TPM disable. 3. Comment PwdCredential driver. 4. Report the setting variable failure to platform through the status code when core cannot handle the error. 5. Support load 64 bit image from 32 bit core. Add more enhancement to check invalid PE format. 6. MdeModulePkg/SecurityPkg Variable: Calculate enough space for PlatformLang and Lang variables and use PcdUefiVariableDefaultLangDeprecate to turn off auto update between PlatformLang and Lang variables. 7. Remove RT attribute for variable LegacyDevOrder 8. Add check to make sure the data be valid. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan <jeff.fan@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/branches/UDK2014@15441 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c59
-rw-r--r--IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c17
-rw-r--r--IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c98
-rw-r--r--IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf4
-rw-r--r--IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h47
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h47
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf4
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c153
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c24
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c7
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c17
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c172
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c9
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/Hotkey.c5
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/Language.c16
-rw-r--r--MdeModulePkg/Include/Guid/StatusCodeDataTypeVariable.h40
-rw-r--r--MdeModulePkg/MdeModulePkg.dec7
-rw-r--r--MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c33
-rw-r--r--MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h1
-rw-r--r--MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf4
-rw-r--r--MdeModulePkg/Universal/PCD/Dxe/Service.c32
-rw-r--r--MdeModulePkg/Universal/PCD/Pei/Service.c40
-rw-r--r--MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c10
-rw-r--r--MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideLib.c60
-rw-r--r--MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c344
-rw-r--r--MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h37
-rw-r--r--MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf5
-rw-r--r--MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf5
-rw-r--r--MdePkg/Library/BasePeCoffLib/BasePeCoff.c31
-rw-r--r--MdePkg/MdePkg.dec3
-rw-r--r--SecurityPkg/SecurityPkg.dsc2
-rw-r--r--SecurityPkg/Tcg/TrEEConfig/TpmDetection.c43
-rw-r--r--SecurityPkg/Tcg/TrEEConfig/TrEEConfig.vfr9
-rw-r--r--SecurityPkg/Tcg/TrEEConfig/TrEEConfigDriver.c63
-rw-r--r--SecurityPkg/Tcg/TrEEConfig/TrEEConfigDxe.inf1
-rw-r--r--SecurityPkg/Tcg/TrEEConfig/TrEEConfigImpl.c177
-rw-r--r--SecurityPkg/Tcg/TrEEConfig/TrEEConfigImpl.h2
-rw-r--r--SecurityPkg/Tcg/TrEEConfig/TrEEConfigNvData.h14
-rw-r--r--SecurityPkg/Tcg/TrEEConfig/TrEEConfigPeim.c19
-rw-r--r--SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c337
-rw-r--r--SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h40
-rw-r--r--SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableRuntimeDxe.inf3
-rw-r--r--SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableSmm.inf3
43 files changed, 1540 insertions, 504 deletions
diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
index 3701434efb..134833286f 100644
--- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
+++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
@@ -1,7 +1,7 @@
/** @file
BDS Lib functions which relate with create or process the boot option.
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, 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
@@ -82,6 +82,10 @@ BdsDeleteBootOption (
0,
NULL
);
+ //
+ // Deleting variable with existing variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
//
// adjust boot order array
@@ -626,6 +630,10 @@ BdsDeleteAllInvalidLegacyBootOptions (
BootOrderSize,
BootOrder
);
+ //
+ // Shrinking variable with existing variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
if (BootOrder != NULL) {
FreePool (BootOrder);
}
@@ -857,11 +865,10 @@ BdsAddNonExistingLegacyBootOptions (
&BootOrder,
&BootOrderSize
);
- if (EFI_ERROR (Status)) {
- break;
+ if (!EFI_ERROR (Status)) {
+ BbsIndex = Index;
+ OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];
}
- BbsIndex = Index;
- OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];
}
ASSERT (BbsIndex == Index);
@@ -2265,7 +2272,7 @@ BdsLibBootViaBootOption (
// In this case, "BootCurrent" is not created.
// Only create the BootCurrent variable when it points to a valid Boot#### variable.
//
- gRT->SetVariable (
+ SetVariableAndReportStatusCodeOnError (
L"BootCurrent",
&gEfiGlobalVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
@@ -2463,13 +2470,14 @@ Done:
//
// Clear Boot Current
+ // Deleting variable with current implementation shouldn't fail.
//
gRT->SetVariable (
L"BootCurrent",
&gEfiGlobalVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
0,
- &Option->BootCurrent
+ NULL
);
return Status;
@@ -2580,6 +2588,7 @@ BdsExpandPartitionPartialDevicePathToFull (
FreePool (TempNewDevicePath);
//
// Save the matching Device Path so we don't need to do a connect all next time
+ // Failure to set the variable only impacts the performance when next time expanding the short-form device path.
//
Status = gRT->SetVariable (
HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
@@ -2678,6 +2687,7 @@ BdsExpandPartitionPartialDevicePathToFull (
//
// Save the matching Device Path so we don't need to do a connect all next time
+ // Failure to set the variable only impacts the performance when next time expanding the short-form device path.
//
Status = gRT->SetVariable (
HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
@@ -2887,6 +2897,10 @@ BdsLibDeleteOptionFromHandle (
BootOrderSize,
BootOrder
);
+ //
+ // Shrinking variable with existing variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
FreePool (BootOrder);
@@ -2985,6 +2999,10 @@ BdsDeleteAllInvalidEfiBootOption (
NULL
);
//
+ // Deleting variable with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
+ //
// Mark this boot option in boot order as deleted
//
BootOrder[Index] = 0xffff;
@@ -3012,6 +3030,10 @@ BdsDeleteAllInvalidEfiBootOption (
Index2 * sizeof (UINT16),
BootOrder
);
+ //
+ // Shrinking variable with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
FreePool (BootOrder);
@@ -3135,7 +3157,9 @@ BdsLibEnumerateAllBootOption (
AsciiStrSize (PlatLang),
PlatLang
);
- ASSERT_EFI_ERROR (Status);
+ //
+ // Failure to set the variable only impacts the performance next time enumerating the boot options.
+ //
if (LastLang != NULL) {
FreePool (LastLang);
@@ -3478,6 +3502,7 @@ BdsLibBootNext (
VOID
)
{
+ EFI_STATUS Status;
UINT16 *BootNext;
UINTN BootNextSize;
CHAR16 Buffer[20];
@@ -3502,13 +3527,17 @@ BdsLibBootNext (
// Clear the boot next variable first
//
if (BootNext != NULL) {
- gRT->SetVariable (
- L"BootNext",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- 0,
- BootNext
- );
+ Status = gRT->SetVariable (
+ L"BootNext",
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ 0,
+ NULL
+ );
+ //
+ // Deleting variable with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
//
// Start to build the boot option and try to boot
diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
index 84e4a0e6be..271093eec9 100644
--- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
+++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
@@ -1,7 +1,7 @@
/** @file
BDS Lib functions which contain all the code to connect console device
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, 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
@@ -285,17 +285,16 @@ BdsLibUpdateConsoleVariable (
// Finally, Update the variable of the default console by NewDevicePath
//
DevicePathSize = GetDevicePathSize (NewDevicePath);
- Status = gRT->SetVariable (
- ConVarName,
- &gEfiGlobalVariableGuid,
- Attributes,
- DevicePathSize,
- NewDevicePath
- );
+ Status = SetVariableAndReportStatusCodeOnError (
+ ConVarName,
+ &gEfiGlobalVariableGuid,
+ Attributes,
+ DevicePathSize,
+ NewDevicePath
+ );
if ((DevicePathSize == 0) && (Status == EFI_NOT_FOUND)) {
Status = EFI_SUCCESS;
}
- ASSERT_EFI_ERROR (Status);
if (VarConsole == NewDevicePath) {
if (VarConsole != NULL) {
diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
index cafbe71e25..4ea30bdf7d 100644
--- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
+++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
@@ -1419,13 +1419,13 @@ BdsSetMemoryTypeInformationVariable (
// Or create the variable in first boot.
//
if (MemoryTypeInformationModified || !MemoryTypeInformationVariableExists) {
- Status = gRT->SetVariable (
- EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
- &gEfiMemoryTypeInformationGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
- VariableSize,
- PreviousMemoryTypeInformation
- );
+ Status = SetVariableAndReportStatusCodeOnError (
+ EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
+ &gEfiMemoryTypeInformationGuid,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
+ VariableSize,
+ PreviousMemoryTypeInformation
+ );
if (!EFI_ERROR (Status)) {
//
@@ -1486,3 +1486,87 @@ BdsLibUserIdentify (
return Manager->Identify (Manager, User);
}
+/**
+ Set the variable and report the error through status code upon failure.
+
+ @param VariableName A Null-terminated string that is the name of the vendor's variable.
+ Each VariableName is unique for each VendorGuid. VariableName must
+ contain 1 or more characters. If VariableName is an empty string,
+ then EFI_INVALID_PARAMETER is returned.
+ @param VendorGuid A unique identifier for the vendor.
+ @param Attributes Attributes bitmask to set for the variable.
+ @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
+ EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
+ EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
+ causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
+ set, then a SetVariable() call with a DataSize of zero will not cause any change to
+ the variable value (the timestamp associated with the variable may be updated however
+ even if no new data value is provided,see the description of the
+ EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
+ be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
+ @param Data The contents for the variable.
+
+ @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
+ defined by the Attributes.
+ @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
+ DataSize exceeds the maximum allowed.
+ @retval EFI_INVALID_PARAMETER VariableName is an empty string.
+ @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
+ @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
+ @retval EFI_WRITE_PROTECTED The variable in question is read-only.
+ @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
+ @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
+ or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
+ does NOT pass the validation check carried out by the firmware.
+
+ @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
+**/
+EFI_STATUS
+SetVariableAndReportStatusCodeOnError (
+ IN CHAR16 *VariableName,
+ IN EFI_GUID *VendorGuid,
+ IN UINT32 Attributes,
+ IN UINTN DataSize,
+ IN VOID *Data
+ )
+{
+ EFI_STATUS Status;
+ EDKII_SET_VARIABLE_STATUS *SetVariableStatus;
+ UINTN NameSize;
+
+ Status = gRT->SetVariable (
+ VariableName,
+ VendorGuid,
+ Attributes,
+ DataSize,
+ Data
+ );
+ if (EFI_ERROR (Status)) {
+ NameSize = StrSize (VariableName);
+ SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize);
+ if (SetVariableStatus != NULL) {
+ CopyGuid (&SetVariableStatus->Guid, VendorGuid);
+ SetVariableStatus->NameSize = NameSize;
+ SetVariableStatus->DataSize = DataSize;
+ SetVariableStatus->SetStatus = Status;
+ SetVariableStatus->Attributes = Attributes;
+ CopyMem (SetVariableStatus + 1, VariableName, NameSize);
+ CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data, DataSize);
+
+ REPORT_STATUS_CODE_EX (
+ EFI_ERROR_CODE,
+ PcdGet32 (PcdErrorCodeSetVariable),
+ 0,
+ NULL,
+ &gEdkiiStatusCodeDataTypeVariableGuid,
+ SetVariableStatus,
+ sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize
+ );
+
+ FreePool (SetVariableStatus);
+ }
+ }
+
+ return Status;
+}
+
diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf b/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
index 2fb9916aa5..041afc4e10 100644
--- a/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
+++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
@@ -5,7 +5,7 @@
# 2) BDS boot device connect interface;
# 3) BDS Misc interfaces for mainting boot variable, ouput string, etc.
#
-# Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2014, 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
@@ -79,6 +79,7 @@
gHdBootDevicePathVariablGuid ## SOMETIMES_PRODUCES ## Variable:L"HDDP" (The device path of Boot file on Hard device.)
gBdsLibStringPackageGuid ## PRODUCES ## GUID (HII String PackageList Guid)
gEfiLegacyDevOrderVariableGuid ## CONSUMES ## GUID
+ gEdkiiStatusCodeDataTypeVariableGuid ## SOMETIMES_CONSUMES
[Protocols]
gEfiSimpleFileSystemProtocolGuid # PROTOCOL CONSUMES
@@ -111,4 +112,5 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange
gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad
gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart
+ gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile
diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h b/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
index 80b1f49a90..c32579bfc5 100644
--- a/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
+++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
@@ -1,7 +1,7 @@
/** @file
BDS library definition, include the file and data structure
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, 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
@@ -51,6 +51,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Guid/HdBootVariable.h>
#include <Guid/LastEnumLang.h>
#include <Guid/LegacyDevOrder.h>
+#include <Guid/StatusCodeDataTypeVariable.h>
#include <Library/PrintLib.h>
#include <Library/DebugLib.h>
@@ -147,4 +148,48 @@ ValidateOption (
UINTN VariableSize
);
+/**
+ Set the variable and report the error through status code upon failure.
+
+ @param VariableName A Null-terminated string that is the name of the vendor's variable.
+ Each VariableName is unique for each VendorGuid. VariableName must
+ contain 1 or more characters. If VariableName is an empty string,
+ then EFI_INVALID_PARAMETER is returned.
+ @param VendorGuid A unique identifier for the vendor.
+ @param Attributes Attributes bitmask to set for the variable.
+ @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
+ EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
+ EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
+ causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
+ set, then a SetVariable() call with a DataSize of zero will not cause any change to
+ the variable value (the timestamp associated with the variable may be updated however
+ even if no new data value is provided,see the description of the
+ EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
+ be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
+ @param Data The contents for the variable.
+
+ @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
+ defined by the Attributes.
+ @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
+ DataSize exceeds the maximum allowed.
+ @retval EFI_INVALID_PARAMETER VariableName is an empty string.
+ @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
+ @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
+ @retval EFI_WRITE_PROTECTED The variable in question is read-only.
+ @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
+ @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
+ or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
+ does NOT pass the validation check carried out by the firmware.
+
+ @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
+**/
+EFI_STATUS
+SetVariableAndReportStatusCodeOnError (
+ IN CHAR16 *VariableName,
+ IN EFI_GUID *VendorGuid,
+ IN UINT32 Attributes,
+ IN UINTN DataSize,
+ IN VOID *Data
+ );
+
#endif // _BDS_LIB_H_
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h b/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h
index e535bc21da..93bafd2dd8 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h
@@ -1,7 +1,7 @@
/** @file
Head file for BDS Architectural Protocol implementation
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, 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
@@ -20,6 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Guid/MdeModuleHii.h>
#include <Guid/FileSystemVolumeLabelInfo.h>
#include <Guid/HiiPlatformSetupFormset.h>
+#include <Guid/StatusCodeDataTypeVariable.h>
#include <Protocol/DevicePath.h>
#include <IndustryStandard/SmBios.h>
#include <Protocol/LoadFile.h>
@@ -189,4 +190,48 @@ BdsProcessCapsules (
EFI_BOOT_MODE BootMode
);
+/**
+ Set the variable and report the error through status code upon failure.
+
+ @param VariableName A Null-terminated string that is the name of the vendor's variable.
+ Each VariableName is unique for each VendorGuid. VariableName must
+ contain 1 or more characters. If VariableName is an empty string,
+ then EFI_INVALID_PARAMETER is returned.
+ @param VendorGuid A unique identifier for the vendor.
+ @param Attributes Attributes bitmask to set for the variable.
+ @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
+ EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
+ EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
+ causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
+ set, then a SetVariable() call with a DataSize of zero will not cause any change to
+ the variable value (the timestamp associated with the variable may be updated however
+ even if no new data value is provided,see the description of the
+ EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
+ be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
+ @param Data The contents for the variable.
+
+ @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
+ defined by the Attributes.
+ @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
+ DataSize exceeds the maximum allowed.
+ @retval EFI_INVALID_PARAMETER VariableName is an empty string.
+ @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
+ @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
+ @retval EFI_WRITE_PROTECTED The variable in question is read-only.
+ @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
+ @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
+ or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
+ does NOT pass the validation check carried out by the firmware.
+
+ @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
+**/
+EFI_STATUS
+BdsDxeSetVariableAndReportStatusCodeOnError (
+ IN CHAR16 *VariableName,
+ IN EFI_GUID *VendorGuid,
+ IN UINT32 Attributes,
+ IN UINTN DataSize,
+ IN VOID *Data
+ );
+
#endif
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf b/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
index b10056491e..6796adc436 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
@@ -14,7 +14,7 @@
# BDSDxe also maintain the UI for "Boot Manager, Boot Maintaince Manager, Device Manager" which
# is used for user to configure boot option or maintain hardware device.
#
-# Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2008 - 2014, 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
@@ -142,6 +142,7 @@
gDriverHealthFormSetGuid ## SOMETIMES_PRODUCES ## DriverHealth HII Package
gConnectConInEventGuid ## CONSUMES ## GUID (Connect ConIn Event)
gEfiFmpCapsuleGuid ## CONSUMES ## GUID (FMP Capsule)
+ gEdkiiStatusCodeDataTypeVariableGuid ## SOMETIMES_CONSUMES
[Protocols]
gEfiSimpleFileSystemProtocolGuid ## PROTOCOL CONSUMES
@@ -188,6 +189,7 @@
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile
+ gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable
[Depex]
TRUE
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
index 33b3cc2dc4..ae7ad2153c 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
@@ -5,7 +5,7 @@
After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be invoked
to enter BDS phase.
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, 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
@@ -164,13 +164,17 @@ BdsBootDeviceSelect (
//
// Clear the this variable so it's only exist in this time boot
//
- gRT->SetVariable (
- L"BootNext",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- 0,
- mBootNext
- );
+ Status = gRT->SetVariable (
+ L"BootNext",
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ 0,
+ NULL
+ );
+ //
+ // Deleting variable with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
//
// Add the boot next boot option
@@ -368,6 +372,9 @@ BdsFormalizeConsoleVariable (
0,
NULL
);
+ //
+ // Deleting variable with current variable implementation shouldn't fail.
+ //
ASSERT_EFI_ERROR (Status);
}
}
@@ -406,14 +413,13 @@ BdsFormalizeEfiGlobalVariable (
OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI \
| EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED;
- Status = gRT->SetVariable (
- L"OsIndicationsSupported",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- sizeof(UINT64),
- &OsIndicationSupport
- );
- ASSERT_EFI_ERROR (Status);
+ BdsDxeSetVariableAndReportStatusCodeOnError (
+ L"OsIndicationsSupported",
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ sizeof(UINT64),
+ &OsIndicationSupport
+ );
//
// If OsIndications is invalid, remove it.
@@ -442,10 +448,13 @@ BdsFormalizeEfiGlobalVariable (
Status = gRT->SetVariable (
L"OsIndications",
&gEfiGlobalVariableGuid,
- Attributes,
0,
- &OsIndication
+ 0,
+ NULL
);
+ //
+ // Deleting variable with current variable implementation shouldn't fail.
+ //
ASSERT_EFI_ERROR (Status);
}
}
@@ -481,16 +490,19 @@ BdsAllocateMemoryForPerformanceData (
//
// Save the pointer to variable for use in S3 resume.
//
- Status = gRT->SetVariable (
- L"PerfDataMemAddr",
- &gPerformanceProtocolGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- sizeof (EFI_PHYSICAL_ADDRESS),
- &AcpiLowMemoryBase
- );
- ASSERT_EFI_ERROR (Status);
+ BdsDxeSetVariableAndReportStatusCodeOnError (
+ L"PerfDataMemAddr",
+ &gPerformanceProtocolGuid,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ sizeof (EFI_PHYSICAL_ADDRESS),
+ &AcpiLowMemoryBase
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((EFI_D_ERROR, "[Bds] PerfDataMemAddr (%08x) cannot be saved to NV storage.\n", AcpiLowMemoryBase));
+ }
//
// Mark L"PerfDataMemAddr" variable to read-only if the Variable Lock protocol exists
+ // Still lock it even the variable cannot be saved to prevent it's set by 3rd party code.
//
Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);
if (!EFI_ERROR (Status)) {
@@ -594,14 +606,13 @@ BdsEntry (
// If time out value equal 0xFFFF, no need set to 0xFFFF to variable area because UEFI specification
// define same behavior between no value or 0xFFFF value for L"Timeout".
//
- Status = gRT->SetVariable (
+ BdsDxeSetVariableAndReportStatusCodeOnError (
L"Timeout",
&gEfiGlobalVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
sizeof (UINT16),
&BootTimeOut
);
- ASSERT_EFI_ERROR(Status);
}
//
@@ -655,3 +666,89 @@ BdsEntry (
return ;
}
+
+
+/**
+ Set the variable and report the error through status code upon failure.
+
+ @param VariableName A Null-terminated string that is the name of the vendor's variable.
+ Each VariableName is unique for each VendorGuid. VariableName must
+ contain 1 or more characters. If VariableName is an empty string,
+ then EFI_INVALID_PARAMETER is returned.
+ @param VendorGuid A unique identifier for the vendor.
+ @param Attributes Attributes bitmask to set for the variable.
+ @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
+ EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
+ EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
+ causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
+ set, then a SetVariable() call with a DataSize of zero will not cause any change to
+ the variable value (the timestamp associated with the variable may be updated however
+ even if no new data value is provided,see the description of the
+ EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
+ be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
+ @param Data The contents for the variable.
+
+ @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
+ defined by the Attributes.
+ @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
+ DataSize exceeds the maximum allowed.
+ @retval EFI_INVALID_PARAMETER VariableName is an empty string.
+ @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
+ @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
+ @retval EFI_WRITE_PROTECTED The variable in question is read-only.
+ @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
+ @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
+ or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
+ does NOT pass the validation check carried out by the firmware.
+
+ @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
+**/
+EFI_STATUS
+BdsDxeSetVariableAndReportStatusCodeOnError (
+ IN CHAR16 *VariableName,
+ IN EFI_GUID *VendorGuid,
+ IN UINT32 Attributes,
+ IN UINTN DataSize,
+ IN VOID *Data
+ )
+{
+ EFI_STATUS Status;
+ EDKII_SET_VARIABLE_STATUS *SetVariableStatus;
+ UINTN NameSize;
+
+ Status = gRT->SetVariable (
+ VariableName,
+ VendorGuid,
+ Attributes,
+ DataSize,
+ Data
+ );
+ if (EFI_ERROR (Status)) {
+ NameSize = StrSize (VariableName);
+ SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize);
+ if (SetVariableStatus != NULL) {
+ CopyGuid (&SetVariableStatus->Guid, VendorGuid);
+ SetVariableStatus->NameSize = NameSize;
+ SetVariableStatus->DataSize = DataSize;
+ SetVariableStatus->SetStatus = Status;
+ SetVariableStatus->Attributes = Attributes;
+ CopyMem (SetVariableStatus + 1, VariableName, NameSize);
+ CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data, DataSize);
+
+ REPORT_STATUS_CODE_EX (
+ EFI_ERROR_CODE,
+ PcdGet32 (PcdErrorCodeSetVariable),
+ 0,
+ NULL,
+ &gEdkiiStatusCodeDataTypeVariableGuid,
+ SetVariableStatus,
+ sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize
+ );
+
+ FreePool (SetVariableStatus);
+ }
+ }
+
+ return Status;
+}
+
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c
index db0fed5834..adf84f42f7 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c
@@ -3,7 +3,7 @@
and manage the legacy boot option, all legacy boot option is getting from
the legacy BBS table.
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, 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
@@ -143,6 +143,9 @@ OrderLegacyBootOption4SameType (
BootOrderSize,
BootOrder
);
+ //
+ // Changing content without increasing its size with current variable implementation shouldn't fail.
+ //
ASSERT_EFI_ERROR (Status);
FreePool (NewBootOption);
@@ -171,6 +174,7 @@ GroupMultipleLegacyBootOption4SameType (
VOID
)
{
+ EFI_STATUS Status;
UINTN Index;
UINTN DeviceIndex;
UINTN DeviceTypeIndex[7];
@@ -233,13 +237,17 @@ GroupMultipleLegacyBootOption4SameType (
FreePool (BootOption);
}
- gRT->SetVariable (
- L"BootOrder",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- BootOrderSize,
- BootOrder
- );
+ Status = gRT->SetVariable (
+ L"BootOrder",
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ BootOrderSize,
+ BootOrder
+ );
+ //
+ // Changing content without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
FreePool (BootOrder);
}
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c
index c83b7ddede..5fe5388f9e 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c
@@ -1,7 +1,7 @@
/** @file
Utility routines used by boot maintenance modules.
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, 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
@@ -178,7 +178,10 @@ EfiLibDeleteVariable (
0,
NULL
);
- ASSERT (!EFI_ERROR (Status));
+ //
+ // Deleting variable with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
FreePool (VarBuf);
}
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c
index 5f200e2e16..b974a67ea5 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c
@@ -1,7 +1,7 @@
/** @file
The functions for Boot Maintainence Main menu.
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, 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
@@ -672,14 +672,13 @@ ApplyChangeHandler (
break;
case FORM_TIME_OUT_ID:
- Status = gRT->SetVariable (
- L"Timeout",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- sizeof (UINT16),
- &(CurrentFakeNVMap->BootTimeOut)
- );
- ASSERT_EFI_ERROR(Status);
+ BdsDxeSetVariableAndReportStatusCodeOnError (
+ L"Timeout",
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ sizeof (UINT16),
+ &(CurrentFakeNVMap->BootTimeOut)
+ );
Private->BmmOldFakeNVData.BootTimeOut = CurrentFakeNVMap->BootTimeOut;
break;
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c
index ef36ae2dc8..529fdaea2a 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c
@@ -1,7 +1,7 @@
/** @file
Variable operation that will be used by bootmaint
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, 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
@@ -165,9 +165,10 @@ Var_ChangeBootOrder (
BootOrderListSize * sizeof (UINT16),
BootOrderList
);
- if (EFI_ERROR (Status)) {
- return Status;
- }
+ //
+ // Changing variable without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
}
return EFI_SUCCESS;
}
@@ -303,9 +304,10 @@ Var_ChangeDriverOrder (
DriverOrderListSize * sizeof (UINT16),
DriverOrderList
);
- if (EFI_ERROR (Status)) {
- return Status;
- }
+ //
+ // Changing variable without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
}
return EFI_SUCCESS;
}
@@ -338,7 +340,10 @@ Var_UpdateAllConsoleOption (
GetDevicePathSize (OutDevicePath),
OutDevicePath
);
- ASSERT (!EFI_ERROR (Status));
+ //
+ // Changing variable without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
}
if (InpDevicePath != NULL) {
@@ -350,7 +355,10 @@ Var_UpdateAllConsoleOption (
GetDevicePathSize (InpDevicePath),
InpDevicePath
);
- ASSERT (!EFI_ERROR (Status));
+ //
+ // Changing variable without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
}
if (ErrDevicePath != NULL) {
@@ -362,7 +370,10 @@ Var_UpdateAllConsoleOption (
GetDevicePathSize (ErrDevicePath),
ErrDevicePath
);
- ASSERT (!EFI_ERROR (Status));
+ //
+ // Changing variable without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
}
}
@@ -667,38 +678,40 @@ Var_UpdateDriverOption (
BufferSize,
Buffer
);
- ASSERT_EFI_ERROR (Status);
- DriverOrderList = BdsLibGetVariableAndSize (
- L"DriverOrder",
- &gEfiGlobalVariableGuid,
- &DriverOrderListSize
- );
- NewDriverOrderList = AllocateZeroPool (DriverOrderListSize + sizeof (UINT16));
- ASSERT (NewDriverOrderList != NULL);
- if (DriverOrderList != NULL) {
- CopyMem (NewDriverOrderList, DriverOrderList, DriverOrderListSize);
- EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid);
- }
- NewDriverOrderList[DriverOrderListSize / sizeof (UINT16)] = Index;
+ if (!EFI_ERROR (Status)) {
+ DriverOrderList = BdsLibGetVariableAndSize (
+ L"DriverOrder",
+ &gEfiGlobalVariableGuid,
+ &DriverOrderListSize
+ );
+ NewDriverOrderList = AllocateZeroPool (DriverOrderListSize + sizeof (UINT16));
+ ASSERT (NewDriverOrderList != NULL);
+ if (DriverOrderList != NULL) {
+ CopyMem (NewDriverOrderList, DriverOrderList, DriverOrderListSize);
+ EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid);
+ }
+ NewDriverOrderList[DriverOrderListSize / sizeof (UINT16)] = Index;
- Status = gRT->SetVariable (
- L"DriverOrder",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- DriverOrderListSize + sizeof (UINT16),
- NewDriverOrderList
- );
- ASSERT_EFI_ERROR (Status);
- if (DriverOrderList != NULL) {
- FreePool (DriverOrderList);
- }
- DriverOrderList = NULL;
- FreePool (NewDriverOrderList);
- InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link);
- DriverOptionMenu.MenuNumber++;
+ Status = gRT->SetVariable (
+ L"DriverOrder",
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ DriverOrderListSize + sizeof (UINT16),
+ NewDriverOrderList
+ );
+ if (DriverOrderList != NULL) {
+ FreePool (DriverOrderList);
+ }
+ DriverOrderList = NULL;
+ FreePool (NewDriverOrderList);
+ if (!EFI_ERROR (Status)) {
+ InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link);
+ DriverOptionMenu.MenuNumber++;
- *DescriptionData = 0x0000;
- *OptionalData = 0x0000;
+ *DescriptionData = 0x0000;
+ *OptionalData = 0x0000;
+ }
+ }
return EFI_SUCCESS;
}
@@ -835,39 +848,41 @@ Var_UpdateBootOption (
BufferSize,
Buffer
);
- ASSERT_EFI_ERROR (Status);
+ if (!EFI_ERROR (Status)) {
- BootOrderList = BdsLibGetVariableAndSize (
+ BootOrderList = BdsLibGetVariableAndSize (
+ L"BootOrder",
+ &gEfiGlobalVariableGuid,
+ &BootOrderListSize
+ );
+ ASSERT (BootOrderList != NULL);
+ NewBootOrderList = AllocateZeroPool (BootOrderListSize + sizeof (UINT16));
+ ASSERT (NewBootOrderList != NULL);
+ CopyMem (NewBootOrderList, BootOrderList, BootOrderListSize);
+ NewBootOrderList[BootOrderListSize / sizeof (UINT16)] = Index;
+
+ if (BootOrderList != NULL) {
+ FreePool (BootOrderList);
+ }
+
+ Status = gRT->SetVariable (
L"BootOrder",
&gEfiGlobalVariableGuid,
- &BootOrderListSize
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ BootOrderListSize + sizeof (UINT16),
+ NewBootOrderList
);
- ASSERT (BootOrderList != NULL);
- NewBootOrderList = AllocateZeroPool (BootOrderListSize + sizeof (UINT16));
- ASSERT (NewBootOrderList != NULL);
- CopyMem (NewBootOrderList, BootOrderList, BootOrderListSize);
- NewBootOrderList[BootOrderListSize / sizeof (UINT16)] = Index;
-
- if (BootOrderList != NULL) {
- FreePool (BootOrderList);
- }
-
- Status = gRT->SetVariable (
- L"BootOrder",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- BootOrderListSize + sizeof (UINT16),
- NewBootOrderList
- );
- ASSERT_EFI_ERROR (Status);
+ if (!EFI_ERROR (Status)) {
- FreePool (NewBootOrderList);
- NewBootOrderList = NULL;
- InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link);
- BootOptionMenu.MenuNumber++;
+ FreePool (NewBootOrderList);
+ NewBootOrderList = NULL;
+ InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link);
+ BootOptionMenu.MenuNumber++;
- NvRamMap->DescriptionData[0] = 0x0000;
- NvRamMap->OptionalData[0] = 0x0000;
+ NvRamMap->DescriptionData[0] = 0x0000;
+ NvRamMap->OptionalData[0] = 0x0000;
+ }
+ }
return EFI_SUCCESS;
}
@@ -987,6 +1002,10 @@ Var_UpdateBootOrder (
BootOrderListSize,
BootOrderList
);
+ //
+ // Changing the content without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
FreePool (BootOrderList);
GroupMultipleLegacyBootOption4SameType ();
@@ -1058,10 +1077,11 @@ Var_UpdateDriverOrder (
DriverOrderListSize,
NewDriverOrderList
);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
+ //
+ // Changing the content without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
+
BOpt_FreeMenu (&DriverOptionMenu);
BOpt_GetDriverOptions (CallbackData);
return EFI_SUCCESS;
@@ -1215,7 +1235,7 @@ Var_UpdateBBSOption (
Status = gRT->SetVariable (
VAR_LEGACY_DEV_ORDER,
&gEfiLegacyDevOrderVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
VarSize,
OriginalPtr
);
@@ -1258,6 +1278,10 @@ Var_UpdateBBSOption (
OptionSize,
BootOptionVar
);
+ //
+ // Changing the content without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
FreePool (BootOptionVar);
}
@@ -1281,6 +1305,10 @@ Var_UpdateBBSOption (
OptionSize,
BootOptionVar
);
+ //
+ // Changing the content without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
FreePool (BootOptionVar);
}
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
index 432b22469e..3bbe71a8fe 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
@@ -1,7 +1,7 @@
/** @file
FrontPage routines to handle the callbacks and browser calls
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, 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
@@ -182,7 +182,6 @@ FrontPageCallback (
CHAR8 *LangCode;
CHAR8 *Lang;
UINTN Index;
- EFI_STATUS Status;
if (Action != EFI_BROWSER_ACTION_CHANGING && Action != EFI_BROWSER_ACTION_CHANGED) {
//
@@ -226,14 +225,13 @@ FrontPageCallback (
}
if (Index == Value->u8) {
- Status = gRT->SetVariable (
+ BdsDxeSetVariableAndReportStatusCodeOnError (
L"PlatformLang",
&gEfiGlobalVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
AsciiStrSize (Lang),
Lang
);
- ASSERT_EFI_ERROR(Status);
} else {
ASSERT (FALSE);
}
@@ -1095,6 +1093,9 @@ PlatformBdsEnterFrontPage (
sizeof(UINT64),
&OsIndication
);
+ //
+ // Changing the content without increasing its size with current variable implementation shouldn't fail.
+ //
ASSERT_EFI_ERROR (Status);
//
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/Hotkey.c b/IntelFrameworkModulePkg/Universal/BdsDxe/Hotkey.c
index 477411377d..63de0d5f57 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/Hotkey.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/Hotkey.c
@@ -2,7 +2,7 @@
Provides a way for 3rd party applications to register themselves for launch by the
Boot Manager based on hot key
-Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2014, 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
@@ -550,6 +550,9 @@ InitializeHotkeyService (
sizeof (UINT32),
&BootOptionSupport
);
+ //
+ // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.
+ //
ASSERT_EFI_ERROR (Status);
KeyOptionNumbers = HotkeyGetOptionNumbers (&KeyOptionCount);
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/Language.c b/IntelFrameworkModulePkg/Universal/BdsDxe/Language.c
index 6d25bfe237..4c74b018af 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/Language.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/Language.c
@@ -1,7 +1,7 @@
/** @file
Language settings
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, 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
@@ -425,7 +425,7 @@ InitializeLangVariable (
// The default language code should be one of the supported language codes.
//
ASSERT (IsLangInSupportedLangCodes (SupportedLang, DefaultLang, Iso639Language));
- Status = gRT->SetVariable (
+ BdsDxeSetVariableAndReportStatusCodeOnError (
LangName,
&gEfiGlobalVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
@@ -462,7 +462,7 @@ InitializeLanguage (
if (LangCodesSettingRequired) {
if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
//
- // UEFI 2.1 depricated this variable so we support turning it off
+ // UEFI 2.0 depricated this variable so we support turning it off
//
Status = gRT->SetVariable (
L"LangCodes",
@@ -471,6 +471,10 @@ InitializeLanguage (
AsciiStrSize (LangCodes),
LangCodes
);
+ //
+ // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
}
Status = gRT->SetVariable (
@@ -480,11 +484,15 @@ InitializeLanguage (
AsciiStrSize (PlatformLangCodes),
PlatformLangCodes
);
+ //
+ // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
}
if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
//
- // UEFI 2.1 depricated this variable so we support turning it off
+ // UEFI 2.0 depricated this variable so we support turning it off
//
InitializeLangVariable (L"Lang", LangCodes, (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultLang), TRUE);
}
diff --git a/MdeModulePkg/Include/Guid/StatusCodeDataTypeVariable.h b/MdeModulePkg/Include/Guid/StatusCodeDataTypeVariable.h
new file mode 100644
index 0000000000..9ea85f8099
--- /dev/null
+++ b/MdeModulePkg/Include/Guid/StatusCodeDataTypeVariable.h
@@ -0,0 +1,40 @@
+/** @file
+ This file defines the GUID and data structure used to pass variable setting
+ failure information to the Status Code Protocol.
+
+Copyright (c) 2014, 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 that accompanies this distribution.
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _STATUS_CODE_DATA_TYPE_VARIABLE_H_
+#define _STATUS_CODE_DATA_TYPE_VARIABLE_H_
+
+///
+/// The Global ID used to identify a structure of type EDKII_SET_VARIABLE_STATUS.
+/// The status code value is PcdGet32 (PcdErrorCodeSetVariable).
+///
+#define EDKII_STATUS_CODE_DATA_TYPE_VARIABLE_GUID \
+ { \
+ 0xf6ee6dbb, 0xd67f, 0x4ea0, { 0x8b, 0x96, 0x6a, 0x71, 0xb1, 0x9d, 0x84, 0xad } \
+ }
+
+typedef struct {
+ EFI_GUID Guid;
+ UINTN NameSize;
+ UINTN DataSize;
+ EFI_STATUS SetStatus;
+ UINT32 Attributes;
+ // CHAR16 Name[];
+ // UINT8 Data[];
+} EDKII_SET_VARIABLE_STATUS;
+
+extern EFI_GUID gEdkiiStatusCodeDataTypeVariableGuid;
+
+#endif // _STATUS_CODE_DATA_TYPE_VARIABLE_H_
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 9084af7b84..e04246a2f4 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -270,6 +270,9 @@
## Include/Guid/ConnectConInEvent.h
gConnectConInEventGuid = { 0xdb4e8151, 0x57ed, 0x4bed, { 0x88, 0x33, 0x67, 0x51, 0xb5, 0xd1, 0xa8, 0xd7 }}
+ ## Include/Guid/StatusCodeDataTypeVariable.h
+ gEdkiiStatusCodeDataTypeVariableGuid = { 0xf6ee6dbb, 0xd67f, 0x4ea0, { 0x8b, 0x96, 0x6a, 0x71, 0xb1, 0x9d, 0x84, 0xad }}
+
[Ppis]
## Include/Ppi/AtaController.h
gPeiAtaControllerPpiGuid = { 0xa45e60d1, 0xc719, 0x44aa, { 0xb0, 0x7a, 0xaa, 0x77, 0x7f, 0x85, 0x90, 0x6d }}
@@ -603,6 +606,10 @@
# PROGRESS_CODE_S3_SUSPEND_END = (EFI_SOFTWARE_SMM_DRIVER | (EFI_OEM_SPECIFIC | 0x00000001)) = 0x03078001
gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd|0x03078001|UINT32|0x30001033
+ ## Error Code for SetVariable failure.
+ # EDKII_ERROR_CODE_SET_VARIABLE = (EFI_SOFTWARE_DXE_BS_DRIVER | (EFI_OEM_SPECIFIC | 0x00000002)) = 0x03058002
+ gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable|0x03058002|UINT32|0x30001040
+
[PcdsFixedAtBuild,PcdsPatchableInModule]
## VPD type PCD allow developer point an absoluted physical address PcdVpdBaseAddress
# to store PCD value.
diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c
index a27090815c..511094844b 100644
--- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c
+++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c
@@ -1422,11 +1422,13 @@ TerminalUpdateConsoleDevVariable (
)
{
EFI_STATUS Status;
+ UINTN NameSize;
UINTN VariableSize;
UINT8 TerminalType;
EFI_DEVICE_PATH_PROTOCOL *Variable;
EFI_DEVICE_PATH_PROTOCOL *NewVariable;
EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
+ EDKII_SET_VARIABLE_STATUS *SetVariableStatus;
//
// Get global variable and its size according to the name given.
@@ -1462,6 +1464,33 @@ TerminalUpdateConsoleDevVariable (
VariableSize,
Variable
);
+
+ if (EFI_ERROR (Status)) {
+ NameSize = StrSize (VariableName);
+ SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + VariableSize);
+ if (SetVariableStatus != NULL) {
+ CopyGuid (&SetVariableStatus->Guid, &gEfiGlobalVariableGuid);
+ SetVariableStatus->NameSize = NameSize;
+ SetVariableStatus->DataSize = VariableSize;
+ SetVariableStatus->SetStatus = Status;
+ SetVariableStatus->Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
+ CopyMem (SetVariableStatus + 1, VariableName, NameSize);
+ CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Variable, VariableSize);
+
+ REPORT_STATUS_CODE_EX (
+ EFI_ERROR_CODE,
+ PcdGet32 (PcdErrorCodeSetVariable),
+ 0,
+ NULL,
+ &gEdkiiStatusCodeDataTypeVariableGuid,
+ SetVariableStatus,
+ sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + VariableSize
+ );
+
+ FreePool (SetVariableStatus);
+ }
+ }
+
FreePool (Variable);
return ;
@@ -1569,6 +1598,10 @@ TerminalRemoveConsoleDevVariable (
VariableSize,
NewVariable
);
+ //
+ // Shrinking variable with existing variable driver implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
}
if (NewVariable != NULL) {
diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
index 0f285eb286..d393acbc20 100644
--- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
+++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
@@ -20,6 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Guid/GlobalVariable.h>
#include <Guid/PcAnsi.h>
+#include <Guid/StatusCodeDataTypeVariable.h>
#include <Protocol/SimpleTextOut.h>
#include <Protocol/SerialIo.h>
diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
index d4bd55b4ab..6611751853 100644
--- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
+++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
@@ -4,7 +4,7 @@
#
# This driver installs Simple Text In/Out protocol for terminal devices (serial devices or hotplug devices).
#
-# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2006 - 2014, 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
@@ -65,6 +65,7 @@
gEfiVT100Guid ## SOMETIMES_CONSUMES ## GUID
gEfiVT100PlusGuid ## SOMETIMES_CONSUMES ## GUID
gEfiPcAnsiGuid ## SOMETIMES_CONSUMES ## GUID
+ gEdkiiStatusCodeDataTypeVariableGuid ## SOMETIMES_CONSUMES ## GUID
[Protocols]
gEfiSerialIoProtocolGuid ## TO_START
@@ -75,6 +76,7 @@
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType
+ gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable
# [Event]
# ##
diff --git a/MdeModulePkg/Universal/PCD/Dxe/Service.c b/MdeModulePkg/Universal/PCD/Dxe/Service.c
index a9e1ca49a3..4cbf6dd209 100644
--- a/MdeModulePkg/Universal/PCD/Dxe/Service.c
+++ b/MdeModulePkg/Universal/PCD/Dxe/Service.c
@@ -1,7 +1,7 @@
/** @file
Help functions used by PCD DXE driver.
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2014, 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
@@ -457,25 +457,33 @@ GetWorker (
// string array in string table.
//
StringTableIdx = *(STRING_HEAD*)((UINT8 *) PcdDb + VariableHead->DefaultValueOffset);
- VaraiableDefaultBuffer = (VOID *) (StringTable + StringTableIdx);
+ VaraiableDefaultBuffer = (UINT8 *) (StringTable + StringTableIdx);
} else {
VaraiableDefaultBuffer = (UINT8 *) PcdDb + VariableHead->DefaultValueOffset;
}
Status = GetHiiVariable (Guid, Name, &Data, &DataSize);
if (Status == EFI_SUCCESS) {
- if (GetSize == 0) {
+ if (DataSize >= (VariableHead->Offset + GetSize)) {
+ if (GetSize == 0) {
+ //
+ // It is a pointer type. So get the MaxSize reserved for
+ // this PCD entry.
+ //
+ GetPtrTypeSize (TmpTokenNumber, &GetSize);
+ if (GetSize > (DataSize - VariableHead->Offset)) {
+ //
+ // Use actual valid size.
+ //
+ GetSize = DataSize - VariableHead->Offset;
+ }
+ }
//
- // It is a pointer type. So get the MaxSize reserved for
- // this PCD entry.
+ // If the operation is successful, we copy the data
+ // to the default value buffer in the PCD Database.
+ // So that we can free the Data allocated in GetHiiVariable.
//
- GetPtrTypeSize (TmpTokenNumber, &GetSize);
+ CopyMem (VaraiableDefaultBuffer, Data + VariableHead->Offset, GetSize);
}
- //
- // If the operation is successful, we copy the data
- // to the default value buffer in the PCD Database.
- // So that we can free the Data allocated in GetHiiVariable.
- //
- CopyMem (VaraiableDefaultBuffer, Data + VariableHead->Offset, GetSize);
FreePool (Data);
}
RetPtr = (VOID *) VaraiableDefaultBuffer;
diff --git a/MdeModulePkg/Universal/PCD/Pei/Service.c b/MdeModulePkg/Universal/PCD/Pei/Service.c
index 4fb8b4a687..af40db8319 100644
--- a/MdeModulePkg/Universal/PCD/Pei/Service.c
+++ b/MdeModulePkg/Universal/PCD/Pei/Service.c
@@ -2,7 +2,7 @@
The driver internal functions are implmented here.
They build Pei PCD database, and provide access service to PCD database.
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2014, 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
@@ -947,6 +947,7 @@ GetWorker (
PEI_PCD_DATABASE *PeiPcdDb;
UINT32 LocalTokenNumber;
UINT32 LocalTokenCount;
+ UINT8 *VaraiableDefaultBuffer;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
@@ -986,20 +987,37 @@ GetWorker (
Guid = (EFI_GUID *) ((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset) + VariableHead->GuidTableIndex;
Name = (UINT16*)&StringTable[VariableHead->StringIndex];
- Status = GetHiiVariable (Guid, Name, &Data, &DataSize);
-
- if (Status == EFI_SUCCESS) {
- return (VOID *) ((UINT8 *) Data + VariableHead->Offset);
- } else {
+ if ((LocalTokenNumber & PCD_TYPE_ALL_SET) == (PCD_TYPE_HII|PCD_TYPE_STRING)) {
//
- // Return the default value specified by Platform Integrator
+ // If a HII type PCD's datum type is VOID*, the DefaultValueOffset is the index of
+ // string array in string table.
//
- if ((LocalTokenNumber & PCD_TYPE_ALL_SET) == (PCD_TYPE_HII|PCD_TYPE_STRING)) {
- return (VOID*)&StringTable[*(STRING_HEAD*)((UINT8*)PeiPcdDb + VariableHead->DefaultValueOffset)];
- } else {
- return (VOID *) ((UINT8 *) PeiPcdDb + VariableHead->DefaultValueOffset);
+ VaraiableDefaultBuffer = (UINT8 *) &StringTable[*(STRING_HEAD*)((UINT8*) PeiPcdDb + VariableHead->DefaultValueOffset)];
+ } else {
+ VaraiableDefaultBuffer = (UINT8 *) PeiPcdDb + VariableHead->DefaultValueOffset;
+ }
+ Status = GetHiiVariable (Guid, Name, &Data, &DataSize);
+ if ((Status == EFI_SUCCESS) && (DataSize >= (VariableHead->Offset + GetSize))) {
+ if (GetSize == 0) {
+ //
+ // It is a pointer type. So get the MaxSize reserved for
+ // this PCD entry.
+ //
+ GetPtrTypeSize (TokenNumber, &GetSize, PeiPcdDb);
+ if (GetSize > (DataSize - VariableHead->Offset)) {
+ //
+ // Use actual valid size.
+ //
+ GetSize = DataSize - VariableHead->Offset;
+ }
}
+ //
+ // If the operation is successful, we copy the data
+ // to the default value buffer in the PCD Database.
+ //
+ CopyMem (VaraiableDefaultBuffer, (UINT8 *) Data + VariableHead->Offset, GetSize);
}
+ return (VOID *) VaraiableDefaultBuffer;
}
case PCD_TYPE_DATA:
diff --git a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c
index ab254a0b45..3c55a785fc 100644
--- a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c
+++ b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c
@@ -13,7 +13,7 @@
4. It save all the mapping info in NV variables which will be consumed
by platform override protocol driver to publish the platform override protocol.
-Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2014, 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
@@ -1240,6 +1240,7 @@ PlatOverMngrRouteConfig (
EFI_CALLBACK_INFO *Private;
UINT16 KeyValue;
PLAT_OVER_MNGR_DATA *FakeNvData;
+ EFI_STATUS Status;
if (Configuration == NULL || Progress == NULL) {
return EFI_INVALID_PARAMETER;
@@ -1260,11 +1261,12 @@ PlatOverMngrRouteConfig (
return EFI_SUCCESS;
}
+ Status = EFI_SUCCESS;
if (mCurrentPage == FORM_ID_DRIVER) {
KeyValue = KEY_VALUE_DRIVER_GOTO_ORDER;
UpdatePrioritySelectPage (Private, KeyValue, FakeNvData);
KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;
- CommintChanges (Private, KeyValue, FakeNvData);
+ Status = CommintChanges (Private, KeyValue, FakeNvData);
//
// Since UpdatePrioritySelectPage will change mCurrentPage,
// should ensure the mCurrentPage still indicate the second page here
@@ -1274,10 +1276,10 @@ PlatOverMngrRouteConfig (
if (mCurrentPage == FORM_ID_ORDER) {
KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;
- CommintChanges (Private, KeyValue, FakeNvData);
+ Status = CommintChanges (Private, KeyValue, FakeNvData);
}
- return EFI_SUCCESS;
+ return Status;
}
/**
diff --git a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideLib.c b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideLib.c
index 2391ade211..d07f62ab4a 100644
--- a/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideLib.c
+++ b/MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideLib.c
@@ -1,7 +1,7 @@
/** @file
Implementation of the shared functions to do the platform driver vverride mapping.
- Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2007 - 2014, 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
@@ -691,12 +691,17 @@ InitOverridesMapping (
//
VariableNum = 1;
Corrupted = FALSE;
+ NotEnd = 0;
do {
VariableIndex = VariableBuffer;
- //
- // End flag
- //
- NotEnd = *(UINT32*) VariableIndex;
+ if (VariableIndex + sizeof (UINT32) > (UINT8 *) VariableBuffer + BufferSize) {
+ Corrupted = TRUE;
+ } else {
+ //
+ // End flag
+ //
+ NotEnd = *(UINT32*) VariableIndex;
+ }
//
// Traverse the entries containing the mapping that Controller Device Path
// to a set of Driver Device Paths within this variable.
@@ -706,6 +711,10 @@ InitOverridesMapping (
//
// Check signature of this entry
//
+ if (VariableIndex + sizeof (UINT32) > (UINT8 *) VariableBuffer + BufferSize) {
+ Corrupted = TRUE;
+ break;
+ }
Signature = *(UINT32 *) VariableIndex;
if (Signature != PLATFORM_OVERRIDE_ITEM_SIGNATURE) {
Corrupted = TRUE;
@@ -722,6 +731,10 @@ InitOverridesMapping (
//
// Get DriverNum
//
+ if (VariableIndex + sizeof (UINT32) >= (UINT8 *) VariableBuffer + BufferSize) {
+ Corrupted = TRUE;
+ break;
+ }
DriverNumber = *(UINT32*) VariableIndex;
OverrideItem->DriverInfoNum = DriverNumber;
VariableIndex = VariableIndex + sizeof (UINT32);
@@ -735,6 +748,14 @@ InitOverridesMapping (
// Align the VariableIndex since the controller device path may not be aligned, refer to the SaveOverridesMapping()
//
VariableIndex += ((sizeof(UINT32) - ((UINTN) (VariableIndex))) & (sizeof(UINT32) - 1));
+ //
+ // Check buffer overflow.
+ //
+ if ((OverrideItem->ControllerDevicePath == NULL) || (VariableIndex < (UINT8 *) ControllerDevicePath) ||
+ (VariableIndex > (UINT8 *) VariableBuffer + BufferSize)) {
+ Corrupted = TRUE;
+ break;
+ }
//
// Get all DriverImageDevicePath[]
@@ -756,8 +777,20 @@ InitOverridesMapping (
VariableIndex += ((sizeof(UINT32) - ((UINTN) (VariableIndex))) & (sizeof(UINT32) - 1));
InsertTailList (&OverrideItem->DriverInfoList, &DriverImageInfo->Link);
+
+ //
+ // Check buffer overflow
+ //
+ if ((DriverImageInfo->DriverImagePath == NULL) || (VariableIndex < (UINT8 *) DriverDevicePath) ||
+ (VariableIndex < (UINT8 *) VariableBuffer + BufferSize)) {
+ Corrupted = TRUE;
+ break;
+ }
}
InsertTailList (MappingDataBase, &OverrideItem->Link);
+ if (Corrupted) {
+ break;
+ }
}
FreePool (VariableBuffer);
@@ -866,11 +899,11 @@ DeleteOverridesVariables (
//
// Check NotEnd to get all PlatDriOverX variable(s)
//
- while ((*(UINT32*)VariableBuffer) != 0) {
+ while ((VariableBuffer != NULL) && ((*(UINT32*)VariableBuffer) != 0)) {
+ FreePool (VariableBuffer);
UnicodeSPrint (OverrideVariableName, sizeof (OverrideVariableName), L"PlatDriOver%d", VariableNum);
VariableBuffer = GetVariableAndSize (OverrideVariableName, &gEfiCallerIdGuid, &BufferSize);
VariableNum++;
- ASSERT (VariableBuffer != NULL);
}
//
@@ -1057,10 +1090,19 @@ SaveOverridesMapping (
VariableNeededSize,
VariableBuffer
);
- ASSERT (!EFI_ERROR(Status));
+ FreePool (VariableBuffer);
+
+ if (EFI_ERROR (Status)) {
+ if (NumIndex > 0) {
+ //
+ // Delete all PlatDriOver variables when full mapping can't be set.
+ //
+ DeleteOverridesVariables ();
+ }
+ return Status;
+ }
NumIndex ++;
- FreePool (VariableBuffer);
}
return EFI_SUCCESS;
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
index 5f128e9d61..9825580d3a 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -1259,6 +1259,121 @@ VariableGetBestLanguage (
}
/**
+ This function is to check if the remaining variable space is enough to set
+ all Variables from argument list successfully. The purpose of the check
+ is to keep the consistency of the Variables to be in variable storage.
+
+ Note: Variables are assumed to be in same storage.
+ The set sequence of Variables will be same with the sequence of VariableEntry from argument list,
+ so follow the argument sequence to check the Variables.
+
+ @param[in] Attributes Variable attributes for Variable entries.
+ @param ... Variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.
+ A NULL terminates the list.
+
+ @retval TRUE Have enough variable space to set the Variables successfully.
+ @retval FALSE No enough variable space to set the Variables successfully.
+
+**/
+BOOLEAN
+EFIAPI
+CheckRemainingSpaceForConsistency (
+ IN UINT32 Attributes,
+ ...
+ )
+{
+ EFI_STATUS Status;
+ VA_LIST Args;
+ VARIABLE_ENTRY_CONSISTENCY *VariableEntry;
+ UINT64 MaximumVariableStorageSize;
+ UINT64 RemainingVariableStorageSize;
+ UINT64 MaximumVariableSize;
+ UINTN TotalNeededSize;
+ UINTN OriginalVarSize;
+ VARIABLE_STORE_HEADER *VariableStoreHeader;
+ VARIABLE_POINTER_TRACK VariablePtrTrack;
+ VARIABLE_HEADER *NextVariable;
+
+ //
+ // Non-Volatile related.
+ //
+ VariableStoreHeader = mNvVariableCache;
+
+ Status = VariableServiceQueryVariableInfoInternal (
+ Attributes,
+ &MaximumVariableStorageSize,
+ &RemainingVariableStorageSize,
+ &MaximumVariableSize
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ TotalNeededSize = 0;
+ VA_START (Args, Attributes);
+ VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
+ while (VariableEntry != NULL) {
+ TotalNeededSize += VariableEntry->VariableSize;
+ VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
+ }
+ VA_END (Args);
+
+ if (RemainingVariableStorageSize >= TotalNeededSize) {
+ //
+ // Already have enough space.
+ //
+ return TRUE;
+ } else if (AtRuntime ()) {
+ //
+ // At runtime, no reclaim.
+ // The original variable space of Variables can't be reused.
+ //
+ return FALSE;
+ }
+
+ VA_START (Args, Attributes);
+ VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
+ while (VariableEntry != NULL) {
+ //
+ // Check if Variable[Index] has been present and get its size.
+ //
+ OriginalVarSize = 0;
+ VariablePtrTrack.StartPtr = GetStartPointer (VariableStoreHeader);
+ VariablePtrTrack.EndPtr = GetEndPointer (VariableStoreHeader);
+ Status = FindVariableEx (
+ VariableEntry->Name,
+ VariableEntry->Guid,
+ FALSE,
+ &VariablePtrTrack
+ );
+ if (!EFI_ERROR (Status)) {
+ //
+ // Get size of Variable[Index].
+ //
+ NextVariable = GetNextVariablePtr (VariablePtrTrack.CurrPtr);
+ OriginalVarSize = (UINTN) NextVariable - (UINTN) VariablePtrTrack.CurrPtr;
+ //
+ // Add the original size of Variable[Index] to remaining variable storage size.
+ //
+ RemainingVariableStorageSize += OriginalVarSize;
+ }
+ if (VariableEntry->VariableSize > RemainingVariableStorageSize) {
+ //
+ // No enough space for Variable[Index].
+ //
+ VA_END (Args);
+ return FALSE;
+ }
+ //
+ // Sub the (new) size of Variable[Index] from remaining variable storage size.
+ //
+ RemainingVariableStorageSize -= VariableEntry->VariableSize;
+ VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
+ }
+ VA_END (Args);
+
+ return TRUE;
+}
+
+/**
Hook the operations in PlatformLangCodes, LangCodes, PlatformLang and Lang.
When setting Lang/LangCodes, simultaneously update PlatformLang/PlatformLangCodes.
@@ -1292,6 +1407,9 @@ AutoUpdateLangVariable (
UINT32 Attributes;
VARIABLE_POINTER_TRACK Variable;
BOOLEAN SetLanguageCodes;
+ UINTN VarNameSize;
+ UINTN VarDataSize;
+ VARIABLE_ENTRY_CONSISTENCY VariableEntry[2];
//
// Don't do updates for delete operation
@@ -1414,14 +1532,39 @@ AutoUpdateLangVariable (
BestLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->LangCodes, Index, TRUE);
//
- // Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.
+ // Calculate the needed variable size for Lang variable.
+ //
+ VarNameSize = StrSize (EFI_LANG_VARIABLE_NAME);
+ VarDataSize = ISO_639_2_ENTRY_SIZE + 1;
+ VariableEntry[0].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
+ VariableEntry[0].VariableSize = HEADER_ALIGN (VariableEntry[0].VariableSize);
+ VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
+ VariableEntry[0].Name = EFI_LANG_VARIABLE_NAME;
//
- FindVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
+ // Calculate the needed variable size for PlatformLang variable.
+ //
+ VarNameSize = StrSize (EFI_PLATFORM_LANG_VARIABLE_NAME);
+ VarDataSize = AsciiStrSize (BestPlatformLang);
+ VariableEntry[1].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
+ VariableEntry[1].VariableSize = HEADER_ALIGN (VariableEntry[1].VariableSize);
+ VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
+ VariableEntry[1].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;
+ if (!CheckRemainingSpaceForConsistency (VARIABLE_ATTRIBUTE_NV_BS_RT, &VariableEntry[0], &VariableEntry[1], NULL)) {
+ //
+ // No enough variable space to set both Lang and PlatformLang successfully.
+ //
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ //
+ // Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.
+ //
+ FindVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
- Status = UpdateVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestLang,
- ISO_639_2_ENTRY_SIZE + 1, Attributes, &Variable);
+ Status = UpdateVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestLang,
+ ISO_639_2_ENTRY_SIZE + 1, Attributes, &Variable);
+ }
- DEBUG ((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a: Status: %r\n", BestPlatformLang, BestLang, Status));
+ DEBUG ((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a Status: %r\n", BestPlatformLang, BestLang, Status));
}
}
@@ -1446,19 +1589,51 @@ AutoUpdateLangVariable (
BestPlatformLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->PlatformLangCodes, Index, FALSE);
//
- // Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.
+ // Calculate the needed variable size for PlatformLang variable.
+ //
+ VarNameSize = StrSize (EFI_PLATFORM_LANG_VARIABLE_NAME);
+ VarDataSize = AsciiStrSize (BestPlatformLang);
+ VariableEntry[0].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
+ VariableEntry[0].VariableSize = HEADER_ALIGN (VariableEntry[0].VariableSize);
+ VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
+ VariableEntry[0].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;
+ //
+ // Calculate the needed variable size for Lang variable.
//
- FindVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
+ VarNameSize = StrSize (EFI_LANG_VARIABLE_NAME);
+ VarDataSize = ISO_639_2_ENTRY_SIZE + 1;
+ VariableEntry[1].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
+ VariableEntry[1].VariableSize = HEADER_ALIGN (VariableEntry[1].VariableSize);
+ VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
+ VariableEntry[1].Name = EFI_LANG_VARIABLE_NAME;
+ if (!CheckRemainingSpaceForConsistency (VARIABLE_ATTRIBUTE_NV_BS_RT, &VariableEntry[0], &VariableEntry[1], NULL)) {
+ //
+ // No enough variable space to set both PlatformLang and Lang successfully.
+ //
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ //
+ // Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.
+ //
+ FindVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
- Status = UpdateVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestPlatformLang,
- AsciiStrSize (BestPlatformLang), Attributes, &Variable);
+ Status = UpdateVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestPlatformLang,
+ AsciiStrSize (BestPlatformLang), Attributes, &Variable);
+ }
DEBUG ((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a Status: %r\n", BestLang, BestPlatformLang, Status));
}
}
}
- return Status;
+ if (SetLanguageCodes) {
+ //
+ // Continue to set PlatformLangCodes or LangCodes.
+ //
+ return EFI_SUCCESS;
+ } else {
+ return Status;
+ }
}
/**
@@ -2492,15 +2667,17 @@ VariableServiceSetVariable (
}
}
- //
- // Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang.
- //
- Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
- if (EFI_ERROR (Status)) {
+ if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
//
- // The auto update operation failed, directly return to avoid inconsistency between PlatformLang and Lang.
+ // Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang.
//
- goto Done;
+ Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
+ if (EFI_ERROR (Status)) {
+ //
+ // The auto update operation failed, directly return to avoid inconsistency between PlatformLang and Lang.
+ //
+ goto Done;
+ }
}
Status = UpdateVariable (VariableName, VendorGuid, Data, DataSize, Attributes, &Variable);
@@ -2525,14 +2702,12 @@ Done:
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
associated with the attributes specified.
- @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
@return EFI_SUCCESS Query successfully.
- @return EFI_UNSUPPORTED The attribute is not supported on this platform.
**/
EFI_STATUS
EFIAPI
-VariableServiceQueryVariableInfo (
+VariableServiceQueryVariableInfoInternal (
IN UINT32 Attributes,
OUT UINT64 *MaximumVariableStorageSize,
OUT UINT64 *RemainingVariableStorageSize,
@@ -2545,43 +2720,12 @@ VariableServiceQueryVariableInfo (
VARIABLE_STORE_HEADER *VariableStoreHeader;
UINT64 CommonVariableTotalSize;
UINT64 HwErrVariableTotalSize;
+ EFI_STATUS Status;
+ VARIABLE_POINTER_TRACK VariablePtrTrack;
CommonVariableTotalSize = 0;
HwErrVariableTotalSize = 0;
- if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {
- return EFI_INVALID_PARAMETER;
- }
-
- if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == 0) {
- //
- // Make sure the Attributes combination is supported by the platform.
- //
- return EFI_UNSUPPORTED;
- } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {
- //
- // Make sure if runtime bit is set, boot service bit is set also.
- //
- return EFI_INVALID_PARAMETER;
- } else if (AtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) {
- //
- // Make sure RT Attribute is set if we are in Runtime phase.
- //
- return EFI_INVALID_PARAMETER;
- } else if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
- //
- // Make sure Hw Attribute is set with NV.
- //
- return EFI_INVALID_PARAMETER;
- } else if ((Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) != 0) {
- //
- // Not support authentiated variable write yet.
- //
- return EFI_UNSUPPORTED;
- }
-
- AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
-
if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {
//
// Query is Volatile related.
@@ -2653,6 +2797,27 @@ VariableServiceQueryVariableInfo (
} else {
CommonVariableTotalSize += VariableSize;
}
+ } else if (Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
+ //
+ // If it is a IN_DELETED_TRANSITION variable,
+ // and there is not also a same ADDED one at the same time,
+ // this IN_DELETED_TRANSITION variable is valid.
+ //
+ VariablePtrTrack.StartPtr = GetStartPointer (VariableStoreHeader);
+ VariablePtrTrack.EndPtr = GetEndPointer (VariableStoreHeader);
+ Status = FindVariableEx (
+ GetVariableNamePtr (Variable),
+ &Variable->VendorGuid,
+ FALSE,
+ &VariablePtrTrack
+ );
+ if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State != VAR_ADDED) {
+ if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
+ HwErrVariableTotalSize += VariableSize;
+ } else {
+ CommonVariableTotalSize += VariableSize;
+ }
+ }
}
}
@@ -2674,10 +2839,81 @@ VariableServiceQueryVariableInfo (
*MaximumVariableSize = *RemainingVariableStorageSize - sizeof (VARIABLE_HEADER);
}
- ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
return EFI_SUCCESS;
}
+/**
+
+ This code returns information about the EFI variables.
+
+ @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
+ for the EFI variables associated with the attributes specified.
+ @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
+ for EFI variables associated with the attributes specified.
+ @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
+ associated with the attributes specified.
+
+ @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
+ @return EFI_SUCCESS Query successfully.
+ @return EFI_UNSUPPORTED The attribute is not supported on this platform.
+
+**/
+EFI_STATUS
+EFIAPI
+VariableServiceQueryVariableInfo (
+ IN UINT32 Attributes,
+ OUT UINT64 *MaximumVariableStorageSize,
+ OUT UINT64 *RemainingVariableStorageSize,
+ OUT UINT64 *MaximumVariableSize
+ )
+{
+ EFI_STATUS Status;
+
+ if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == 0) {
+ //
+ // Make sure the Attributes combination is supported by the platform.
+ //
+ return EFI_UNSUPPORTED;
+ } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {
+ //
+ // Make sure if runtime bit is set, boot service bit is set also.
+ //
+ return EFI_INVALID_PARAMETER;
+ } else if (AtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) {
+ //
+ // Make sure RT Attribute is set if we are in Runtime phase.
+ //
+ return EFI_INVALID_PARAMETER;
+ } else if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
+ //
+ // Make sure Hw Attribute is set with NV.
+ //
+ return EFI_INVALID_PARAMETER;
+ } else if ((Attributes & (EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | EFI_VARIABLE_APPEND_WRITE)) != 0) {
+ //
+ // Not support authenticated or append variable write yet.
+ //
+ return EFI_UNSUPPORTED;
+ }
+
+ AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
+
+ Status = VariableServiceQueryVariableInfoInternal (
+ Attributes,
+ MaximumVariableStorageSize,
+ RemainingVariableStorageSize,
+ MaximumVariableSize
+ );
+
+ ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
+ return Status;
+}
/**
This function reclaims variable storage if free size is below the threshold.
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
index 9c8626cdc4..fa78e4414b 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
@@ -3,7 +3,7 @@
The internal header file includes the common header files, defines
internal structure and functions used by Variable modules.
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2014, 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
@@ -101,10 +101,12 @@ typedef struct {
typedef struct {
EFI_GUID *Guid;
CHAR16 *Name;
- UINT32 Attributes;
- UINTN DataSize;
- VOID *Data;
-} VARIABLE_CACHE_ENTRY;
+// UINT32 Attributes;
+ //
+ // Variable size include variable header, name and data.
+ //
+ UINTN VariableSize;
+} VARIABLE_ENTRY_CONSISTENCY;
typedef struct {
EFI_GUID Guid;
@@ -456,6 +458,31 @@ VariableServiceSetVariable (
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
associated with the attributes specified.
+ @return EFI_SUCCESS Query successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+VariableServiceQueryVariableInfoInternal (
+ IN UINT32 Attributes,
+ OUT UINT64 *MaximumVariableStorageSize,
+ OUT UINT64 *RemainingVariableStorageSize,
+ OUT UINT64 *MaximumVariableSize
+ );
+
+/**
+
+ This code returns information about the EFI variables.
+
+ @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
+ for the EFI variables associated with the attributes specified.
+ @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
+ for EFI variables associated with the attributes specified.
+ @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
+ associated with the attributes specified.
+
@return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
@return EFI_SUCCESS Query successfully.
@return EFI_UNSUPPORTED The attribute is not supported on this platform.
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
index c712ba0200..297a6da5a5 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
@@ -2,7 +2,7 @@
# Component description file for Variable module.
#
# This module installs three EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName.
-# Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2006 - 2014, 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
@@ -80,7 +80,8 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
[FeaturePcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## SOMETIME_CONSUMES (statistic the information of variable.)
+ gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## CONSUMES # statistic the information of variable.
+ gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate ## CONSUMES
[Depex]
TRUE
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
index 36436b6db8..1448240d1b 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
@@ -14,7 +14,7 @@
# This external input must be validated carefully to avoid security issue like
# buffer overflow, integer overflow.
#
-# Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2010 - 2014, 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
@@ -89,7 +89,8 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
[FeaturePcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## SOMETIME_CONSUMES (statistic the information of variable.)
+ gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## CONSUMES # statistic the information of variable.
+ gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate ## CONSUMES
[Depex]
TRUE
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
index d9e8809e55..33cad23a01 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
@@ -941,6 +941,7 @@ PeCoffLoaderRelocateImage (
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
EFI_IMAGE_DATA_DIRECTORY *RelocDir;
UINT64 Adjust;
+ EFI_IMAGE_BASE_RELOCATION *RelocBaseOrg;
EFI_IMAGE_BASE_RELOCATION *RelocBase;
EFI_IMAGE_BASE_RELOCATION *RelocBaseEnd;
UINT16 *Reloc;
@@ -1041,7 +1042,8 @@ PeCoffLoaderRelocateImage (
RelocDir->VirtualAddress + RelocDir->Size - 1,
TeStrippedOffset
);
- if (RelocBase == NULL || RelocBaseEnd == NULL) {
+ if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd < RelocBase) {
+ ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
return RETURN_LOAD_ERROR;
}
} else {
@@ -1050,6 +1052,7 @@ PeCoffLoaderRelocateImage (
//
RelocBase = RelocBaseEnd = NULL;
}
+ RelocBaseOrg = RelocBase;
//
// If Adjust is not zero, then apply fix ups to the image
@@ -1065,14 +1068,23 @@ PeCoffLoaderRelocateImage (
//
// Add check for RelocBase->SizeOfBlock field.
//
- if ((RelocBase->SizeOfBlock == 0) || (RelocBase->SizeOfBlock > RelocDir->Size)) {
+ if (RelocBase->SizeOfBlock == 0) {
+ ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
+ return RETURN_LOAD_ERROR;
+ }
+ if ((UINTN)RelocBase > MAX_ADDRESS - RelocBase->SizeOfBlock) {
ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
return RETURN_LOAD_ERROR;
}
RelocEnd = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock);
+ if ((UINTN)RelocEnd > (UINTN)RelocBaseOrg + RelocDir->Size) {
+ ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
+ return RETURN_LOAD_ERROR;
+ }
FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress, TeStrippedOffset);
if (FixupBase == NULL) {
+ ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
return RETURN_LOAD_ERROR;
}
@@ -1080,8 +1092,11 @@ PeCoffLoaderRelocateImage (
// Run this relocation record
//
while (Reloc < RelocEnd) {
-
- Fixup = FixupBase + (*Reloc & 0xFFF);
+ Fixup = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress + (*Reloc & 0xFFF), TeStrippedOffset);
+ if (Fixup == NULL) {
+ ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
+ return RETURN_LOAD_ERROR;
+ }
switch ((*Reloc) >> 12) {
case EFI_IMAGE_REL_BASED_ABSOLUTE:
break;
@@ -1148,6 +1163,7 @@ PeCoffLoaderRelocateImage (
//
RelocBase = (EFI_IMAGE_BASE_RELOCATION *) RelocEnd;
}
+ ASSERT ((UINTN)FixupData <= (UINTN)ImageContext->FixupData + ImageContext->FixupDataSize);
//
// Adjust the EntryPoint to match the linked-to address
@@ -1444,14 +1460,17 @@ PeCoffLoaderLoadImage (
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC];
}
+ //
+ // Must use UINT64 here, because there might a case that 32bit loader to load 64bit image.
+ //
if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {
- ImageContext->FixupDataSize = DirectoryEntry->Size / sizeof (UINT16) * sizeof (UINTN);
+ ImageContext->FixupDataSize = DirectoryEntry->Size / sizeof (UINT16) * sizeof (UINT64);
} else {
ImageContext->FixupDataSize = 0;
}
} else {
DirectoryEntry = &Hdr.Te->DataDirectory[0];
- ImageContext->FixupDataSize = DirectoryEntry->Size / sizeof (UINT16) * sizeof (UINTN);
+ ImageContext->FixupDataSize = DirectoryEntry->Size / sizeof (UINT16) * sizeof (UINT64);
}
//
// Consumer must allocate a buffer for the relocation fixup log.
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index affff516ef..4daf3e6a75 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -1375,7 +1375,8 @@
## If TRUE, the driver diagnostics2 protocol will not be installed.
gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|FALSE|BOOLEAN|0x00000011
- ## Indicates whether EFI 1.1 ISO 639-2 language supports are obsolete
+ ## Indicates whether EFI 1.1 ISO 639-2 language supports are obsolete.
+ # If TRUE, Variable driver will be also not to auto update between PlatformLang and Lang variables.
gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate|FALSE|BOOLEAN|0x00000012
## If TRUE, UGA Draw Protocol is still consumed.
diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
index e7e70512e8..0a01050a8c 100644
--- a/SecurityPkg/SecurityPkg.dsc
+++ b/SecurityPkg/SecurityPkg.dsc
@@ -163,7 +163,7 @@
SecurityPkg/Library/HashLibTpm2/HashLibTpm2.inf
[Components.IA32, Components.X64, Components.IPF]
- SecurityPkg/UserIdentification/PwdCredentialProviderDxe/PwdCredentialProviderDxe.inf
+# SecurityPkg/UserIdentification/PwdCredentialProviderDxe/PwdCredentialProviderDxe.inf
# SecurityPkg/UserIdentification/UsbCredentialProviderDxe/UsbCredentialProviderDxe.inf
SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableRuntimeDxe.inf
diff --git a/SecurityPkg/Tcg/TrEEConfig/TpmDetection.c b/SecurityPkg/Tcg/TrEEConfig/TpmDetection.c
index b8aab1ffd1..ce7a9a1974 100644
--- a/SecurityPkg/Tcg/TrEEConfig/TpmDetection.c
+++ b/SecurityPkg/Tcg/TrEEConfig/TpmDetection.c
@@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <PiPei.h>
+#include <Ppi/ReadOnlyVariable2.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
@@ -64,25 +65,47 @@ DetectTpmDevice (
{
EFI_STATUS Status;
EFI_BOOT_MODE BootMode;
+ TREE_DEVICE_DETECTION TrEEDeviceDetection;
+ EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi;
+ UINTN Size;
+
+ if (PcdGetBool (PcdHideTpmSupport) && PcdGetBool (PcdHideTpm)) {
+ DEBUG ((EFI_D_ERROR, "DetectTpmDevice: Tpm is hide\n"));
+ return TPM_DEVICE_NULL;
+ }
Status = PeiServicesGetBootMode (&BootMode);
ASSERT_EFI_ERROR (Status);
//
- // In S3, we rely on Setup option, because we save to Setup in normal boot.
+ // In S3, we rely on normal boot Detection, because we save to ReadOnly Variable in normal boot.
//
if (BootMode == BOOT_ON_S3_RESUME) {
DEBUG ((EFI_D_ERROR, "DetectTpmDevice: S3 mode\n"));
- return SetupTpmDevice;
- }
- if (PcdGetBool (PcdHideTpmSupport) && PcdGetBool (PcdHideTpm)) {
- DEBUG ((EFI_D_ERROR, "DetectTpmDevice: Tpm is hide\n"));
- return TPM_DEVICE_NULL;
+ Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, (VOID **) &VariablePpi);
+ ASSERT_EFI_ERROR (Status);
+
+ Size = sizeof(TREE_DEVICE_DETECTION);
+ ZeroMem (&TrEEDeviceDetection, sizeof(TrEEDeviceDetection));
+ Status = VariablePpi->GetVariable (
+ VariablePpi,
+ TREE_DEVICE_DETECTION_NAME,
+ &gTrEEConfigFormSetGuid,
+ NULL,
+ &Size,
+ &TrEEDeviceDetection
+ );
+ if (!EFI_ERROR (Status) &&
+ (TrEEDeviceDetection.TpmDeviceDetected >= TPM_DEVICE_MIN) &&
+ (TrEEDeviceDetection.TpmDeviceDetected <= TPM_DEVICE_MAX)) {
+ DEBUG ((EFI_D_ERROR, "TpmDevice from DeviceDetection: %x\n", TrEEDeviceDetection.TpmDeviceDetected));
+ return TrEEDeviceDetection.TpmDeviceDetected;
+ }
}
DEBUG ((EFI_D_ERROR, "DetectTpmDevice:\n"));
- if ((!IsDtpmPresent ()) || (SetupTpmDevice == TPM_DEVICE_NULL)) {
+ if (!IsDtpmPresent ()) {
// dTPM not available
return TPM_DEVICE_NULL;
}
@@ -96,7 +119,11 @@ DetectTpmDevice (
return TPM_DEVICE_2_0_DTPM;
}
- Status = Tpm12Startup (TPM_ST_CLEAR);
+ if (BootMode == BOOT_ON_S3_RESUME) {
+ Status = Tpm12Startup (TPM_ST_STATE);
+ } else {
+ Status = Tpm12Startup (TPM_ST_CLEAR);
+ }
if (EFI_ERROR (Status)) {
return TPM_DEVICE_2_0_DTPM;
}
diff --git a/SecurityPkg/Tcg/TrEEConfig/TrEEConfig.vfr b/SecurityPkg/Tcg/TrEEConfig/TrEEConfig.vfr
index 74e2363199..84b55a9f15 100644
--- a/SecurityPkg/Tcg/TrEEConfig/TrEEConfig.vfr
+++ b/SecurityPkg/Tcg/TrEEConfig/TrEEConfig.vfr
@@ -20,8 +20,9 @@ formset
help = STRING_TOKEN(STR_TREE_HELP),
classguid = EFI_HII_PLATFORM_SETUP_FORMSET_GUID,
- varstore TREE_CONFIGURATION,
+ efivarstore TREE_CONFIGURATION,
varid = TREE_CONFIGURATION_VARSTORE_ID,
+ attribute = 0x03, // EFI variable attribures EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE
name = TREE_CONFIGURATION,
guid = TREE_CONFIG_FORM_SET_GUID;
@@ -40,7 +41,6 @@ formset
prompt = STRING_TOKEN(STR_TREE_DEVICE_PROMPT),
help = STRING_TOKEN(STR_TREE_DEVICE_HELP),
flags = INTERACTIVE,
- option text = STRING_TOKEN(STR_TREE_TPM_DISABLE), value = TPM_DEVICE_NULL, flags = RESET_REQUIRED;
option text = STRING_TOKEN(STR_TREE_TPM_1_2), value = TPM_DEVICE_1_2, flags = DEFAULT | MANUFACTURING | RESET_REQUIRED;
option text = STRING_TOKEN(STR_TREE_TPM_2_0_DTPM), value = TPM_DEVICE_2_0_DTPM, flags = RESET_REQUIRED;
endoneof;
@@ -52,10 +52,11 @@ formset
subtitle text = STRING_TOKEN(STR_NULL);
subtitle text = STRING_TOKEN(STR_TREE_PP_OPERATION);
- oneof varid = TREE_CONFIGURATION.Tpm2Operation,
+ oneof name = Tpm2Operation,
+ questionid = KEY_TPM2_OPERATION,
prompt = STRING_TOKEN(STR_TREE_OPERATION),
help = STRING_TOKEN(STR_TREE_OPERATION_HELP),
- flags = INTERACTIVE,
+ flags = INTERACTIVE | NUMERIC_SIZE_1,
option text = STRING_TOKEN(STR_TREE_NO_ACTION), value = TREE_PHYSICAL_PRESENCE_NO_ACTION, flags = DEFAULT | MANUFACTURING | RESET_REQUIRED;
option text = STRING_TOKEN(STR_TREE_CLEAR), value = TREE_PHYSICAL_PRESENCE_CLEAR_CONTROL_CLEAR, flags = RESET_REQUIRED;
endoneof;
diff --git a/SecurityPkg/Tcg/TrEEConfig/TrEEConfigDriver.c b/SecurityPkg/Tcg/TrEEConfig/TrEEConfigDriver.c
index 74b5e7ee25..2ad02c05a6 100644
--- a/SecurityPkg/Tcg/TrEEConfig/TrEEConfigDriver.c
+++ b/SecurityPkg/Tcg/TrEEConfig/TrEEConfigDriver.c
@@ -38,8 +38,10 @@ TrEEConfigDriverEntryPoint (
EFI_STATUS Status;
TREE_CONFIG_PRIVATE_DATA *PrivateData;
TREE_CONFIGURATION TrEEConfiguration;
+ TREE_DEVICE_DETECTION TrEEDeviceDetection;
UINTN Index;
UINTN DataSize;
+ EDKII_VARIABLE_LOCK_PROTOCOL *VariableLockProtocol;
Status = gBS->OpenProtocol (
ImageHandle,
@@ -79,37 +81,80 @@ TrEEConfigDriverEntryPoint (
&TrEEConfiguration
);
if (EFI_ERROR (Status)) {
+ //
+ // Variable not ready, set default value
+ //
+ TrEEConfiguration.TpmDevice = TPM_DEVICE_DEFAULT;
}
+
//
- // We should always reinit PP request.
+ // Validation
//
- TrEEConfiguration.Tpm2Operation = TREE_PHYSICAL_PRESENCE_NO_ACTION;
+ if ((TrEEConfiguration.TpmDevice > TPM_DEVICE_MAX) || (TrEEConfiguration.TpmDevice < TPM_DEVICE_MIN)) {
+ TrEEConfiguration.TpmDevice = TPM_DEVICE_DEFAULT;
+ }
//
- // Sync data from PCD to variable, so that we do not need detect again in S3 phase.
+ // Save to variable so platform driver can get it.
//
+ Status = gRT->SetVariable (
+ TREE_STORAGE_NAME,
+ &gTrEEConfigFormSetGuid,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
+ sizeof(TrEEConfiguration),
+ &TrEEConfiguration
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((EFI_D_ERROR, "TrEEConfigDriver: Fail to set TREE_STORAGE_NAME\n"));
+ }
//
- // Get data from PCD to make sure data consistant - platform driver is suppose to construct this PCD accroding to Variable
+ // Sync data from PCD to variable, so that we do not need detect again in S3 phase.
//
+ TrEEDeviceDetection.TpmDeviceDetected = TPM_DEVICE_NULL;
for (Index = 0; Index < sizeof(mTpmInstanceId)/sizeof(mTpmInstanceId[0]); Index++) {
if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &mTpmInstanceId[Index].TpmInstanceGuid)) {
- TrEEConfiguration.TpmDevice = mTpmInstanceId[Index].TpmDevice;
+ TrEEDeviceDetection.TpmDeviceDetected = mTpmInstanceId[Index].TpmDevice;
break;
}
}
+ PrivateData->TpmDeviceDetected = TrEEDeviceDetection.TpmDeviceDetected;
+
//
// Save to variable so platform driver can get it.
//
Status = gRT->SetVariable (
- TREE_STORAGE_NAME,
+ TREE_DEVICE_DETECTION_NAME,
&gTrEEConfigFormSetGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
- sizeof(TrEEConfiguration),
- &TrEEConfiguration
+ sizeof(TrEEDeviceDetection),
+ &TrEEDeviceDetection
);
- ASSERT_EFI_ERROR (Status);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((EFI_D_ERROR, "TrEEConfigDriver: Fail to set TREE_DEVICE_DETECTION_NAME\n"));
+ Status = gRT->SetVariable (
+ TREE_DEVICE_DETECTION_NAME,
+ &gTrEEConfigFormSetGuid,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
+ 0,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+ }
+
+ //
+ // We should lock TrEEDeviceDetection, because it contains information needed at S3.
+ //
+ Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **)&VariableLockProtocol);
+ if (!EFI_ERROR (Status)) {
+ Status = VariableLockProtocol->RequestToLock (
+ VariableLockProtocol,
+ TREE_DEVICE_DETECTION_NAME,
+ &gTrEEConfigFormSetGuid
+ );
+ ASSERT_EFI_ERROR (Status);
+ }
//
// Install TrEE configuration form
diff --git a/SecurityPkg/Tcg/TrEEConfig/TrEEConfigDxe.inf b/SecurityPkg/Tcg/TrEEConfig/TrEEConfigDxe.inf
index 0878fb6518..042ad878d6 100644
--- a/SecurityPkg/Tcg/TrEEConfig/TrEEConfigDxe.inf
+++ b/SecurityPkg/Tcg/TrEEConfig/TrEEConfigDxe.inf
@@ -62,6 +62,7 @@
[Protocols]
gEfiHiiConfigAccessProtocolGuid ## PRODUCES
gEfiHiiConfigRoutingProtocolGuid ## CONSUMES
+ gEdkiiVariableLockProtocolGuid ## CONSUMES
[Pcd]
gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid
diff --git a/SecurityPkg/Tcg/TrEEConfig/TrEEConfigImpl.c b/SecurityPkg/Tcg/TrEEConfig/TrEEConfigImpl.c
index 0df99d607e..2748505fec 100644
--- a/SecurityPkg/Tcg/TrEEConfig/TrEEConfigImpl.c
+++ b/SecurityPkg/Tcg/TrEEConfig/TrEEConfigImpl.c
@@ -86,96 +86,7 @@ TrEEExtractConfig (
OUT EFI_STRING *Results
)
{
- EFI_STATUS Status;
- UINTN BufferSize;
- TREE_CONFIGURATION Configuration;
- TREE_CONFIG_PRIVATE_DATA *PrivateData;
- EFI_STRING ConfigRequestHdr;
- EFI_STRING ConfigRequest;
- BOOLEAN AllocatedRequest;
- UINTN Size;
- UINTN Index;
-
- if (Progress == NULL || Results == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- *Progress = Request;
- if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gTrEEConfigFormSetGuid, TREE_STORAGE_NAME)) {
- return EFI_NOT_FOUND;
- }
-
- ConfigRequestHdr = NULL;
- ConfigRequest = NULL;
- AllocatedRequest = FALSE;
- Size = 0;
-
- PrivateData = TREE_CONFIG_PRIVATE_DATA_FROM_THIS (This);
-
- //
- // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
- //
- BufferSize = sizeof (Configuration);
- Status = gRT->GetVariable (
- TREE_STORAGE_NAME,
- &gTrEEConfigFormSetGuid,
- NULL,
- &BufferSize,
- &Configuration
- );
- ASSERT_EFI_ERROR (Status);
-
- //
- // Get data from PCD to make sure data consistant - platform driver is suppose to construct this PCD accroding to Variable
- //
- for (Index = 0; Index < sizeof(mTpmInstanceId)/sizeof(mTpmInstanceId[0]); Index++) {
- if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &mTpmInstanceId[Index].TpmInstanceGuid)) {
- Configuration.TpmDevice = mTpmInstanceId[Index].TpmDevice;
- break;
- }
- }
-
- BufferSize = sizeof (Configuration);
- ConfigRequest = Request;
- if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
- //
- // Request has no request element, construct full request string.
- // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
- // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
- //
- ConfigRequestHdr = HiiConstructConfigHdr (&gTrEEConfigFormSetGuid, TREE_STORAGE_NAME, PrivateData->DriverHandle);
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
- ASSERT (ConfigRequest != NULL);
- AllocatedRequest = TRUE;
- UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64) BufferSize);
- FreePool (ConfigRequestHdr);
- }
-
- Status = gHiiConfigRouting->BlockToConfig (
- gHiiConfigRouting,
- ConfigRequest,
- (UINT8 *) &Configuration,
- BufferSize,
- Results,
- Progress
- );
- //
- // Free the allocated config request string.
- //
- if (AllocatedRequest) {
- FreePool (ConfigRequest);
- }
- //
- // Set Progress string to the original request string.
- //
- if (Request == NULL) {
- *Progress = NULL;
- } else if (StrStr (Request, L"OFFSET") == NULL) {
- *Progress = Request + StrLen (Request);
- }
-
- return Status;
+ return EFI_UNSUPPORTED;
}
/**
@@ -252,59 +163,7 @@ TrEERouteConfig (
OUT EFI_STRING *Progress
)
{
- EFI_STATUS Status;
- UINTN BufferSize;
- TREE_CONFIGURATION TrEEConfiguration;
-
- if (Configuration == NULL || Progress == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- *Progress = Configuration;
- if (!HiiIsConfigHdrMatch (Configuration, &gTrEEConfigFormSetGuid, TREE_STORAGE_NAME)) {
- return EFI_NOT_FOUND;
- }
-
- BufferSize = sizeof (TrEEConfiguration);
- Status = gRT->GetVariable (
- TREE_STORAGE_NAME,
- &gTrEEConfigFormSetGuid,
- NULL,
- &BufferSize,
- &TrEEConfiguration
- );
- ASSERT_EFI_ERROR (Status);
-
- //
- // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
- //
- BufferSize = sizeof (TREE_CONFIGURATION);
- Status = gHiiConfigRouting->ConfigToBlock (
- gHiiConfigRouting,
- Configuration,
- (UINT8 *) &TrEEConfiguration,
- &BufferSize,
- Progress
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Save to variable so platform driver can get it.
- //
- Status = gRT->SetVariable (
- TREE_STORAGE_NAME,
- &gTrEEConfigFormSetGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
- sizeof(TrEEConfiguration),
- &TrEEConfiguration
- );
-
- SaveTrEEPpRequest (TrEEConfiguration.Tpm2Operation
- );
-
- return Status;
+ return EFI_UNSUPPORTED;
}
/**
@@ -343,13 +202,17 @@ TrEECallback (
if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {
return EFI_INVALID_PARAMETER;
}
-
- if ((Action != EFI_BROWSER_ACTION_CHANGED) ||
- (QuestionId != KEY_TPM_DEVICE)) {
- return EFI_UNSUPPORTED;
+
+ if (Action == EFI_BROWSER_ACTION_CHANGED) {
+ if (QuestionId == KEY_TPM_DEVICE) {
+ return EFI_SUCCESS;
+ }
+ if (QuestionId == KEY_TPM2_OPERATION) {
+ return SaveTrEEPpRequest (Value->u8);
+ }
}
- return EFI_SUCCESS;
+ return EFI_UNSUPPORTED;
}
/**
@@ -413,6 +276,24 @@ InstallTrEEConfigForm (
PrivateData->HiiHandle = HiiHandle;
+ //
+ // Update static data
+ //
+ switch (PrivateData->TpmDeviceDetected) {
+ case TPM_DEVICE_NULL:
+ HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TREE_DEVICE_STATE_CONTENT), L"Not Found", NULL);
+ break;
+ case TPM_DEVICE_1_2:
+ HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TREE_DEVICE_STATE_CONTENT), L"TPM 1.2", NULL);
+ break;
+ case TPM_DEVICE_2_0_DTPM:
+ HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TREE_DEVICE_STATE_CONTENT), L"TPM 2.0 (DTPM)", NULL);
+ break;
+ default:
+ HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TREE_DEVICE_STATE_CONTENT), L"Unknown", NULL);
+ break;
+ }
+
return EFI_SUCCESS;
}
diff --git a/SecurityPkg/Tcg/TrEEConfig/TrEEConfigImpl.h b/SecurityPkg/Tcg/TrEEConfig/TrEEConfigImpl.h
index 0d62c831de..720c698e7a 100644
--- a/SecurityPkg/Tcg/TrEEConfig/TrEEConfigImpl.h
+++ b/SecurityPkg/Tcg/TrEEConfig/TrEEConfigImpl.h
@@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/HiiConfigAccess.h>
#include <Protocol/HiiConfigRouting.h>
#include <Protocol/TrEEProtocol.h>
+#include <Protocol/VariableLock.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
@@ -60,6 +61,7 @@ typedef struct {
EFI_HII_HANDLE HiiHandle;
EFI_HANDLE DriverHandle;
+ UINT8 TpmDeviceDetected;
} TREE_CONFIG_PRIVATE_DATA;
extern TREE_CONFIG_PRIVATE_DATA mTrEEConfigPrivateDateTemplate;
diff --git a/SecurityPkg/Tcg/TrEEConfig/TrEEConfigNvData.h b/SecurityPkg/Tcg/TrEEConfig/TrEEConfigNvData.h
index cb9f5a818e..14e5d926a1 100644
--- a/SecurityPkg/Tcg/TrEEConfig/TrEEConfigNvData.h
+++ b/SecurityPkg/Tcg/TrEEConfig/TrEEConfigNvData.h
@@ -23,22 +23,32 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#define TREE_CONFIGURATION_FORM_ID 0x0001
#define KEY_TPM_DEVICE 0x2000
+#define KEY_TPM2_OPERATION 0x2001
#define TPM_DEVICE_NULL 0
#define TPM_DEVICE_1_2 1
#define TPM_DEVICE_2_0_DTPM 2
+#define TPM_DEVICE_MIN TPM_DEVICE_1_2
#define TPM_DEVICE_MAX TPM_DEVICE_2_0_DTPM
#define TPM_DEVICE_DEFAULT TPM_DEVICE_1_2
//
-// Nv Data structure referenced by IFR
+// Nv Data structure referenced by IFR, TPM device user desired
//
typedef struct {
UINT8 TpmDevice;
- UINT8 Tpm2Operation;
} TREE_CONFIGURATION;
+//
+// Variable saved for S3, TPM detected, only valid in S3 path.
+// This variable is ReadOnly.
+//
+typedef struct {
+ UINT8 TpmDeviceDetected;
+} TREE_DEVICE_DETECTION;
+
#define TREE_STORAGE_NAME L"TREE_CONFIGURATION"
+#define TREE_DEVICE_DETECTION_NAME L"TREE_DEVICE_DETECTION"
#define TPM_INSTANCE_ID_LIST { \
{TPM_DEVICE_INTERFACE_NONE, TPM_DEVICE_NULL}, \
diff --git a/SecurityPkg/Tcg/TrEEConfig/TrEEConfigPeim.c b/SecurityPkg/Tcg/TrEEConfig/TrEEConfigPeim.c
index 77d640dd44..9c1e917ab4 100644
--- a/SecurityPkg/Tcg/TrEEConfig/TrEEConfigPeim.c
+++ b/SecurityPkg/Tcg/TrEEConfig/TrEEConfigPeim.c
@@ -94,8 +94,8 @@ TrEEConfigPeimEntryPoint (
//
// Validation
//
- if (TrEEConfiguration.TpmDevice > TPM_DEVICE_MAX) {
- TrEEConfiguration.TpmDevice = TPM_DEVICE_DEFAULT;
+ if ((TrEEConfiguration.TpmDevice > TPM_DEVICE_MAX) || (TrEEConfiguration.TpmDevice < TPM_DEVICE_MIN)) {
+ TrEEConfiguration.TpmDevice = TPM_DEVICE_DEFAULT;
}
//
@@ -105,8 +105,12 @@ TrEEConfigPeimEntryPoint (
if (PcdGetBool (PcdTpmAutoDetection)) {
TpmDevice = DetectTpmDevice (TrEEConfiguration.TpmDevice);
- DEBUG ((EFI_D_ERROR, "TrEEConfiguration.TpmDevice final: %x\n", TpmDevice));
- TrEEConfiguration.TpmDevice = TpmDevice;
+ DEBUG ((EFI_D_ERROR, "TpmDevice final: %x\n", TpmDevice));
+ if (TpmDevice != TPM_DEVICE_NULL) {
+ TrEEConfiguration.TpmDevice = TpmDevice;
+ }
+ } else {
+ TpmDevice = TrEEConfiguration.TpmDevice;
}
//
@@ -114,11 +118,14 @@ TrEEConfigPeimEntryPoint (
// This is work-around because there is no gurantee DynamicHiiPcd can return correct value in DXE phase.
// Using DynamicPcd instead.
//
+ // NOTE: TrEEConfiguration variable contains the desired TpmDevice type,
+ // while PcdTpmInstanceGuid PCD contains the real detected TpmDevice type
+ //
for (Index = 0; Index < sizeof(mTpmInstanceId)/sizeof(mTpmInstanceId[0]); Index++) {
- if (TrEEConfiguration.TpmDevice == mTpmInstanceId[Index].TpmDevice) {
+ if (TpmDevice == mTpmInstanceId[Index].TpmDevice) {
Size = sizeof(mTpmInstanceId[Index].TpmInstanceGuid);
PcdSetPtr (PcdTpmInstanceGuid, &Size, &mTpmInstanceId[Index].TpmInstanceGuid);
- DEBUG ((EFI_D_ERROR, "TrEEConfiguration.TpmDevice PCD: %g\n", &mTpmInstanceId[Index].TpmInstanceGuid));
+ DEBUG ((EFI_D_ERROR, "TpmDevice PCD: %g\n", &mTpmInstanceId[Index].TpmInstanceGuid));
break;
}
}
diff --git a/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c b/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c
index 71cd460e0c..8f4a0a8f1b 100644
--- a/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c
+++ b/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c
@@ -1509,6 +1509,121 @@ VariableGetBestLanguage (
}
/**
+ This function is to check if the remaining variable space is enough to set
+ all Variables from argument list successfully. The purpose of the check
+ is to keep the consistency of the Variables to be in variable storage.
+
+ Note: Variables are assumed to be in same storage.
+ The set sequence of Variables will be same with the sequence of VariableEntry from argument list,
+ so follow the argument sequence to check the Variables.
+
+ @param[in] Attributes Variable attributes for Variable entries.
+ @param ... Variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.
+ A NULL terminates the list.
+
+ @retval TRUE Have enough variable space to set the Variables successfully.
+ @retval FALSE No enough variable space to set the Variables successfully.
+
+**/
+BOOLEAN
+EFIAPI
+CheckRemainingSpaceForConsistency (
+ IN UINT32 Attributes,
+ ...
+ )
+{
+ EFI_STATUS Status;
+ VA_LIST Args;
+ VARIABLE_ENTRY_CONSISTENCY *VariableEntry;
+ UINT64 MaximumVariableStorageSize;
+ UINT64 RemainingVariableStorageSize;
+ UINT64 MaximumVariableSize;
+ UINTN TotalNeededSize;
+ UINTN OriginalVarSize;
+ VARIABLE_STORE_HEADER *VariableStoreHeader;
+ VARIABLE_POINTER_TRACK VariablePtrTrack;
+ VARIABLE_HEADER *NextVariable;
+
+ //
+ // Non-Volatile related.
+ //
+ VariableStoreHeader = mNvVariableCache;
+
+ Status = VariableServiceQueryVariableInfoInternal (
+ Attributes,
+ &MaximumVariableStorageSize,
+ &RemainingVariableStorageSize,
+ &MaximumVariableSize
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ TotalNeededSize = 0;
+ VA_START (Args, Attributes);
+ VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
+ while (VariableEntry != NULL) {
+ TotalNeededSize += VariableEntry->VariableSize;
+ VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
+ }
+ VA_END (Args);
+
+ if (RemainingVariableStorageSize >= TotalNeededSize) {
+ //
+ // Already have enough space.
+ //
+ return TRUE;
+ } else if (AtRuntime ()) {
+ //
+ // At runtime, no reclaim.
+ // The original variable space of Variables can't be reused.
+ //
+ return FALSE;
+ }
+
+ VA_START (Args, Attributes);
+ VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
+ while (VariableEntry != NULL) {
+ //
+ // Check if Variable[Index] has been present and get its size.
+ //
+ OriginalVarSize = 0;
+ VariablePtrTrack.StartPtr = GetStartPointer (VariableStoreHeader);
+ VariablePtrTrack.EndPtr = GetEndPointer (VariableStoreHeader);
+ Status = FindVariableEx (
+ VariableEntry->Name,
+ VariableEntry->Guid,
+ FALSE,
+ &VariablePtrTrack
+ );
+ if (!EFI_ERROR (Status)) {
+ //
+ // Get size of Variable[Index].
+ //
+ NextVariable = GetNextVariablePtr (VariablePtrTrack.CurrPtr);
+ OriginalVarSize = (UINTN) NextVariable - (UINTN) VariablePtrTrack.CurrPtr;
+ //
+ // Add the original size of Variable[Index] to remaining variable storage size.
+ //
+ RemainingVariableStorageSize += OriginalVarSize;
+ }
+ if (VariableEntry->VariableSize > RemainingVariableStorageSize) {
+ //
+ // No enough space for Variable[Index].
+ //
+ VA_END (Args);
+ return FALSE;
+ }
+ //
+ // Sub the (new) size of Variable[Index] from remaining variable storage size.
+ //
+ RemainingVariableStorageSize -= VariableEntry->VariableSize;
+ VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
+ }
+ VA_END (Args);
+
+ return TRUE;
+}
+
+/**
Hook the operations in PlatformLangCodes, LangCodes, PlatformLang and Lang.
When setting Lang/LangCodes, simultaneously update PlatformLang/PlatformLangCodes.
@@ -1542,6 +1657,9 @@ AutoUpdateLangVariable (
UINT32 Attributes;
VARIABLE_POINTER_TRACK Variable;
BOOLEAN SetLanguageCodes;
+ UINTN VarNameSize;
+ UINTN VarDataSize;
+ VARIABLE_ENTRY_CONSISTENCY VariableEntry[2];
//
// Don't do updates for delete operation
@@ -1664,12 +1782,37 @@ AutoUpdateLangVariable (
BestLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->LangCodes, Index, TRUE);
//
- // Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.
+ // Calculate the needed variable size for Lang variable.
+ //
+ VarNameSize = StrSize (EFI_LANG_VARIABLE_NAME);
+ VarDataSize = ISO_639_2_ENTRY_SIZE + 1;
+ VariableEntry[0].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
+ VariableEntry[0].VariableSize = HEADER_ALIGN (VariableEntry[0].VariableSize);
+ VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
+ VariableEntry[0].Name = EFI_LANG_VARIABLE_NAME;
//
- FindVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
+ // Calculate the needed variable size for PlatformLang variable.
+ //
+ VarNameSize = StrSize (EFI_PLATFORM_LANG_VARIABLE_NAME);
+ VarDataSize = AsciiStrSize (BestPlatformLang);
+ VariableEntry[1].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
+ VariableEntry[1].VariableSize = HEADER_ALIGN (VariableEntry[1].VariableSize);
+ VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
+ VariableEntry[1].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;
+ if (!CheckRemainingSpaceForConsistency (VARIABLE_ATTRIBUTE_NV_BS_RT, &VariableEntry[0], &VariableEntry[1], NULL)) {
+ //
+ // No enough variable space to set both Lang and PlatformLang successfully.
+ //
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ //
+ // Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.
+ //
+ FindVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
- Status = UpdateVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestLang,
- ISO_639_2_ENTRY_SIZE + 1, Attributes, 0, 0, &Variable, NULL);
+ Status = UpdateVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestLang,
+ ISO_639_2_ENTRY_SIZE + 1, Attributes, 0, 0, &Variable, NULL);
+ }
DEBUG ((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a Status: %r\n", BestPlatformLang, BestLang, Status));
}
@@ -1696,19 +1839,51 @@ AutoUpdateLangVariable (
BestPlatformLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->PlatformLangCodes, Index, FALSE);
//
- // Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.
+ // Calculate the needed variable size for PlatformLang variable.
//
- FindVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
+ VarNameSize = StrSize (EFI_PLATFORM_LANG_VARIABLE_NAME);
+ VarDataSize = AsciiStrSize (BestPlatformLang);
+ VariableEntry[0].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
+ VariableEntry[0].VariableSize = HEADER_ALIGN (VariableEntry[0].VariableSize);
+ VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
+ VariableEntry[0].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;
+ //
+ // Calculate the needed variable size for Lang variable.
+ //
+ VarNameSize = StrSize (EFI_LANG_VARIABLE_NAME);
+ VarDataSize = ISO_639_2_ENTRY_SIZE + 1;
+ VariableEntry[1].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
+ VariableEntry[1].VariableSize = HEADER_ALIGN (VariableEntry[1].VariableSize);
+ VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
+ VariableEntry[1].Name = EFI_LANG_VARIABLE_NAME;
+ if (!CheckRemainingSpaceForConsistency (VARIABLE_ATTRIBUTE_NV_BS_RT, &VariableEntry[0], &VariableEntry[1], NULL)) {
+ //
+ // No enough variable space to set both PlatformLang and Lang successfully.
+ //
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ //
+ // Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.
+ //
+ FindVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
- Status = UpdateVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestPlatformLang,
- AsciiStrSize (BestPlatformLang), Attributes, 0, 0, &Variable, NULL);
+ Status = UpdateVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestPlatformLang,
+ AsciiStrSize (BestPlatformLang), Attributes, 0, 0, &Variable, NULL);
+ }
DEBUG ((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a Status: %r\n", BestLang, BestPlatformLang, Status));
}
}
}
- return Status;
+ if (SetLanguageCodes) {
+ //
+ // Continue to set PlatformLangCodes or LangCodes.
+ //
+ return EFI_SUCCESS;
+ } else {
+ return Status;
+ }
}
/**
@@ -2992,16 +3167,18 @@ VariableServiceSetVariable (
goto Done;
}
}
-
- //
- // Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang.
- //
- Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
- if (EFI_ERROR (Status)) {
+
+ if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
//
- // The auto update operation failed, directly return to avoid inconsistency between PlatformLang and Lang.
+ // Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang.
//
- goto Done;
+ Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
+ if (EFI_ERROR (Status)) {
+ //
+ // The auto update operation failed, directly return to avoid inconsistency between PlatformLang and Lang.
+ //
+ goto Done;
+ }
}
//
@@ -3053,14 +3230,12 @@ Done:
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
associated with the attributes specified.
- @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
@return EFI_SUCCESS Query successfully.
- @return EFI_UNSUPPORTED The attribute is not supported on this platform.
**/
EFI_STATUS
EFIAPI
-VariableServiceQueryVariableInfo (
+VariableServiceQueryVariableInfoInternal (
IN UINT32 Attributes,
OUT UINT64 *MaximumVariableStorageSize,
OUT UINT64 *RemainingVariableStorageSize,
@@ -3073,38 +3248,12 @@ VariableServiceQueryVariableInfo (
VARIABLE_STORE_HEADER *VariableStoreHeader;
UINT64 CommonVariableTotalSize;
UINT64 HwErrVariableTotalSize;
+ EFI_STATUS Status;
+ VARIABLE_POINTER_TRACK VariablePtrTrack;
CommonVariableTotalSize = 0;
HwErrVariableTotalSize = 0;
- if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {
- return EFI_INVALID_PARAMETER;
- }
-
- if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == 0) {
- //
- // Make sure the Attributes combination is supported by the platform.
- //
- return EFI_UNSUPPORTED;
- } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {
- //
- // Make sure if runtime bit is set, boot service bit is set also.
- //
- return EFI_INVALID_PARAMETER;
- } else if (AtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) {
- //
- // Make sure RT Attribute is set if we are in Runtime phase.
- //
- return EFI_INVALID_PARAMETER;
- } else if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
- //
- // Make sure Hw Attribute is set with NV.
- //
- return EFI_INVALID_PARAMETER;
- }
-
- AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
-
if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {
//
// Query is Volatile related.
@@ -3176,6 +3325,27 @@ VariableServiceQueryVariableInfo (
} else {
CommonVariableTotalSize += VariableSize;
}
+ } else if (Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
+ //
+ // If it is a IN_DELETED_TRANSITION variable,
+ // and there is not also a same ADDED one at the same time,
+ // this IN_DELETED_TRANSITION variable is valid.
+ //
+ VariablePtrTrack.StartPtr = GetStartPointer (VariableStoreHeader);
+ VariablePtrTrack.EndPtr = GetEndPointer (VariableStoreHeader);
+ Status = FindVariableEx (
+ GetVariableNamePtr (Variable),
+ &Variable->VendorGuid,
+ FALSE,
+ &VariablePtrTrack
+ );
+ if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State != VAR_ADDED) {
+ if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
+ HwErrVariableTotalSize += VariableSize;
+ } else {
+ CommonVariableTotalSize += VariableSize;
+ }
+ }
}
}
@@ -3197,10 +3367,79 @@ VariableServiceQueryVariableInfo (
*MaximumVariableSize = *RemainingVariableStorageSize - sizeof (VARIABLE_HEADER);
}
- ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
return EFI_SUCCESS;
}
+/**
+
+ 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
+ for the EFI variables associated with the attributes specified.
+ @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
+ for EFI variables associated with the attributes specified.
+ @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
+ associated with the attributes specified.
+
+ @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
+ @return EFI_SUCCESS Query successfully.
+ @return EFI_UNSUPPORTED The attribute is not supported on this platform.
+
+**/
+EFI_STATUS
+EFIAPI
+VariableServiceQueryVariableInfo (
+ IN UINT32 Attributes,
+ OUT UINT64 *MaximumVariableStorageSize,
+ OUT UINT64 *RemainingVariableStorageSize,
+ OUT UINT64 *MaximumVariableSize
+ )
+{
+ EFI_STATUS Status;
+
+ if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == 0) {
+ //
+ // Make sure the Attributes combination is supported by the platform.
+ //
+ return EFI_UNSUPPORTED;
+ } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {
+ //
+ // Make sure if runtime bit is set, boot service bit is set also.
+ //
+ return EFI_INVALID_PARAMETER;
+ } else if (AtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) {
+ //
+ // Make sure RT Attribute is set if we are in Runtime phase.
+ //
+ return EFI_INVALID_PARAMETER;
+ } else if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
+ //
+ // Make sure Hw Attribute is set with NV.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
+
+ Status = VariableServiceQueryVariableInfoInternal (
+ Attributes,
+ MaximumVariableStorageSize,
+ RemainingVariableStorageSize,
+ MaximumVariableSize
+ );
+
+ ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
+ return Status;
+}
/**
This function reclaims variable storage if free size is below the threshold.
diff --git a/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h b/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h
index b4512d2cca..b9f4f43402 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 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2014, 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
@@ -111,10 +111,12 @@ typedef struct {
typedef struct {
EFI_GUID *Guid;
CHAR16 *Name;
- UINT32 Attributes;
- UINTN DataSize;
- VOID *Data;
-} VARIABLE_CACHE_ENTRY;
+// UINT32 Attributes;
+ //
+ // Variable size include variable header, name and data.
+ //
+ UINTN VariableSize;
+} VARIABLE_ENTRY_CONSISTENCY;
typedef struct {
EFI_GUID Guid;
@@ -580,6 +582,34 @@ VariableServiceSetVariable (
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
associated with the attributes specified.
+ @return EFI_SUCCESS Query successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+VariableServiceQueryVariableInfoInternal (
+ IN UINT32 Attributes,
+ OUT UINT64 *MaximumVariableStorageSize,
+ OUT UINT64 *RemainingVariableStorageSize,
+ OUT UINT64 *MaximumVariableSize
+ );
+
+/**
+
+ 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
+ for the EFI variables associated with the attributes specified.
+ @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
+ for EFI variables associated with the attributes specified.
+ @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
+ associated with the attributes specified.
+
@return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
@return EFI_SUCCESS Query successfully.
@return EFI_UNSUPPORTED The attribute is not supported on this platform.
diff --git a/SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableRuntimeDxe.inf b/SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableRuntimeDxe.inf
index a05c048494..41e85c0156 100644
--- a/SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableRuntimeDxe.inf
+++ b/SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableRuntimeDxe.inf
@@ -99,7 +99,8 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
[FeaturePcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## SOMETIME_CONSUMES (statistic the information of variable.)
+ gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## CONSUMES # statistic the information of variable.
+ gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate ## CONSUMES
[Depex]
TRUE
diff --git a/SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableSmm.inf b/SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableSmm.inf
index e7c6de8b94..0e3fc514b4 100644
--- a/SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableSmm.inf
+++ b/SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableSmm.inf
@@ -102,7 +102,8 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
[FeaturePcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## SOMETIME_CONSUMES (statistic the information of variable.)
+ gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## CONSUMES # statistic the information of variable.
+ gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate ## CONSUMES
[Depex]
TRUE