From 90d2d0fe52ca6f3b61056e7b239da696713eaec1 Mon Sep 17 00:00:00 2001 From: Chris Engel Date: Mon, 31 Jul 2017 17:18:15 -0500 Subject: Fix HDAT support for TPM log to support events after HDAT is populated Change-Id: I55a85f48e9238846134cdc39bcb4e5e03466bce5 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/43961 Reviewed-by: Stephen M. Cprek Tested-by: Jenkins Server Reviewed-by: Nicholas E. Bofferding Reviewed-by: Timothy R. Block Tested-by: Jenkins OP Build CI Tested-by: FSP CI Jenkins Tested-by: Jenkins OP HW Reviewed-by: Daniel M. Crowell --- src/usr/runtime/populate_hbruntime.C | 22 ++++++++++------------ src/usr/secureboot/trusted/tpmLogMgr.C | 33 +++++++++++++++++++++++++++++++++ src/usr/secureboot/trusted/tpmLogMgr.H | 9 +++++++++ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/usr/runtime/populate_hbruntime.C b/src/usr/runtime/populate_hbruntime.C index bc2915ddd..eb92807fe 100644 --- a/src/usr/runtime/populate_hbruntime.C +++ b/src/usr/runtime/populate_hbruntime.C @@ -1252,18 +1252,16 @@ errlHndl_t populate_TpmInfoByNode() if(pLogMgr != nullptr) { #ifdef CONFIG_TPMDD - auto const * const pLogStart = - TRUSTEDBOOT::TpmLogMgr_getLogStartPtr(pLogMgr); - assert(pLogStart != nullptr,"populate_TpmInfoByNode: BUG! An " - "allocated log manager's log start pointer should never be " - "nullptr"); - - logSize = (pLogMgr->logSize < TPM_SRTM_EVENT_LOG_MAX) ? - pLogMgr->logSize : TPM_SRTM_EVENT_LOG_MAX; - - memcpy(reinterpret_cast(l_baseAddr + l_currOffset), - pLogStart, - logSize); + + // The log size always has to be specified to the max + // this is because after HDAT is populated additional + // entries can be posted to the log to cause it to + // grow beyond its current size + logSize = TPM_SRTM_EVENT_LOG_MAX; + + TRUSTEDBOOT::TpmLogMgr_relocateTpmLog(pLogMgr, + reinterpret_cast(l_baseAddr + l_currOffset), + logSize); #endif } else diff --git a/src/usr/secureboot/trusted/tpmLogMgr.C b/src/usr/secureboot/trusted/tpmLogMgr.C index fe773d5f3..625c6261a 100644 --- a/src/usr/secureboot/trusted/tpmLogMgr.C +++ b/src/usr/secureboot/trusted/tpmLogMgr.C @@ -572,6 +572,39 @@ namespace TRUSTEDBOOT i_val->devtreeI2cMasterOffset = i_i2cMasterOffset; } + void TpmLogMgr_relocateTpmLog(TpmLogMgr* i_val, + uint8_t* i_newLog, + size_t i_maxSize) + { + mutex_lock( &i_val->logMutex ); + + TRACUCOMP( g_trac_trustedboot, + ">>relocateTpmLog() LogSize:%d MaxSize:%d", + i_val->logSize, i_maxSize); + + assert(i_newLog != NULL, "Bug! Log start address is nullptr"); + assert(i_val->eventLogInMem == NULL, + "relocateTpmLog can only be called once"); + assert(i_val->logSize < i_maxSize, + "Logsize is greater than maxsize"); + + // Point logMgr to new location + i_val->eventLogInMem = i_newLog; + + // Copy log into new location + memset(i_val->eventLogInMem, 0, i_maxSize); + memcpy(i_val->eventLogInMem, i_val->eventLog, i_val->logSize); + i_val->newEventPtr = i_val->eventLogInMem + i_val->logSize; + + mutex_unlock( &i_val->logMutex ); + + TRACUCOMP( g_trac_trustedboot, + "<