X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=SecurityPkg%2FTcg%2FTcgSmm%2FTcgSmm.c;h=96fb456ccd9bd1c3c6dcb0e4f53bbaa1f5b614ce;hp=ab2df664d771a90bdcb0de10e569f69623c185ea;hb=4610b23ab10942d140eb51c4bdbefc5f896979ad;hpb=0f7f6d23ea54f81ef6a75a83a4c973324a06f99d diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.c b/SecurityPkg/Tcg/TcgSmm/TcgSmm.c index ab2df664d7..96fb456ccd 100644 --- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.c +++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.c @@ -2,7 +2,13 @@ It updates TPM items in ACPI table and registers SMI callback functions for physical presence and ClearMemory. -Copyright (c) 2011, Intel Corporation. All rights reserved.
+ Caution: This module requires additional review when modified. + This driver will have external input - variable and ACPINvs data in SMM mode. + This external input must be validated carefully to avoid security issue. + + PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check. + +Copyright (c) 2011 - 2015, 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 @@ -13,61 +19,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -// -// AML parsing definitions -// -#define AML_OPREGION_OP 0x80 -#define AML_BYTE_PREFIX 0x0A -#define AML_DWORD_PREFIX 0x0C - -#pragma pack(1) -typedef struct { - UINT8 SoftwareSmi; - UINT32 Parameter; - UINT32 Response; - UINT32 Request; - UINT32 LastRequest; - UINT32 ReturnCode; -} PHYSICAL_PRESENCE_NVS; - -typedef struct { - UINT8 SoftwareSmi; - UINT32 Parameter; - UINT32 Request; -} MEMORY_CLEAR_NVS; - -typedef struct { - PHYSICAL_PRESENCE_NVS PhysicalPresence; - MEMORY_CLEAR_NVS MemoryClear; -} TCG_NVS; - -typedef struct { - UINT8 OpRegionOp; - UINT32 NameString; - UINT8 RegionSpace; - UINT8 DWordPrefix; - UINT32 RegionOffset; - UINT8 BytePrefix; - UINT8 RegionLen; -} AML_OP_REGION_32_8; -#pragma pack() +#include "TcgSmm.h" EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable; TCG_NVS *mTcgNvs; @@ -75,6 +27,10 @@ TCG_NVS *mTcgNvs; /** Software SMI callback for TPM physical presence which is called from ACPI method. + Caution: This function may receive untrusted input. + Variable and ACPINvs are external input, so this function will validate + its data structure to be valid value. + @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister(). @param[in] Context Points to an optional handler context which was specified when the handler was registered. @@ -97,7 +53,7 @@ PhysicalPresenceCallback ( EFI_STATUS Status; UINTN DataSize; EFI_PHYSICAL_PRESENCE PpData; - UINT8 Flags; + EFI_PHYSICAL_PRESENCE_FLAGS Flags; BOOLEAN RequestConfirmed; // @@ -111,28 +67,31 @@ PhysicalPresenceCallback ( &DataSize, &PpData ); - if (EFI_ERROR (Status)) { - return EFI_SUCCESS; - } DEBUG ((EFI_D_INFO, "[TPM] PP callback, Parameter = %x\n", mTcgNvs->PhysicalPresence.Parameter)); - if (mTcgNvs->PhysicalPresence.Parameter == 5) { - // - // Return TPM Operation Response to OS Environment - // + if (mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_RETURN_REQUEST_RESPONSE_TO_OS) { + if (EFI_ERROR (Status)) { + mTcgNvs->PhysicalPresence.ReturnCode = PP_RETURN_TPM_OPERATION_RESPONSE_FAILURE; + mTcgNvs->PhysicalPresence.LastRequest = 0; + mTcgNvs->PhysicalPresence.Response = 0; + DEBUG ((EFI_D_ERROR, "[TPM] Get PP variable failure! Status = %r\n", Status)); + return EFI_SUCCESS; + } + mTcgNvs->PhysicalPresence.ReturnCode = PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS; mTcgNvs->PhysicalPresence.LastRequest = PpData.LastPPRequest; mTcgNvs->PhysicalPresence.Response = PpData.PPResponse; - - } else if ((mTcgNvs->PhysicalPresence.Parameter == 2) || (mTcgNvs->PhysicalPresence.Parameter == 7)) { - // - // Submit TPM Operation Request to Pre-OS Environment - // - - if (mTcgNvs->PhysicalPresence.Request == SET_OPERATOR_AUTH) { + } else if ((mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS) + || (mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS_2)) { + if (EFI_ERROR (Status)) { + mTcgNvs->PhysicalPresence.ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; + DEBUG ((EFI_D_ERROR, "[TPM] Get PP variable failure! Status = %r\n", Status)); + return EFI_SUCCESS; + } + if (mTcgNvs->PhysicalPresence.Request == PHYSICAL_PRESENCE_SET_OPERATOR_AUTH) { // - // This command requires UI to prompt user for Auth data, NOT implemented. + // This command requires UI to prompt user for Auth data. // - mTcgNvs->PhysicalPresence.ReturnCode = 1; + mTcgNvs->PhysicalPresence.ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED; return EFI_SUCCESS; } @@ -149,83 +108,111 @@ PhysicalPresenceCallback ( } if (EFI_ERROR (Status)) { - // - // General failure. - // - mTcgNvs->PhysicalPresence.ReturnCode = 2; + mTcgNvs->PhysicalPresence.ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; + return EFI_SUCCESS; + } + mTcgNvs->PhysicalPresence.ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS; + + if (mTcgNvs->PhysicalPresence.Request >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) { + DataSize = sizeof (EFI_PHYSICAL_PRESENCE_FLAGS); + Status = mSmmVariable->SmmGetVariable ( + PHYSICAL_PRESENCE_FLAGS_VARIABLE, + &gEfiPhysicalPresenceGuid, + NULL, + &DataSize, + &Flags + ); + if (EFI_ERROR (Status)) { + Flags.PPFlags = TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION; + } + mTcgNvs->PhysicalPresence.ReturnCode = TcgPpVendorLibSubmitRequestToPreOSFunction (mTcgNvs->PhysicalPresence.Request, Flags.PPFlags); + } + } else if (mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_GET_USER_CONFIRMATION_STATUS_FOR_REQUEST) { + if (EFI_ERROR (Status)) { + mTcgNvs->PhysicalPresence.ReturnCode = TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION; + DEBUG ((EFI_D_ERROR, "[TPM] Get PP variable failure! Status = %r\n", Status)); return EFI_SUCCESS; } - mTcgNvs->PhysicalPresence.ReturnCode = 0; - } else if (mTcgNvs->PhysicalPresence.Parameter == 8) { - // - // Get User Confirmation Status for Operation // - Flags = PpData.Flags; + // Get the Physical Presence flags + // + DataSize = sizeof (EFI_PHYSICAL_PRESENCE_FLAGS); + Status = mSmmVariable->SmmGetVariable ( + PHYSICAL_PRESENCE_FLAGS_VARIABLE, + &gEfiPhysicalPresenceGuid, + NULL, + &DataSize, + &Flags + ); + if (EFI_ERROR (Status)) { + mTcgNvs->PhysicalPresence.ReturnCode = TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION; + DEBUG ((EFI_D_ERROR, "[TPM] Get PP flags failure! Status = %r\n", Status)); + return EFI_SUCCESS; + } + RequestConfirmed = FALSE; switch (mTcgNvs->PhysicalPresence.Request) { - case ENABLE: - case DISABLE: - case ACTIVATE: - case DEACTIVATE: - case ENABLE_ACTIVATE: - case DEACTIVATE_DISABLE: - case SET_OWNER_INSTALL_TRUE: - case SET_OWNER_INSTALL_FALSE: - case ENABLE_ACTIVATE_OWNER_TRUE: - case DEACTIVATE_DISABLE_OWNER_FALSE: - if ((Flags & FLAG_NO_PPI_PROVISION) != 0) { + case PHYSICAL_PRESENCE_ENABLE: + case PHYSICAL_PRESENCE_DISABLE: + case PHYSICAL_PRESENCE_ACTIVATE: + case PHYSICAL_PRESENCE_DEACTIVATE: + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE: + case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE: + case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE: + case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE: + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE: + case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE: + if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION) != 0) { RequestConfirmed = TRUE; } break; - case CLEAR: - case ENABLE_ACTIVATE_CLEAR: - if ((Flags & FLAG_NO_PPI_CLEAR) != 0) { + case PHYSICAL_PRESENCE_CLEAR: + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR: + if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) != 0) { RequestConfirmed = TRUE; } break; - case DEFERRED_PP_UNOWNERED_FIELD_UPGRADE: - if ((Flags & FLAG_NO_PPI_MAINTENANCE) != 0) { + case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE: + if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE) != 0) { RequestConfirmed = TRUE; } break; - case ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE: - case CLEAR_ENABLE_ACTIVATE: - if ((Flags & FLAG_NO_PPI_CLEAR) != 0 && (Flags & FLAG_NO_PPI_PROVISION) != 0) { + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE: + case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE: + if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) != 0 && (Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION) != 0) { RequestConfirmed = TRUE; } break; - case SET_NO_PPI_PROVISION_FALSE: - case SET_NO_PPI_CLEAR_FALSE: - case SET_NO_PPI_MAINTENANCE_FALSE: - case NO_ACTION: + case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE: + case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE: + case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE: + case PHYSICAL_PRESENCE_NO_ACTION: RequestConfirmed = TRUE; break; - case SET_OPERATOR_AUTH: + case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH: // // This command requires UI to prompt user for Auth data - // Here it is NOT implemented // - mTcgNvs->PhysicalPresence.ReturnCode = 0; + mTcgNvs->PhysicalPresence.ReturnCode = TCG_PP_GET_USER_CONFIRMATION_NOT_IMPLEMENTED; return EFI_SUCCESS; + default: + break; } if (RequestConfirmed) { - // - // Allowed and physically present user not required - // - mTcgNvs->PhysicalPresence.ReturnCode = 4; + mTcgNvs->PhysicalPresence.ReturnCode = TCG_PP_GET_USER_CONFIRMATION_ALLOWED_AND_PPUSER_NOT_REQUIRED; } else { - // - // Allowed and physically present user required - // - mTcgNvs->PhysicalPresence.ReturnCode = 3; + mTcgNvs->PhysicalPresence.ReturnCode = TCG_PP_GET_USER_CONFIRMATION_ALLOWED_AND_PPUSER_REQUIRED; } + if (mTcgNvs->PhysicalPresence.Request >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) { + mTcgNvs->PhysicalPresence.ReturnCode = TcgPpVendorLibGetUserConfirmationStatusFunction (mTcgNvs->PhysicalPresence.Request, Flags.PPFlags); + } } return EFI_SUCCESS; @@ -235,6 +222,10 @@ PhysicalPresenceCallback ( /** Software SMI callback for MemoryClear which is called from ACPI method. + Caution: This function may receive untrusted input. + Variable and ACPINvs are external input, so this function will validate + its data structure to be valid value. + @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister(). @param[in] Context Points to an optional handler context which was specified when the handler was registered. @@ -258,15 +249,10 @@ MemoryClearCallback ( UINTN DataSize; UINT8 MorControl; - if (mTcgNvs->MemoryClear.Parameter == 1) { - // - // Called from ACPI _DSM method, save the MOR data to variable. - // + mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_SUCCESS; + if (mTcgNvs->MemoryClear.Parameter == ACPI_FUNCTION_DSM_MEMORY_CLEAR_INTERFACE) { MorControl = (UINT8) mTcgNvs->MemoryClear.Request; - } else if (mTcgNvs->MemoryClear.Parameter == 2) { - // - // Called from ACPI _PTS method, setup ClearMemory flags if needed. - // + } else if (mTcgNvs->MemoryClear.Parameter == ACPI_FUNCTION_PTS_CLEAR_MOR_BIT) { DataSize = sizeof (UINT8); Status = mSmmVariable->SmmGetVariable ( MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, @@ -276,7 +262,8 @@ MemoryClearCallback ( &MorControl ); if (EFI_ERROR (Status)) { - ASSERT (Status == EFI_NOT_FOUND); + mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_GENERAL_FAILURE; + DEBUG ((EFI_D_ERROR, "[TPM] Get MOR variable failure! Status = %r\n", Status)); return EFI_SUCCESS; } @@ -294,7 +281,10 @@ MemoryClearCallback ( DataSize, &MorControl ); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_GENERAL_FAILURE; + DEBUG ((EFI_D_ERROR, "[TPM] Set MOR variable failure! Status = %r\n", Status)); + } return EFI_SUCCESS; } @@ -329,9 +319,8 @@ AssignOpRegion ( for (OpRegion = (AML_OP_REGION_32_8 *) (Table + 1); OpRegion <= (AML_OP_REGION_32_8 *) ((UINT8 *) Table + Table->Length); OpRegion = (AML_OP_REGION_32_8 *) ((UINT8 *) OpRegion + 1)) { - if ((OpRegion->OpRegionOp == AML_OPREGION_OP) && + if ((OpRegion->OpRegionOp == AML_EXT_REGION_OP) && (OpRegion->NameString == Name) && - (OpRegion->RegionLen == Size) && (OpRegion->DWordPrefix == AML_DWORD_PREFIX) && (OpRegion->BytePrefix == AML_BYTE_PREFIX)) { @@ -339,6 +328,7 @@ AssignOpRegion ( ASSERT_EFI_ERROR (Status); ZeroMem ((VOID *)(UINTN)MemoryAddress, Size); OpRegion->RegionOffset = (UINT32) (UINTN) MemoryAddress; + OpRegion->RegionLen = (UINT8) Size; break; } } @@ -373,7 +363,22 @@ PublishAcpiTable ( ); ASSERT_EFI_ERROR (Status); + + // + // Measure to PCR[0] with event EV_POST_CODE ACPI DATA + // + TpmMeasureAndLogData( + 0, + EV_POST_CODE, + EV_POSTCODE_INFO_ACPI_DATA, + ACPI_DATA_LEN, + Table, + TableSize + ); + + ASSERT (Table->OemTableId == SIGNATURE_64 ('T', 'c', 'g', 'T', 'a', 'b', 'l', 'e')); + CopyMem (Table->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (Table->OemId) ); mTcgNvs = AssignOpRegion (Table, SIGNATURE_32 ('T', 'N', 'V', 'S'), (UINT16) sizeof (TCG_NVS)); ASSERT (mTcgNvs != NULL); @@ -420,6 +425,11 @@ InitializeTcgSmm ( EFI_SMM_SW_REGISTER_CONTEXT SwContext; EFI_HANDLE SwHandle; + if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)){ + DEBUG ((EFI_D_ERROR, "No TPM12 instance required!\n")); + return EFI_UNSUPPORTED; + } + Status = PublishAcpiTable (); ASSERT_EFI_ERROR (Status);