summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Fan <jeff.fan@intel.com>2014-03-28 07:03:15 +0000
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2014-03-28 07:03:15 +0000
commit4a4f0b640c46a50f592b86ed648bf1f624dff08c (patch)
tree95baeab4aadb5d05d9718892a57a2aaacc0f0f6d
parentf08c8b1fcf9e3965a9363619c400d6af482df69b (diff)
downloadedk2-4a4f0b640c46a50f592b86ed648bf1f624dff08c.tar.gz
edk2-4a4f0b640c46a50f592b86ed648bf1f624dff08c.tar.bz2
edk2-4a4f0b640c46a50f592b86ed648bf1f624dff08c.zip
Sync patches r15385, r15386, r15387, r15391, r15393, r15401, r15403, r15407, and r15410 from main trunk.
1. Report the setting variable failure to platform through the status code when core cannot handle the error. 2. Report the setting variable failure to platform through the status code when core cannot handle the error. 3. Support load 64 bit image from 32 bit core. Add more enhancement to check invalid PE format. 4. Remove RT attribute for variable LegacyDevOrder. 5. Add check to make sure the data be valid. 6. Remove RT attribute for variable PlatDriOver. 7. Update code logic, remove ASSERT and use error handling. 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/UDK2010.SR1@15413 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c44
-rw-r--r--IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c17
-rw-r--r--IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c103
-rw-r--r--IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf4
-rw-r--r--IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h47
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h91
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf4
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c153
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c2
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c2
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c17
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c184
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c9
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/Hotkey.c5
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/Language.c17
-rw-r--r--MdeModulePkg/Include/Guid/StatusCodeDataTypeVariable.h40
-rw-r--r--MdeModulePkg/MdeModulePkg.dec7
-rw-r--r--MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c34
-rw-r--r--MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h1
-rw-r--r--MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf4
-rw-r--r--MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c42
-rw-r--r--MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c10
-rw-r--r--MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideLib.c68
-rw-r--r--MdePkg/Library/BasePeCoffLib/BasePeCoff.c31
24 files changed, 749 insertions, 187 deletions
diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
index 525ef86b73..133ad2afe3 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
@@ -670,7 +670,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,
@@ -868,13 +868,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;
@@ -985,6 +986,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,
@@ -1083,6 +1085,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,
@@ -1292,6 +1295,10 @@ BdsLibDeleteOptionFromHandle (
BootOrderSize,
BootOrder
);
+ //
+ // Shrinking variable with existing variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
FreePool (BootOrder);
@@ -1390,6 +1397,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;
@@ -1417,6 +1428,10 @@ BdsDeleteAllInvalidEfiBootOption (
Index2 * sizeof (UINT16),
BootOrder
);
+ //
+ // Shrinking variable with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
FreePool (BootOrder);
@@ -1540,7 +1555,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);
@@ -1883,6 +1900,7 @@ BdsLibBootNext (
VOID
)
{
+ EFI_STATUS Status;
UINT16 *BootNext;
UINTN BootNextSize;
CHAR16 Buffer[20];
@@ -1907,13 +1925,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 4ea9d03091..73c3e416af 100644
--- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
+++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
@@ -217,6 +217,9 @@ BdsLibRegisterNewOption (
UINT16 BootOrderEntry;
UINTN OrderItemNum;
+ if (DevicePath == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
OptionPtr = NULL;
OptionSize = 0;
@@ -1425,13 +1428,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)) {
//
@@ -1492,3 +1495,89 @@ 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);
+ if ((Data != NULL) && (DataSize != 0)) {
+ 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 545709c6eb..5e425b7cbe 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
@@ -78,6 +78,7 @@
gLastEnumLangGuid ## SOMETIMES_PRODUCES ## Variable:L"LastEnumLang" (Platform language at last time enumeration.)
gHdBootDevicePathVariablGuid ## SOMETIMES_PRODUCES ## Variable:L"HDDP" (The device path of Boot file on Hard device.)
gBdsLibStringPackageGuid ## PRODUCES ## GUID (HII String PackageList Guid)
+ gEdkiiStatusCodeDataTypeVariableGuid ## SOMETIMES_CONSUMES
[Protocols]
gEfiSimpleFileSystemProtocolGuid # PROTOCOL CONSUMES
@@ -110,4 +111,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 e00dd7a544..faa42b5cb6 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
@@ -50,6 +50,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Guid/BdsLibHii.h>
#include <Guid/HdBootVariable.h>
#include <Guid/LastEnumLang.h>
+#include <Guid/StatusCodeDataTypeVariable.h>
#include <Library/PrintLib.h>
#include <Library/DebugLib.h>
@@ -146,4 +147,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 0aba09c1bf..e62828593c 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>
@@ -188,4 +189,92 @@ 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
+ );
+
+/**
+ 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 2424a8a842..3041c2a786 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
@@ -141,6 +141,7 @@
gDeviceManagerFormSetGuid ## SOMETIMES_PRODUCES ## DeviceManager HII Package
gDriverHealthFormSetGuid ## SOMETIMES_PRODUCES ## DriverHealth HII Package
gConnectConInEventGuid ## CONSUMES ## GUID (Connect ConIn Event)
+ gEdkiiStatusCodeDataTypeVariableGuid ## SOMETIMES_CONSUMES
[Protocols]
gEfiSimpleFileSystemProtocolGuid ## PROTOCOL CONSUMES
@@ -187,6 +188,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 ef5c36e49b..fbcb11f856 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 - 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
@@ -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);
}
}
@@ -404,14 +411,13 @@ BdsFormalizeEfiGlobalVariable (
// OS indicater support variable
//
OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
- 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.
@@ -440,10 +446,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);
}
}
@@ -479,16 +488,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)) {
@@ -591,14 +603,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);
}
//
@@ -652,3 +663,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 a4b6b53a06..c4df60b230 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 - 2011, 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
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c
index 2394688479..18262a0d20 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
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c
index cd4bbe767c..b15b3bb844 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 c4b83ba0ff..252da3c321 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c
@@ -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,
- VAR_FLAG,
- 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,
+ VAR_FLAG,
+ 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
+ VAR_FLAG,
+ 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 (!EFI_ERROR (Status)) {
- if (BootOrderList != NULL) {
- FreePool (BootOrderList);
- }
+ FreePool (NewBootOrderList);
+ NewBootOrderList = NULL;
+ InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link);
+ BootOptionMenu.MenuNumber++;
- Status = gRT->SetVariable (
- L"BootOrder",
- &gEfiGlobalVariableGuid,
- VAR_FLAG,
- BootOrderListSize + sizeof (UINT16),
- NewBootOrderList
- );
- ASSERT_EFI_ERROR (Status);
-
- 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;
}
@@ -992,6 +1007,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);
BOpt_FreeMenu (&BootOptionMenu);
@@ -1061,10 +1080,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;
@@ -1219,10 +1239,14 @@ Var_UpdateBBSOption (
Status = gRT->SetVariable (
VAR_LEGACY_DEV_ORDER,
&gEfiLegacyDevOrderVariableGuid,
- VAR_FLAG,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
VarSize,
OriginalPtr
- );
+ );
+ //
+ // Changing the content without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
//
@@ -1252,8 +1276,12 @@ Var_UpdateBBSOption (
&EnBootOptionCount,
DisBootOption,
&DisBootOptionCount
- );
-
+ );
+ //
+ // Changing the content without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
+
Status = gRT->SetVariable (
L"BootOrder",
&gEfiGlobalVariableGuid,
@@ -1286,6 +1314,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);
}
@@ -1309,6 +1341,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 1a3ec1ff84..29829faea5 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 - 2012, 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
@@ -546,6 +546,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..6dbb74c666 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
@@ -408,24 +408,23 @@ InitializeLangVariable (
IN BOOLEAN Iso639Language
)
{
- EFI_STATUS Status;
CHAR8 *Lang;
//
// Find current Lang or PlatformLang from EFI Variable.
//
- Status = GetEfiGlobalVariable2 (LangName, (VOID **) &Lang, NULL);
+ GetEfiGlobalVariable2 (LangName, (VOID **) &Lang, NULL);
//
// If Lang or PlatformLang variable is not found,
// or it has been set to an unsupported value(not one of the supported language codes),
// set the default language code to it.
//
- if (EFI_ERROR (Status) || !IsLangInSupportedLangCodes (SupportedLang, Lang, Iso639Language)) {
+ if ((Lang == NULL) || !IsLangInSupportedLangCodes (SupportedLang, Lang, Iso639Language)) {
//
// 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,
@@ -471,6 +470,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,6 +483,10 @@ 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)) {
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 c8a401b8d7..ffafc5f51a 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -262,6 +262,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 }}
@@ -599,6 +602,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]
## Maximun number of performance log entries during PEI phase.
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPerformanceLogEntries|40|UINT8|0x0001002f
diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c
index a27090815c..966fb79ce4 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.
@@ -1442,6 +1444,7 @@ TerminalUpdateConsoleDevVariable (
for (TerminalType = PCANSITYPE; TerminalType <= VTUTF8TYPE; TerminalType++) {
SetTerminalDevicePath (TerminalType, ParentDevicePath, &TempDevicePath);
NewVariable = AppendDevicePathInstance (Variable, TempDevicePath);
+ ASSERT (NewVariable != NULL);
if (Variable != NULL) {
FreePool (Variable);
}
@@ -1462,6 +1465,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 +1599,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 9387998e01..a6f39997b7 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/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
index f5c44d0247..c8260e9150 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
+++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
@@ -2,7 +2,7 @@
This is an example of how a driver might export data to the HII protocol to be
later utilized by the Setup Protocol
-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
@@ -1979,25 +1979,40 @@ DriverSampleInit (
sizeof (DRIVER_SAMPLE_CONFIGURATION),
Configuration
);
- ASSERT (Status == EFI_SUCCESS);
+ if (EFI_ERROR (Status)) {
+ DriverSampleUnload (ImageHandle);
+ return Status;
+ }
//
// EFI variable for NV config doesn't exit, we should build this variable
// based on default values stored in IFR
//
ActionFlag = HiiSetToDefaults (NameRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
- ASSERT (ActionFlag);
+ if (!ActionFlag) {
+ DriverSampleUnload (ImageHandle);
+ return EFI_INVALID_PARAMETER;
+ }
ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
- ASSERT (ActionFlag);
+ if (!ActionFlag) {
+ DriverSampleUnload (ImageHandle);
+ return EFI_INVALID_PARAMETER;
+ }
} else {
//
// EFI variable does exist and Validate Current Setting
//
ActionFlag = HiiValidateSettings (NameRequestHdr);
- ASSERT (ActionFlag);
+ if (!ActionFlag) {
+ DriverSampleUnload (ImageHandle);
+ return EFI_INVALID_PARAMETER;
+ }
ActionFlag = HiiValidateSettings (ConfigRequestHdr);
- ASSERT (ActionFlag);
+ if (!ActionFlag) {
+ DriverSampleUnload (ImageHandle);
+ return EFI_INVALID_PARAMETER;
+ }
}
FreePool (ConfigRequestHdr);
@@ -2023,19 +2038,28 @@ DriverSampleInit (
sizeof (MY_EFI_VARSTORE_DATA),
VarStoreConfig
);
- ASSERT (Status == EFI_SUCCESS);
+ if (EFI_ERROR (Status)) {
+ DriverSampleUnload (ImageHandle);
+ return Status;
+ }
//
// EFI variable for NV config doesn't exit, we should build this variable
// based on default values stored in IFR
//
ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
- ASSERT (ActionFlag);
+ if (!ActionFlag) {
+ DriverSampleUnload (ImageHandle);
+ return EFI_INVALID_PARAMETER;
+ }
} else {
//
// EFI variable does exist and Validate Current Setting
//
ActionFlag = HiiValidateSettings (ConfigRequestHdr);
- ASSERT (ActionFlag);
+ if (!ActionFlag) {
+ DriverSampleUnload (ImageHandle);
+ return EFI_INVALID_PARAMETER;
+ }
}
FreePool (ConfigRequestHdr);
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..bad8ecc35f 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);
}
//
@@ -879,7 +912,7 @@ DeleteOverridesVariables (
Status = gRT->SetVariable (
L"PlatDriOver",
&gEfiCallerIdGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
0,
NULL
);
@@ -889,7 +922,7 @@ DeleteOverridesVariables (
Status = gRT->SetVariable (
OverrideVariableName,
&gEfiCallerIdGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
0,
NULL
);
@@ -944,7 +977,7 @@ SaveOverridesMapping (
// Get the the maximum size of an individual EFI variable in current system
//
gRT->QueryVariableInfo (
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
&MaximumVariableStorageSize,
&RemainingVariableStorageSize,
&MaximumVariableSize
@@ -1053,14 +1086,23 @@ SaveOverridesMapping (
Status = gRT->SetVariable (
OverrideVariableName,
&gEfiCallerIdGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
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/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.