From f71ed839e1b59b8e1036c5d8a6f1153be1f32053 Mon Sep 17 00:00:00 2001 From: sfu5 Date: Wed, 9 Jan 2013 05:19:43 +0000 Subject: [PATCH] =?utf8?q?1.=20Set=20the=20secure=20boot=20state=20to=20St?= =?utf8?q?andard=20Mode=20when=20user=20leaving=20secure=20boot=20setup=20?= =?utf8?q?page.=202.=20Add=20=E2=80=9CCurrent=20SecureBoot=20State?= =?utf8?q?=E2=80=9D=20field=20to=20reflect=20current=20secure=20boot=20sta?= =?utf8?q?tus=20of=20the=20platform.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Fu Siyuan Reviewed-by: Dong Guo Reviewed-by: Yao Jiewen git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14042 6f19259b-4bc3-4df7-8a09-765794883524 --- .../RuntimeDxe/AuthService.c | 37 ++-- .../SecureBootConfigDxe/SecureBootConfig.vfr | 11 +- .../SecureBootConfigImpl.c | 165 +++++++++++++++--- .../SecureBootConfigNvData.h | 4 +- .../SecureBootConfigStrings.uni | Bin 9518 -> 10086 bytes 5 files changed, 167 insertions(+), 50 deletions(-) diff --git a/SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.c b/SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.c index 1ba934b922..8552d31b25 100644 --- a/SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.c +++ b/SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.c @@ -356,30 +356,23 @@ AutenticatedVariableServiceInitialize ( DEBUG ((EFI_D_INFO, "Variable %s is %x\n", EFI_SECURE_BOOT_ENABLE_NAME, SecureBootEnable)); // - // Check "CustomMode" variable's existence. + // Initialize "CustomMode" in STANDARD_SECURE_BOOT_MODE state. // FindVariable (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE); - if (Variable.CurrPtr != NULL) { - CustomMode = *(GetVariableDataPtr (Variable.CurrPtr)); - } else { - // - // "CustomMode" not exist, initialize it in STANDARD_SECURE_BOOT_MODE. - // - CustomMode = STANDARD_SECURE_BOOT_MODE; - Status = UpdateVariable ( - EFI_CUSTOM_MODE_NAME, - &gEfiCustomModeEnableGuid, - &CustomMode, - sizeof (UINT8), - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, - 0, - 0, - &Variable, - NULL - ); - if (EFI_ERROR (Status)) { - return Status; - } + CustomMode = STANDARD_SECURE_BOOT_MODE; + Status = UpdateVariable ( + EFI_CUSTOM_MODE_NAME, + &gEfiCustomModeEnableGuid, + &CustomMode, + sizeof (UINT8), + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + 0, + 0, + &Variable, + NULL + ); + if (EFI_ERROR (Status)) { + return Status; } DEBUG ((EFI_D_INFO, "Variable %s is %x\n", EFI_CUSTOM_MODE_NAME, CustomMode)); diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfig.vfr b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfig.vfr index df7ff37a86..ae4b71bffd 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfig.vfr +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfig.vfr @@ -1,7 +1,7 @@ /** @file VFR file used by the SecureBoot configuration component. -Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2013, 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 @@ -32,7 +32,12 @@ formset title = STRING_TOKEN(STR_SECUREBOOT_TITLE); subtitle text = STRING_TOKEN(STR_NULL); - + + text + help = STRING_TOKEN(STR_SECURE_BOOT_STATE_HELP), + text = STRING_TOKEN(STR_SECURE_BOOT_STATE_PROMPT), + text = STRING_TOKEN(STR_SECURE_BOOT_STATE_CONTENT); + // // Define of Check Box: Attempt Secure Boot // @@ -47,7 +52,7 @@ formset // Display of Check Box: Attempt Secure Boot // grayoutif ideqval SECUREBOOT_CONFIGURATION.HideSecureBoot == 1; - checkbox varid = SECUREBOOT_CONFIGURATION.SecureBootState, + checkbox varid = SECUREBOOT_CONFIGURATION.AttemptSecureBoot, questionid = KEY_SECURE_BOOT_ENABLE, prompt = STRING_TOKEN(STR_SECURE_BOOT_PROMPT), help = STRING_TOKEN(STR_SECURE_BOOT_HELP), diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c index c56a311760..7df68851c8 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c @@ -1,7 +1,7 @@ /** @file HII Config Access protocol implementation of SecureBoot configuration module. -Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2013, 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 @@ -253,6 +253,7 @@ DeleteVariable ( if (Variable == NULL) { return EFI_SUCCESS; } + FreePool (Variable); Data = NULL; DataSize = 0; @@ -278,6 +279,31 @@ DeleteVariable ( return Status; } +/** + + Set the platform secure boot mode into "Custom" or "Standard" mode. + + @param[in] SecureBootMode New secure boot mode: STANDARD_SECURE_BOOT_MODE or + CUSTOM_SECURE_BOOT_MODE. + + @return EFI_SUCCESS The platform has switched to the special mode successfully. + @return other Fail to operate the secure boot mode. + +**/ +EFI_STATUS +SetSecureBootMode ( + IN UINT8 SecureBootMode + ) +{ + return gRT->SetVariable ( + EFI_CUSTOM_MODE_NAME, + &gEfiCustomModeEnableGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (UINT8), + &SecureBootMode + ); +} + /** Generate the PK signature list from the X509 Certificate storing file (.cer) @@ -380,6 +406,11 @@ EnrollPlatformKey ( PkCert = NULL; + Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + return Status; + } + // // Parse the file's postfix. Only support DER encoded X.509 certificate files. // @@ -457,6 +488,11 @@ DeletePlatformKey ( { EFI_STATUS Status; + Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + return Status; + } + Status = DeleteVariable ( EFI_PLATFORM_KEY_NAME, &gEfiGlobalVariableGuid @@ -766,11 +802,17 @@ EnrollKeyExchangeKey ( ) { UINT16* FilePostFix; + EFI_STATUS Status; if ((Private->FileContext->FileName == NULL) || (Private->SignatureGUID == NULL)) { return EFI_INVALID_PARAMETER; } + Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + return Status; + } + // // Parse the file's postfix. Supports DER-encoded X509 certificate, // and .pbk as RSA public key file. @@ -1508,11 +1550,17 @@ EnrollSignatureDatabase ( ) { UINT16* FilePostFix; + EFI_STATUS Status; if ((Private->FileContext->FileName == NULL) || (Private->FileContext->FHandle == NULL) || (Private->SignatureGUID == NULL)) { return EFI_INVALID_PARAMETER; } + Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + return Status; + } + // // Parse the file's postfix. // @@ -1756,6 +1804,11 @@ DeleteKeyExchangeKey ( Cert = NULL; Attr = 0; DeleteKekIndex = QuestionId - OPTION_DEL_KEK_QUESTION_ID; + + Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + return Status; + } // // Get original KEK variable. @@ -1944,6 +1997,11 @@ DeleteSignature ( Cert = NULL; Attr = 0; + Status = SetSecureBootMode(CUSTOM_SECURE_BOOT_MODE); + if (EFI_ERROR (Status)) { + return Status; + } + // // Get original signature list data. // @@ -2103,23 +2161,25 @@ SecureBootExtractConfigFromVariable ( { UINT8 *SecureBootEnable; UINT8 *SetupMode; - UINT8 *SecureBoot; UINT8 *SecureBootMode; SecureBootEnable = NULL; SetupMode = NULL; - SecureBoot = NULL; SecureBootMode = NULL; // // If the SecureBootEnable Variable doesn't exist, hide the SecureBoot Enable/Disable // Checkbox. // + ConfigData->AttemptSecureBoot = FALSE; GetVariable2 (EFI_SECURE_BOOT_ENABLE_NAME, &gEfiSecureBootEnableDisableGuid, (VOID**)&SecureBootEnable, NULL); if (SecureBootEnable == NULL) { ConfigData->HideSecureBoot = TRUE; } else { ConfigData->HideSecureBoot = FALSE; + if ((*SecureBootEnable) == SECURE_BOOT_ENABLE) { + ConfigData->AttemptSecureBoot = TRUE; + } } // @@ -2140,16 +2200,6 @@ SecureBootExtractConfigFromVariable ( } else { ConfigData->HasPk = TRUE; } - - // - // If the value of SecureBoot variable is 1, the platform is operating in secure boot mode. - // - GetVariable2 (EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&SecureBoot, NULL); - if (SecureBoot != NULL && *SecureBoot == SECURE_BOOT_MODE_ENABLE) { - ConfigData->SecureBootState = TRUE; - } else { - ConfigData->SecureBootState = FALSE; - } // // Get the SecureBootMode from CustomMode variable. @@ -2160,7 +2210,16 @@ SecureBootExtractConfigFromVariable ( } else { ConfigData->SecureBootMode = *(SecureBootMode); } - + + if (SecureBootEnable != NULL) { + FreePool (SecureBootEnable); + } + if (SetupMode != NULL) { + FreePool (SetupMode); + } + if (SecureBootMode != NULL) { + FreePool (SecureBootMode); + } } /** @@ -2206,6 +2265,7 @@ SecureBootExtractConfig ( EFI_STRING ConfigRequestHdr; SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData; BOOLEAN AllocatedRequest; + UINT8 *SecureBoot; if (Progress == NULL || Results == NULL) { return EFI_INVALID_PARAMETER; @@ -2215,6 +2275,7 @@ SecureBootExtractConfig ( ConfigRequestHdr = NULL; ConfigRequest = NULL; Size = 0; + SecureBoot = NULL; ZeroMem (&Configuration, sizeof (Configuration)); PrivateData = SECUREBOOT_CONFIG_PRIVATE_FROM_THIS (This); @@ -2228,6 +2289,19 @@ SecureBootExtractConfig ( // Get Configuration from Variable. // SecureBootExtractConfigFromVariable (&Configuration); + + // + // Update current secure boot state. + // + GetVariable2 (EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&SecureBoot, NULL); + if (SecureBoot != NULL && *SecureBoot == SECURE_BOOT_MODE_ENABLE) { + HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SECURE_BOOT_STATE_CONTENT), L"Enabled", NULL); + } else { + HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SECURE_BOOT_STATE_CONTENT), L"Disabled", NULL); + } + if (SecureBoot != NULL) { + FreePool (SecureBoot); + } BufferSize = sizeof (SECUREBOOT_CONFIGURATION); ConfigRequest = Request; @@ -2355,15 +2429,21 @@ SecureBootCallback ( SECUREBOOT_CONFIGURATION *IfrNvData; UINT16 LabelId; UINT8 *SecureBootEnable; + UINT8 *SecureBootMode; + UINT8 *SetupMode; CHAR16 PromptString[100]; SecureBootEnable = NULL; + SecureBootMode = NULL; + SetupMode = NULL; if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) { return EFI_INVALID_PARAMETER; } - if ((Action != EFI_BROWSER_ACTION_CHANGED) && (Action != EFI_BROWSER_ACTION_CHANGING)) { + if ((Action != EFI_BROWSER_ACTION_CHANGED) && + (Action != EFI_BROWSER_ACTION_CHANGING) && + (Action != EFI_BROWSER_ACTION_FORM_CLOSE)) { return EFI_UNSUPPORTED; } @@ -2388,6 +2468,7 @@ SecureBootCallback ( case KEY_SECURE_BOOT_ENABLE: GetVariable2 (EFI_SECURE_BOOT_ENABLE_NAME, &gEfiSecureBootEnableDisableGuid, (VOID**)&SecureBootEnable, NULL); if (NULL != SecureBootEnable) { + FreePool (SecureBootEnable); if (EFI_ERROR (SaveSecureBootVariable (Value->u8))) { CreatePopUp ( EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, @@ -2400,11 +2481,10 @@ SecureBootCallback ( CreatePopUp ( EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, - L"Secure boot configuration is changed, please reset the platform to take effect!", + L"Configuration changed, please reset the platform to take effect!", NULL ); } - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; } break; @@ -2461,10 +2541,26 @@ SecureBootCallback ( break; case KEY_SECURE_BOOT_DELETE_PK: - if (Value->u8) { + if (Value->u8) { + CreatePopUp ( + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, + &Key, + L"Are you sure you want to delete PK? Secure boot will be disabled!", + L"Press 'Y' to delete PK and exit, 'N' to discard change and return", + NULL + ); + if (Key.UnicodeChar == 'y' || Key.UnicodeChar == 'Y') { Status = DeletePlatformKey (); - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; + if (EFI_ERROR (Status)) { + CreatePopUp ( + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, + &Key, + L"Only Physical Presence User could delete PK in custom mode!", + NULL + ); + } } + } break; case KEY_DELETE_KEK: @@ -2547,7 +2643,7 @@ SecureBootCallback ( } else if (Action == EFI_BROWSER_ACTION_CHANGED) { switch (QuestionId) { case KEY_SECURE_BOOT_ENABLE: - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT; + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; break; case KEY_VALUE_SAVE_AND_EXIT_PK: Status = EnrollPlatformKey (Private); @@ -2588,8 +2684,8 @@ SecureBootCallback ( break; case KEY_SECURE_BOOT_MODE: - GetVariable2 (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, (VOID**)&SecureBootEnable, NULL); - if (NULL != SecureBootEnable) { + GetVariable2 (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, (VOID**)&SecureBootMode, NULL); + if (NULL != SecureBootMode) { Status = gRT->SetVariable ( EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, @@ -2599,6 +2695,7 @@ SecureBootCallback ( ); *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; IfrNvData->SecureBootMode = Value->u8; + FreePool (SecureBootMode); } break; @@ -2619,11 +2716,33 @@ SecureBootCallback ( break; case KEY_SECURE_BOOT_DELETE_PK: - if (Value->u8) { + GetVariable2 (EFI_SETUP_MODE_NAME, &gEfiGlobalVariableGuid, (VOID**)&SetupMode, NULL); + if (SetupMode == NULL || (*SetupMode) == SETUP_MODE) { + IfrNvData->DeletePk = TRUE; + IfrNvData->HasPk = FALSE; *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT; + } else { + IfrNvData->DeletePk = FALSE; + IfrNvData->HasPk = TRUE; + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; + } + if (SetupMode != NULL) { + FreePool (SetupMode); } break; } + } else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) { + // + // Force the platform back to Standard Mode once user leave the setup screen. + // + GetVariable2 (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, (VOID**)&SecureBootMode, NULL); + if (NULL != SecureBootMode && *SecureBootMode == CUSTOM_SECURE_BOOT_MODE) { + IfrNvData->SecureBootMode = STANDARD_SECURE_BOOT_MODE; + SetSecureBootMode(STANDARD_SECURE_BOOT_MODE); + } + if (SecureBootMode != NULL) { + FreePool (SecureBootMode); + } } if (!EFI_ERROR (Status)) { diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigNvData.h b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigNvData.h index 6015dd636d..ea43192900 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigNvData.h +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigNvData.h @@ -1,7 +1,7 @@ /** @file Header file for NV data structure definition. -Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2013, 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 @@ -106,7 +106,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // Nv Data structure referenced by IFR // typedef struct { - BOOLEAN SecureBootState; //Secure Boot Disable/Enable; + BOOLEAN AttemptSecureBoot; //Attempt to enable/disable Secure Boot. BOOLEAN HideSecureBoot; //Hiden Attempt Secure Boot CHAR16 SignatureGuid[SECURE_BOOT_GUID_STORAGE_SIZE]; BOOLEAN PhysicalPresent; //If a Physical Present User; diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigStrings.uni b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigStrings.uni index ed4db131e9b0dd8547b4cf22e3915a25fee3abd1..8a4cb36f72d307197e01abfa64c130a1f8bebc59 100644 GIT binary patch delta 259 zcmZ4I^~`U>GdA{Mh7blvhLFh%`Q#_DDovgs$f8-qP{feRkjGHMpui9eWF<3{f<>Gd z@_`T{TEdXXP%@d3-x6*>p`z&IKN4I}L%5L)nXJevX<7`_2-E^J&I)KO$oNEtB!(Oy zD+S2U2U?&2WMwiGBZ=!xekg1%33VZZD?>bkGlM^aAJE0FAab&yfIg$b