X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=SecurityPkg%2FTcg%2FTcgSmm%2FTcgSmm.c;h=6080eff3b7b880346e0a2b37b0a0add1a4f5a348;hp=ba660c1ee6082158a3112d6dcd8cca802c1eb76a;hb=8a8c6c962a4abc75224799bfd03f2f68bb2a89e3;hpb=607599bf3d054da087529e58883650ad693aad3d diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.c b/SecurityPkg/Tcg/TcgSmm/TcgSmm.c index ba660c1ee6..6080eff3b7 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 - 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 @@ -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. @@ -112,27 +68,22 @@ PhysicalPresenceCallback ( &PpData ); if (EFI_ERROR (Status)) { + mTcgNvs->PhysicalPresence.ReturnCode = PP_SUBMIT_REQUEST_GENERAL_FAILURE; + DEBUG ((EFI_D_ERROR, "[TPM] Get PP variable failure! Status = %r\n", 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) { 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 - // - + } else if ((mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS) + || (mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS_2)) { 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 = PP_SUBMIT_REQUEST_NOT_IMPLEMENTED; return EFI_SUCCESS; } @@ -149,18 +100,28 @@ PhysicalPresenceCallback ( } if (EFI_ERROR (Status)) { - // - // General failure. - // - mTcgNvs->PhysicalPresence.ReturnCode = 2; + mTcgNvs->PhysicalPresence.ReturnCode = PP_SUBMIT_REQUEST_GENERAL_FAILURE; return EFI_SUCCESS; } - mTcgNvs->PhysicalPresence.ReturnCode = 0; - } else if (mTcgNvs->PhysicalPresence.Parameter == 8) { - // - // Get User Confirmation Status for Operation + mTcgNvs->PhysicalPresence.ReturnCode = PP_SUBMIT_REQUEST_SUCCESS; + } else if (mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_GET_USER_CONFIRMATION_STATUS_FOR_REQUEST) { + // + // Get the Physical Presence flags // - Flags = PpData.Flags; + DataSize = sizeof (UINT8); + Status = mSmmVariable->SmmGetVariable ( + PHYSICAL_PRESENCE_FLAGS_VARIABLE, + &gEfiPhysicalPresenceGuid, + NULL, + &DataSize, + &Flags + ); + if (EFI_ERROR (Status)) { + mTcgNvs->PhysicalPresence.ReturnCode = PP_SUBMIT_REQUEST_GENERAL_FAILURE; + DEBUG ((EFI_D_ERROR, "[TPM] Get PP flags failure! Status = %r\n", Status)); + return EFI_SUCCESS; + } + RequestConfirmed = FALSE; switch (mTcgNvs->PhysicalPresence.Request) { @@ -209,22 +170,15 @@ PhysicalPresenceCallback ( 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 = PP_REQUEST_NOT_IMPLEMENTED; return EFI_SUCCESS; } if (RequestConfirmed) { - // - // Allowed and physically present user not required - // - mTcgNvs->PhysicalPresence.ReturnCode = 4; + mTcgNvs->PhysicalPresence.ReturnCode = PP_REQUEST_ALLOWED_AND_PPUSER_NOT_REQUIRED; } else { - // - // Allowed and physically present user required - // - mTcgNvs->PhysicalPresence.ReturnCode = 3; + mTcgNvs->PhysicalPresence.ReturnCode = PP_REQUEST_ALLOWED_AND_PPUSER_REQUIRED; } } @@ -235,6 +189,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 +216,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 +229,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 +248,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 +286,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 +295,7 @@ AssignOpRegion ( ASSERT_EFI_ERROR (Status); ZeroMem ((VOID *)(UINTN)MemoryAddress, Size); OpRegion->RegionOffset = (UINT32) (UINTN) MemoryAddress; + OpRegion->RegionLen = (UINT8) Size; break; } } @@ -373,7 +330,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 +392,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);