X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=SecurityPkg%2FLibrary%2FDxeTcg2PhysicalPresenceLib%2FDxeTcg2PhysicalPresenceLib.c;h=a271c813887f8e5864aa88e348429aad55143c53;hb=b3548d32ddb553a9e95503457c66d11462622d16;hp=38fe89c5c9cf37d75fcf377a2151b8c8801a3d0a;hpb=d6b02b79b0fa2b10a0315f9c1de8ea10efdbc23b;p=mirror_edk2.git diff --git a/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c b/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c index 38fe89c5c9..a271c81388 100644 --- a/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c +++ b/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c @@ -7,13 +7,13 @@ Tpm2ExecutePendingTpmRequest() will receive untrusted input and do validation. -Copyright (c) 2013 - 2016, 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 +Copyright (c) 2013 - 2018, 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 http://opensource.org/licenses/bsd-license.php -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ @@ -37,7 +37,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include -#include #define CONFIRM_BUFFER_SIZE 4096 @@ -110,7 +109,7 @@ Done: Change EPS. @param[in] PlatformAuth platform auth value. NULL means no platform auth change. - + @retval EFI_SUCCESS Operation completed successfully. **/ EFI_STATUS @@ -146,9 +145,9 @@ Tpm2CommandChangeEps ( @param[in] CommandCode Physical presence operation value. @param[in] CommandParameter Physical presence operation parameter. @param[in, out] PpiFlags The physical presence interface flags. - + @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Unknown physical presence operation. - @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Error occurred during sending command to TPM or + @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Error occurred during sending command to TPM or receiving response from TPM. @retval Others Return code from the TPM device after command execution. **/ @@ -164,9 +163,6 @@ Tcg2ExecutePhysicalPresence ( EFI_TCG2_EVENT_ALGORITHM_BITMAP TpmHashAlgorithmBitmap; UINT32 ActivePcrBanks; - Status = Tpm2GetCapabilitySupportedAndActivePcrs (&TpmHashAlgorithmBitmap, &ActivePcrBanks); - ASSERT_EFI_ERROR (Status); - switch (CommandCode) { case TCG2_PHYSICAL_PRESENCE_CLEAR: case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR: @@ -188,6 +184,20 @@ Tcg2ExecutePhysicalPresence ( return TCG_PP_OPERATION_RESPONSE_SUCCESS; case TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS: + Status = Tpm2GetCapabilitySupportedAndActivePcrs (&TpmHashAlgorithmBitmap, &ActivePcrBanks); + ASSERT_EFI_ERROR (Status); + + // + // PP spec requirements: + // Firmware should check that all requested (set) hashing algorithms are supported with respective PCR banks. + // Firmware has to ensure that at least one PCR banks is active. + // If not, an error is returned and no action is taken. + // + if (CommandParameter == 0 || (CommandParameter & (~TpmHashAlgorithmBitmap)) != 0) { + DEBUG((DEBUG_ERROR, "PCR banks %x to allocate are not supported by TPM. Skip operation\n", CommandParameter)); + return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE; + } + Status = Tpm2PcrAllocateBanks (PlatformAuth, TpmHashAlgorithmBitmap, CommandParameter); if (EFI_ERROR (Status)) { return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE; @@ -204,6 +214,8 @@ Tcg2ExecutePhysicalPresence ( } case TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS: + Status = Tpm2GetCapabilitySupportedAndActivePcrs (&TpmHashAlgorithmBitmap, &ActivePcrBanks); + ASSERT_EFI_ERROR (Status); Status = Tpm2PcrAllocateBanks (PlatformAuth, TpmHashAlgorithmBitmap, TpmHashAlgorithmBitmap); if (EFI_ERROR (Status)) { return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE; @@ -211,6 +223,30 @@ Tcg2ExecutePhysicalPresence ( return TCG_PP_OPERATION_RESPONSE_SUCCESS; } + case TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID: + PpiFlags->PPFlags |= TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_ENABLE_BLOCK_SID; + return TCG_PP_OPERATION_RESPONSE_SUCCESS; + + case TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID: + PpiFlags->PPFlags &= ~TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_ENABLE_BLOCK_SID; + return TCG_PP_OPERATION_RESPONSE_SUCCESS; + + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE: + PpiFlags->PPFlags |= TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID; + return TCG_PP_OPERATION_RESPONSE_SUCCESS; + + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE: + PpiFlags->PPFlags &= ~TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID; + return TCG_PP_OPERATION_RESPONSE_SUCCESS; + + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE: + PpiFlags->PPFlags |= TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID; + return TCG_PP_OPERATION_RESPONSE_SUCCESS; + + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE: + PpiFlags->PPFlags &= ~TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID; + return TCG_PP_OPERATION_RESPONSE_SUCCESS; + default: if (CommandCode <= TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) { return TCG_PP_OPERATION_RESPONSE_SUCCESS; @@ -238,8 +274,8 @@ Tcg2ReadUserKey ( EFI_STATUS Status; EFI_INPUT_KEY Key; UINT16 InputKey; - - InputKey = 0; + + InputKey = 0; do { Status = gBS->CheckEvent (gST->ConIn->WaitForKey); if (!EFI_ERROR (Status)) { @@ -253,13 +289,13 @@ Tcg2ReadUserKey ( if ((Key.ScanCode == SCAN_F12) && CautionKey) { InputKey = Key.ScanCode; } - } + } } while (InputKey == 0); if (InputKey != SCAN_ESC) { return TRUE; } - + return FALSE; } @@ -328,7 +364,7 @@ Tcg2UserConfirm ( { CHAR16 *ConfirmText; CHAR16 *TmpStr1; - CHAR16 *TmpStr2; + CHAR16 *TmpStr2; UINTN BufSize; BOOLEAN CautionKey; BOOLEAN NoPpiInfo; @@ -341,22 +377,6 @@ Tcg2UserConfirm ( UINT32 CurrentPCRBanks; EFI_STATUS Status; - Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **) &Tcg2Protocol); - ASSERT_EFI_ERROR (Status); - - ProtocolCapability.Size = sizeof(ProtocolCapability); - Status = Tcg2Protocol->GetCapability ( - Tcg2Protocol, - &ProtocolCapability - ); - ASSERT_EFI_ERROR (Status); - - Status = Tcg2Protocol->GetActivePcrBanks ( - Tcg2Protocol, - &CurrentPCRBanks - ); - ASSERT_EFI_ERROR (Status); - TmpStr2 = NULL; CautionKey = FALSE; NoPpiInfo = FALSE; @@ -364,6 +384,9 @@ Tcg2UserConfirm ( ConfirmText = AllocateZeroPool (BufSize); ASSERT (ConfirmText != NULL); + mTcg2PpStringPackHandle = HiiAddPackages (&gEfiTcg2PhysicalPresenceGuid, gImageHandle, DxeTcg2PhysicalPresenceLibStrings, NULL); + ASSERT (mTcg2PpStringPackHandle != NULL); + switch (TpmPpCommand) { case TCG2_PHYSICAL_PRESENCE_CLEAR: @@ -380,7 +403,7 @@ Tcg2UserConfirm ( TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR)); StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); - FreePool (TmpStr1); + FreePool (TmpStr1); break; @@ -400,11 +423,27 @@ Tcg2UserConfirm ( TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR)); StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); - FreePool (TmpStr1); + FreePool (TmpStr1); break; case TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS: + Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **) &Tcg2Protocol); + ASSERT_EFI_ERROR (Status); + + ProtocolCapability.Size = sizeof(ProtocolCapability); + Status = Tcg2Protocol->GetCapability ( + Tcg2Protocol, + &ProtocolCapability + ); + ASSERT_EFI_ERROR (Status); + + Status = Tcg2Protocol->GetActivePcrBanks ( + Tcg2Protocol, + &CurrentPCRBanks + ); + ASSERT_EFI_ERROR (Status); + CautionKey = TRUE; TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_SET_PCR_BANKS)); @@ -414,11 +453,11 @@ Tcg2UserConfirm ( TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_SET_PCR_BANKS_1)); StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); - FreePool (TmpStr1); + FreePool (TmpStr1); TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_SET_PCR_BANKS_2)); StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); - FreePool (TmpStr1); + FreePool (TmpStr1); Tcg2FillBufferWithBootHashAlg (TempBuffer, sizeof(TempBuffer), TpmPpCommandParameter); Tcg2FillBufferWithBootHashAlg (TempBuffer2, sizeof(TempBuffer2), CurrentPCRBanks); @@ -429,7 +468,7 @@ Tcg2UserConfirm ( StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); - FreePool (TmpStr1); + FreePool (TmpStr1); break; @@ -443,14 +482,47 @@ Tcg2UserConfirm ( TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CHANGE_EPS_1)); StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); - FreePool (TmpStr1); - + FreePool (TmpStr1); + TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CHANGE_EPS_2)); StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); - FreePool (TmpStr1); + FreePool (TmpStr1); break; - + + case TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID: + TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_ENABLE_BLOCK_SID)); + + TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_HEAD_STR)); + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2); + FreePool (TmpStr1); + break; + + case TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID: + TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_DISABLE_BLOCK_SID)); + + TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_HEAD_STR)); + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2); + FreePool (TmpStr1); + break; + + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE: + NoPpiInfo = TRUE; + TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PP_ENABLE_BLOCK_SID)); + + TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PPI_HEAD_STR)); + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2); + FreePool (TmpStr1); + break; + + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE: + NoPpiInfo = TRUE; + TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PP_DISABLE_BLOCK_SID)); + + TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PPI_HEAD_STR)); + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2); + FreePool (TmpStr1); + break; default: ; @@ -499,31 +571,32 @@ Tcg2UserConfirm ( DstStr[80] = L'\0'; for (Index = 0; Index < StrLen (ConfirmText); Index += 80) { - StrnCpyS (DstStr, sizeof (DstStr) / sizeof (CHAR16), ConfirmText + Index, sizeof (DstStr) / sizeof (CHAR16) - 1); - Print (DstStr); + StrnCpyS (DstStr, sizeof (DstStr) / sizeof (CHAR16), ConfirmText + Index, sizeof (DstStr) / sizeof (CHAR16) - 1); + Print (DstStr); } - + FreePool (TmpStr1); FreePool (TmpStr2); FreePool (ConfirmText); + HiiRemovePackages (mTcg2PpStringPackHandle); if (Tcg2ReadUserKey (CautionKey)) { return TRUE; } - return FALSE; + return FALSE; } /** - Check if there is a valid physical presence command request. Also updates parameter value + Check if there is a valid physical presence command request. Also updates parameter value to whether the requested physical presence command already confirmed by user - - @param[in] TcgPpData EFI Tcg2 Physical Presence request data. + + @param[in] TcgPpData EFI Tcg2 Physical Presence request data. @param[in] Flags The physical presence interface flags. - @param[out] RequestConfirmed If the physical presence operation command required user confirm from UI. - True, it indicates the command doesn't require user confirm, or already confirmed - in last boot cycle by user. - False, it indicates the command need user confirm from UI. + @param[out] RequestConfirmed If the physical presence operation command required user confirm from UI. + True, it indicates the command doesn't require user confirm, or already confirmed + in last boot cycle by user. + False, it indicates the command need user confirm from UI. @retval TRUE Physical Presence operation command is valid. @retval FALSE Physical Presence operation command is invalid. @@ -536,10 +609,22 @@ Tcg2HaveValidTpmRequest ( OUT BOOLEAN *RequestConfirmed ) { - BOOLEAN IsRequestValid; + EFI_TCG2_PROTOCOL *Tcg2Protocol; + EFI_STATUS Status; + BOOLEAN IsRequestValid; *RequestConfirmed = FALSE; + if (TcgPpData->PPRequest <= TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) { + // + // Need TCG2 protocol. + // + Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **) &Tcg2Protocol); + if (EFI_ERROR (Status)) { + return FALSE; + } + } + switch (TcgPpData->PPRequest) { case TCG2_PHYSICAL_PRESENCE_NO_ACTION: *RequestConfirmed = TRUE; @@ -572,11 +657,32 @@ Tcg2HaveValidTpmRequest ( *RequestConfirmed = TRUE; } break; - + case TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS: *RequestConfirmed = TRUE; break; + case TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID: + if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID) == 0) { + *RequestConfirmed = TRUE; + } + break; + + case TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID: + if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID) == 0) { + *RequestConfirmed = TRUE; + } + break; + + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE: + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE: + *RequestConfirmed = TRUE; + break; + + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE: + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE: + break; + default: if (TcgPpData->PPRequest >= TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) { IsRequestValid = Tcg2PpVendorLibHasValidRequest (TcgPpData->PPRequest, Flags.PPFlags, RequestConfirmed); @@ -614,15 +720,15 @@ Tcg2HaveValidTpmRequest ( TcgPpData variable is external input, so this function will validate its data structure to be valid value. - @param[in] PlatformAuth platform auth value. NULL means no platform auth change. - @param[in] TcgPpData Point to the physical presence NV variable. - @param[in] Flags The physical presence interface flags. + @param[in] PlatformAuth platform auth value. NULL means no platform auth change. + @param[in, out] TcgPpData Pointer to the physical presence NV variable. + @param[in, out] Flags Pointer to the physical presence interface flags. **/ VOID Tcg2ExecutePendingTpmRequest ( IN TPM2B_AUTH *PlatformAuth, OPTIONAL - IN EFI_TCG2_PHYSICAL_PRESENCE *TcgPpData, - IN EFI_TCG2_PHYSICAL_PRESENCE_FLAGS Flags + IN OUT EFI_TCG2_PHYSICAL_PRESENCE *TcgPpData, + IN OUT EFI_TCG2_PHYSICAL_PRESENCE_FLAGS *Flags ) { EFI_STATUS Status; @@ -639,7 +745,7 @@ Tcg2ExecutePendingTpmRequest ( return; } - if (!Tcg2HaveValidTpmRequest(TcgPpData, Flags, &RequestConfirmed)) { + if (!Tcg2HaveValidTpmRequest(TcgPpData, *Flags, &RequestConfirmed)) { // // Invalid operation request. // @@ -665,14 +771,14 @@ Tcg2ExecutePendingTpmRequest ( ResetRequired = FALSE; if (TcgPpData->PPRequest >= TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) { - NewFlags = Flags; + NewFlags = *Flags; NewPPFlags = NewFlags.PPFlags; TcgPpData->PPResponse = Tcg2PpVendorLibExecutePendingRequest (PlatformAuth, TcgPpData->PPRequest, &NewPPFlags, &ResetRequired); NewFlags.PPFlags = NewPPFlags; } else { if (!RequestConfirmed) { // - // Print confirm text and wait for approval. + // Print confirm text and wait for approval. // RequestConfirmed = Tcg2UserConfirm (TcgPpData->PPRequest, TcgPpData->PPRequestParameter); } @@ -681,12 +787,12 @@ Tcg2ExecutePendingTpmRequest ( // Execute requested physical presence command // TcgPpData->PPResponse = TCG_PP_OPERATION_RESPONSE_USER_ABORT; - NewFlags = Flags; + NewFlags = *Flags; if (RequestConfirmed) { TcgPpData->PPResponse = Tcg2ExecutePhysicalPresence ( PlatformAuth, - TcgPpData->PPRequest, - TcgPpData->PPRequestParameter, + TcgPpData->PPRequest, + TcgPpData->PPRequestParameter, &NewFlags ); } @@ -695,14 +801,15 @@ Tcg2ExecutePendingTpmRequest ( // // Save the flags if it is updated. // - if (CompareMem (&Flags, &NewFlags, sizeof(EFI_TCG2_PHYSICAL_PRESENCE_FLAGS)) != 0) { + if (CompareMem (Flags, &NewFlags, sizeof(EFI_TCG2_PHYSICAL_PRESENCE_FLAGS)) != 0) { + *Flags = NewFlags; Status = gRT->SetVariable ( TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE, &gEfiTcg2PhysicalPresenceGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, sizeof (EFI_TCG2_PHYSICAL_PRESENCE_FLAGS), &NewFlags - ); + ); } // @@ -710,7 +817,7 @@ Tcg2ExecutePendingTpmRequest ( // if ((NewFlags.PPFlags & TCG2_LIB_PP_FLAG_RESET_TRACK) == 0) { TcgPpData->LastPPRequest = TcgPpData->PPRequest; - TcgPpData->PPRequest = TCG2_PHYSICAL_PRESENCE_NO_ACTION; + TcgPpData->PPRequest = TCG2_PHYSICAL_PRESENCE_NO_ACTION; TcgPpData->PPRequestParameter = 0; } @@ -746,6 +853,16 @@ Tcg2ExecutePendingTpmRequest ( case TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS: break; + case TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID: + case TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID: + break; + + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE: + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE: + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE: + case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE: + return; + default: if (TcgPpData->LastPPRequest >= TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) { if (ResetRequired) { @@ -762,19 +879,19 @@ Tcg2ExecutePendingTpmRequest ( Print (L"Rebooting system to make TPM2 settings in effect\n"); gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL); - ASSERT (FALSE); + ASSERT (FALSE); } /** Check and execute the pending TPM request. - The TPM request may come from OS or BIOS. This API will display request information and wait + The TPM request may come from OS or BIOS. This API will display request information and wait for user confirmation if TPM request exists. The TPM request will be sent to TPM device after - the TPM request is confirmed, and one or more reset may be required to make TPM request to + the TPM request is confirmed, and one or more reset may be required to make TPM request to take effect. - + This API should be invoked after console in and console out are all ready as they are required - to display request information and get user input to confirm the request. + to display request information and get user input to confirm the request. @param[in] PlatformAuth platform auth value. NULL means no platform auth change. **/ @@ -787,20 +904,26 @@ Tcg2PhysicalPresenceLibProcessRequest ( EFI_STATUS Status; UINTN DataSize; EFI_TCG2_PHYSICAL_PRESENCE TcgPpData; - EFI_TCG2_PROTOCOL *Tcg2Protocol; EDKII_VARIABLE_LOCK_PROTOCOL *VariableLockProtocol; EFI_TCG2_PHYSICAL_PRESENCE_FLAGS PpiFlags; // - // Process the storage related action first. + // This flags variable controls whether physical presence is required for TPM command. + // It should be protected from malicious software. We set it as read-only variable here. // - TcgPhysicalPresenceStorageLibProcessRequest(); - - Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **) &Tcg2Protocol); - if (EFI_ERROR (Status)) { - return ; + Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **)&VariableLockProtocol); + if (!EFI_ERROR (Status)) { + Status = VariableLockProtocol->RequestToLock ( + VariableLockProtocol, + TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE, + &gEfiTcg2PhysicalPresenceGuid + ); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "[TPM2] Error when lock variable %s, Status = %r\n", TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE, Status)); + ASSERT_EFI_ERROR (Status); + } } - + // // Check S4 resume // @@ -809,9 +932,6 @@ Tcg2PhysicalPresenceLibProcessRequest ( return ; } - mTcg2PpStringPackHandle = HiiAddPackages (&gEfiTcg2PhysicalPresenceGuid, gImageHandle, DxeTcg2PhysicalPresenceLibStrings, NULL); - ASSERT (mTcg2PpStringPackHandle != NULL); - // // Initialize physical presence flags. // @@ -824,7 +944,7 @@ Tcg2PhysicalPresenceLibProcessRequest ( &PpiFlags ); if (EFI_ERROR (Status)) { - PpiFlags.PPFlags = TCG2_BIOS_TPM_MANAGEMENT_FLAG_DEFAULT; + PpiFlags.PPFlags = PcdGet32(PcdTcg2PhysicalPresenceFlags); Status = gRT->SetVariable ( TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE, &gEfiTcg2PhysicalPresenceGuid, @@ -836,26 +956,9 @@ Tcg2PhysicalPresenceLibProcessRequest ( DEBUG ((EFI_D_ERROR, "[TPM2] Set physical presence flag failed, Status = %r\n", Status)); return ; } + DEBUG((DEBUG_INFO, "[TPM2] Initial physical presence flags value is 0x%x\n", PpiFlags.PPFlags)); } - DEBUG ((EFI_D_INFO, "[TPM2] PpiFlags = %x\n", PpiFlags.PPFlags)); - // - // This flags variable controls whether physical presence is required for TPM command. - // It should be protected from malicious software. We set it as read-only variable here. - // - Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **)&VariableLockProtocol); - if (!EFI_ERROR (Status)) { - Status = VariableLockProtocol->RequestToLock ( - VariableLockProtocol, - TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE, - &gEfiTcg2PhysicalPresenceGuid - ); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "[TPM2] Error when lock variable %s, Status = %r\n", TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE, Status)); - ASSERT_EFI_ERROR (Status); - } - } - // // Initialize physical presence variable. // @@ -887,8 +990,8 @@ Tcg2PhysicalPresenceLibProcessRequest ( // // Execute pending TPM request. - // - Tcg2ExecutePendingTpmRequest (PlatformAuth, &TcgPpData, PpiFlags); + // + Tcg2ExecutePendingTpmRequest (PlatformAuth, &TcgPpData, &PpiFlags); DEBUG ((EFI_D_INFO, "[TPM2] PPResponse = %x (LastPPRequest=%x, Flags=%x)\n", TcgPpData.PPResponse, TcgPpData.LastPPRequest, PpiFlags.PPFlags)); } @@ -898,7 +1001,7 @@ Tcg2PhysicalPresenceLibProcessRequest ( The TPM request may come from OS. This API will check if TPM request exists and need user input to confirmation. - + @retval TRUE TPM needs input to confirm user physical presence. @retval FALSE TPM doesn't need input to confirm user physical presence. @@ -913,23 +1016,8 @@ Tcg2PhysicalPresenceLibNeedUserConfirm( EFI_TCG2_PHYSICAL_PRESENCE TcgPpData; UINTN DataSize; BOOLEAN RequestConfirmed; - EFI_TCG2_PROTOCOL *Tcg2Protocol; EFI_TCG2_PHYSICAL_PRESENCE_FLAGS PpiFlags; - // - // Process the storage related action first. - // If confirm need user confirm, just return TRUE. - // else continue check other actions. - // - if (TcgPhysicalPresenceStorageLibNeedUserConfirm()) { - return TRUE; - } - - Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **) &Tcg2Protocol); - if (EFI_ERROR (Status)) { - return FALSE; - } - // // Check S4 resume // @@ -964,7 +1052,7 @@ Tcg2PhysicalPresenceLibNeedUserConfirm( if (EFI_ERROR (Status)) { return FALSE; } - + if (TcgPpData.PPRequest == TCG2_PHYSICAL_PRESENCE_NO_ACTION) { // // No operation request @@ -1009,7 +1097,7 @@ Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction ( EFI_STATUS Status; UINTN DataSize; EFI_TCG2_PHYSICAL_PRESENCE PpData; - + DEBUG ((EFI_D_INFO, "[TPM2] ReturnOperationResponseToOsFunction\n")); // @@ -1029,7 +1117,7 @@ Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction ( DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status)); return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_FAILURE; } - + *MostRecentRequest = PpData.LastPPRequest; *Response = PpData.PPResponse; @@ -1042,7 +1130,7 @@ Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction ( Submit TPM Operation Request to Pre-OS Environment 2. Caution: This function may receive untrusted input. - + @param[in] OperationRequest TPM physical presence operation request. @param[in] RequestParameter TPM physical presence operation request parameter. @@ -1079,13 +1167,8 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction ( return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; } - if (((OperationRequest > TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) && - (OperationRequest < TCG2_PHYSICAL_PRESENCE_STORAGE_MANAGEMENT_BEGIN)) || - ((OperationRequest > TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE) && - (OperationRequest < TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION))) { - // - // This command requires UI to prompt user for Auth data. - // + if ((OperationRequest > TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) && + (OperationRequest < TCG2_PHYSICAL_PRESENCE_STORAGE_MANAGEMENT_BEGIN) ) { return TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED; } @@ -1101,11 +1184,10 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction ( DataSize, &PpData ); - } - - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "[TPM2] Set PP variable failure! Status = %r\n", Status)); - return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "[TPM2] Set PP variable failure! Status = %r\n", Status)); + return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; + } } if (OperationRequest >= TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) { @@ -1118,10 +1200,41 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction ( &Flags ); if (EFI_ERROR (Status)) { - Flags.PPFlags = TCG2_BIOS_TPM_MANAGEMENT_FLAG_DEFAULT; + Flags.PPFlags = TCG2_BIOS_TPM_MANAGEMENT_FLAG_DEFAULT | TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_DEFAULT; } return Tcg2PpVendorLibSubmitRequestToPreOSFunction (OperationRequest, Flags.PPFlags, RequestParameter); } return TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS; } + +/** + Return TPM2 ManagementFlags set by PP interface. + + @retval ManagementFlags TPM2 Management Flags. +**/ +UINT32 +EFIAPI +Tcg2PhysicalPresenceLibGetManagementFlags ( + VOID + ) +{ + EFI_STATUS Status; + EFI_TCG2_PHYSICAL_PRESENCE_FLAGS PpiFlags; + UINTN DataSize; + + DEBUG ((EFI_D_INFO, "[TPM2] GetManagementFlags\n")); + + DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE_FLAGS); + Status = gRT->GetVariable ( + TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE, + &gEfiTcg2PhysicalPresenceGuid, + NULL, + &DataSize, + &PpiFlags + ); + if (EFI_ERROR (Status)) { + PpiFlags.PPFlags = TCG2_BIOS_TPM_MANAGEMENT_FLAG_DEFAULT | TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_DEFAULT; + } + return PpiFlags.PPFlags; +}