SecurityPkg HashLibRouter: Avoid incorrect PcdTcg2HashAlgorithmBitmap
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=244 Currently, when software HashLib (HashLibBaseCryptoRouter) and related HashInstanceLib instances are used, PcdTcg2HashAlgorithmBitmap is expected to be configured to 0 in platform dsc. But PcdTcg2HashAlgorithmBitmap has default value 0xFFFFFFFF in SecurityPkg.dec, and some platforms forget to configure it to 0 or still configure it to 0xFFFFFFFF in platform dsc, that will make final PcdTcg2HashAlgorithmBitmap value incorrect. This patch is to add CONSTRUCTOR in HashLib (HashLibBaseCryptoRouter) and PcdTcg2HashAlgorithmBitmap will be set to 0 in the CONSTRUCTOR. Current HASH_LIB_PEI_ROUTER_GUID HOB created in HashLibBaseCryptoRouterPei is shared between modules that link HashLibBaseCryptoRouterPei. To avoid mutual interference, separated HASH_LIB_PEI_ROUTER_GUID HOBs with gEfiCallerIdGuid Identifier will be created for those modules. This patch is also to add check in HashLib (HashLibBaseCryptoRouter) for the mismatch of supported HashMask between modules that may link different HashInstanceLib instances, warning will be reported if mismatch is found. Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Chao Zhang <chao.b.zhang@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> Reviewed-by: Chao Zhang <chao.b.zhang@intel.com>
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
hash handler registerd, such as SHA1, SHA256.
|
||||
Platform can use PcdTpm2HashMask to mask some hash engines.
|
||||
|
||||
Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>
|
||||
Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved. <BR>
|
||||
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
|
||||
@ -28,6 +28,30 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
HASH_INTERFACE mHashInterface[HASH_COUNT] = {{{0}, NULL, NULL, NULL}};
|
||||
UINTN mHashInterfaceCount = 0;
|
||||
|
||||
UINT32 mSupportedHashMaskLast = 0;
|
||||
UINT32 mSupportedHashMaskCurrent = 0;
|
||||
|
||||
/**
|
||||
Check mismatch of supported HashMask between modules
|
||||
that may link different HashInstanceLib instances.
|
||||
|
||||
**/
|
||||
VOID
|
||||
CheckSupportedHashMaskMismatch (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
if (mSupportedHashMaskCurrent != mSupportedHashMaskLast) {
|
||||
DEBUG ((
|
||||
DEBUG_WARN,
|
||||
"WARNING: There is mismatch of supported HashMask (0x%x - 0x%x) between modules\n",
|
||||
mSupportedHashMaskCurrent,
|
||||
mSupportedHashMaskLast
|
||||
));
|
||||
DEBUG ((DEBUG_WARN, "that are linking different HashInstanceLib instances!\n"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Start hash sequence.
|
||||
|
||||
@ -50,6 +74,8 @@ HashStart (
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
CheckSupportedHashMaskMismatch ();
|
||||
|
||||
HashCtx = AllocatePool (sizeof(*HashCtx) * mHashInterfaceCount);
|
||||
ASSERT (HashCtx != NULL);
|
||||
|
||||
@ -90,6 +116,8 @@ HashUpdate (
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
CheckSupportedHashMaskMismatch ();
|
||||
|
||||
HashCtx = (HASH_HANDLE *)HashHandle;
|
||||
|
||||
for (Index = 0; Index < mHashInterfaceCount; Index++) {
|
||||
@ -133,6 +161,8 @@ HashCompleteAndExtend (
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
CheckSupportedHashMaskMismatch ();
|
||||
|
||||
HashCtx = (HASH_HANDLE *)HashHandle;
|
||||
ZeroMem (DigestList, sizeof(*DigestList));
|
||||
|
||||
@ -180,6 +210,8 @@ HashAndExtend (
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
CheckSupportedHashMaskMismatch ();
|
||||
|
||||
HashStart (&HashHandle);
|
||||
HashUpdate (HashHandle, DataToHash, DataToHashLen);
|
||||
Status = HashCompleteAndExtend (HashHandle, PcrIndex, NULL, 0, DigestList);
|
||||
@ -204,7 +236,6 @@ RegisterHashInterfaceLib (
|
||||
{
|
||||
UINTN Index;
|
||||
UINT32 HashMask;
|
||||
UINT32 BiosSupportedHashMask;
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
@ -218,21 +249,58 @@ RegisterHashInterfaceLib (
|
||||
if (mHashInterfaceCount >= sizeof(mHashInterface)/sizeof(mHashInterface[0])) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
BiosSupportedHashMask = PcdGet32 (PcdTcg2HashAlgorithmBitmap);
|
||||
Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, BiosSupportedHashMask | HashMask);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
//
|
||||
// Check duplication
|
||||
//
|
||||
for (Index = 0; Index < mHashInterfaceCount; Index++) {
|
||||
if (CompareGuid (&mHashInterface[Index].HashGuid, &HashInterface->HashGuid)) {
|
||||
DEBUG ((DEBUG_ERROR, "Hash Interface (%g) has been registered\n", &HashInterface->HashGuid));
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Record hash algorithm bitmap of CURRENT module which consumes HashLib.
|
||||
//
|
||||
mSupportedHashMaskCurrent = PcdGet32 (PcdTcg2HashAlgorithmBitmap) | HashMask;
|
||||
Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, mSupportedHashMaskCurrent);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
CopyMem (&mHashInterface[mHashInterfaceCount], HashInterface, sizeof(*HashInterface));
|
||||
mHashInterfaceCount ++;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
The constructor function of HashLibBaseCryptoRouterDxe.
|
||||
|
||||
@param ImageHandle The firmware allocated handle for the EFI image.
|
||||
@param SystemTable A pointer to the EFI System Table.
|
||||
|
||||
@retval EFI_SUCCESS The constructor executed correctly.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
HashLibBaseCryptoRouterDxeConstructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
// Record hash algorithm bitmap of LAST module which also consumes HashLib.
|
||||
//
|
||||
mSupportedHashMaskLast = PcdGet32 (PcdTcg2HashAlgorithmBitmap);
|
||||
|
||||
//
|
||||
// Set PcdTcg2HashAlgorithmBitmap to 0 in CONSTRUCTOR for CURRENT module.
|
||||
//
|
||||
Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, 0);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user