From 00ca26eb9a797acdd99ca06556995d91887e39f2 Mon Sep 17 00:00:00 2001 From: Jeff Fan Date: Thu, 20 Mar 2014 03:30:35 +0000 Subject: Sync patch r15340 from main trunk. MdeModulePkg/SecurityPkg Variable: Return error status to avoid inconsistency between PlatformLang and Lang. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan git-svn-id: https://svn.code.sf.net/p/edk2/code/branches/UDK2010.SR1@15349 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Universal/Variable/RuntimeDxe/Variable.c | 38 ++++++++++++++-------- .../VariableAuthenticated/RuntimeDxe/Variable.c | 37 ++++++++++++++------- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c index 09b8b4b..ba4d53a 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -3,7 +3,7 @@ The common variable operation routines shared by DXE_RUNTIME variable module and DXE_SMM variable module. -Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -1211,8 +1211,13 @@ VariableGetBestLanguage ( @param[in] DataSize Size of data. 0 means delete. + @retval EFI_SUCCESS The update operation is successful or ignored. + @retval EFI_WRITE_PROTECTED Update PlatformLangCodes/LangCodes at runtime. + @retval EFI_OUT_OF_RESOURCES No enough variable space to do the update operation. + @retval Others Other errors happened during the update operation. + **/ -VOID +EFI_STATUS AutoUpdateLangVariable ( IN CHAR16 *VariableName, IN VOID *Data, @@ -1231,7 +1236,7 @@ AutoUpdateLangVariable ( // Don't do updates for delete operation // if (DataSize == 0) { - return; + return EFI_SUCCESS; } SetLanguageCodes = FALSE; @@ -1241,7 +1246,7 @@ AutoUpdateLangVariable ( // PlatformLangCodes is a volatile variable, so it can not be updated at runtime. // if (AtRuntime ()) { - return; + return EFI_WRITE_PROTECTED; } SetLanguageCodes = TRUE; @@ -1271,7 +1276,7 @@ AutoUpdateLangVariable ( // LangCodes is a volatile variable, so it can not be updated at runtime. // if (AtRuntime ()) { - return; + return EFI_WRITE_PROTECTED; } SetLanguageCodes = TRUE; @@ -1315,11 +1320,13 @@ AutoUpdateLangVariable ( // // Neither PlatformLang nor Lang is set, directly return // - return; + return EFI_SUCCESS; } } } - + + Status = EFI_SUCCESS; + // // According to UEFI spec, "Lang" and "PlatformLang" is NV|BS|RT attributions. // @@ -1353,9 +1360,7 @@ AutoUpdateLangVariable ( Status = UpdateVariable (L"Lang", &gEfiGlobalVariableGuid, BestLang, ISO_639_2_ENTRY_SIZE + 1, Attributes, &Variable); - DEBUG ((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a\n", BestPlatformLang, BestLang)); - - ASSERT_EFI_ERROR(Status); + DEBUG ((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a: Status: %r\n", BestPlatformLang, BestLang, Status)); } } @@ -1387,11 +1392,12 @@ AutoUpdateLangVariable ( Status = UpdateVariable (L"PlatformLang", &gEfiGlobalVariableGuid, BestPlatformLang, AsciiStrSize (BestPlatformLang), Attributes, &Variable); - DEBUG ((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a\n", BestLang, BestPlatformLang)); - ASSERT_EFI_ERROR (Status); + DEBUG ((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a Status: %r\n", BestLang, BestPlatformLang, Status)); } } } + + return Status; } /** @@ -2366,7 +2372,13 @@ VariableServiceSetVariable ( // // Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang. // - AutoUpdateLangVariable (VariableName, Data, DataSize); + 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); diff --git a/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c b/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c index bda945b..948c8d6 100644 --- a/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c +++ b/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c @@ -16,7 +16,7 @@ VariableServiceSetVariable() should also check authenticate data to avoid buffer overflow, integer overflow. It should also check attribute to avoid authentication bypass. -Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -1462,8 +1462,13 @@ VariableGetBestLanguage ( @param[in] DataSize Size of data. 0 means delete. + @retval EFI_SUCCESS The update operation is successful or ignored. + @retval EFI_WRITE_PROTECTED Update PlatformLangCodes/LangCodes at runtime. + @retval EFI_OUT_OF_RESOURCES No enough variable space to do the update operation. + @retval Others Other errors happened during the update operation. + **/ -VOID +EFI_STATUS AutoUpdateLangVariable ( IN CHAR16 *VariableName, IN VOID *Data, @@ -1482,7 +1487,7 @@ AutoUpdateLangVariable ( // Don't do updates for delete operation // if (DataSize == 0) { - return; + return EFI_SUCCESS; } SetLanguageCodes = FALSE; @@ -1492,7 +1497,7 @@ AutoUpdateLangVariable ( // PlatformLangCodes is a volatile variable, so it can not be updated at runtime. // if (AtRuntime ()) { - return; + return EFI_WRITE_PROTECTED; } SetLanguageCodes = TRUE; @@ -1522,7 +1527,7 @@ AutoUpdateLangVariable ( // LangCodes is a volatile variable, so it can not be updated at runtime. // if (AtRuntime ()) { - return; + return EFI_WRITE_PROTECTED; } SetLanguageCodes = TRUE; @@ -1566,11 +1571,13 @@ AutoUpdateLangVariable ( // // Neither PlatformLang nor Lang is set, directly return // - return; + return EFI_SUCCESS; } } } + Status = EFI_SUCCESS; + // // According to UEFI spec, "Lang" and "PlatformLang" is NV|BS|RT attributions. // @@ -1604,9 +1611,7 @@ AutoUpdateLangVariable ( Status = UpdateVariable (L"Lang", &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\n", BestPlatformLang, BestLang)); - - ASSERT_EFI_ERROR(Status); + DEBUG ((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a Status: %r\n", BestPlatformLang, BestLang, Status)); } } @@ -1638,11 +1643,12 @@ AutoUpdateLangVariable ( Status = UpdateVariable (L"PlatformLang", &gEfiGlobalVariableGuid, BestPlatformLang, AsciiStrSize (BestPlatformLang), Attributes, 0, 0, &Variable, NULL); - DEBUG ((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a\n", BestLang, BestPlatformLang)); - ASSERT_EFI_ERROR (Status); + DEBUG ((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a Status: %r\n", BestLang, BestPlatformLang, Status)); } } } + + return Status; } /** @@ -2850,7 +2856,14 @@ VariableServiceSetVariable ( // // Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang. // - AutoUpdateLangVariable (VariableName, Data, DataSize); + 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; + } + // // Process PK, KEK, Sigdb seperately. // -- cgit v1.1