Skip to content

Commit

Permalink
DeviceSecurityPkg: check return value of libspdm.
Browse files Browse the repository at this point in the history
Signed-off-by: Qi Zhang <[email protected]>
  • Loading branch information
qizhangz authored and jyao1 committed Nov 22, 2022
1 parent 2da8439 commit 8dcc69f
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions DeviceSecurityPkg/Library/SpdmSecurityLib/SpdmConnectionInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ CreateSpdmDeviceContext (
ScratchBuffer = AllocateZeroPool (ScratchBufferSize);
ASSERT (ScratchBuffer != NULL);

SpdmInitContext (SpdmContext);
SpdmReturn = SpdmInitContext (SpdmContext);
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
goto Error;
}
SpdmRegisterDeviceIoFunc (
SpdmContext,
SpdmDeviceInfo->SendMessage,
Expand Down Expand Up @@ -200,8 +203,10 @@ CreateSpdmDeviceContext (

ZeroMem (&Parameter, sizeof (Parameter));
Parameter.location = SpdmDataLocationLocal;
SpdmSetData (SpdmContext, SpdmDataPeerPublicRootCert, &Parameter, Data, DataSize);

SpdmReturn = SpdmSetData (SpdmContext, SpdmDataPeerPublicRootCert, &Parameter, Data, DataSize);
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
goto Error;
}
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)Cert + DbList->SignatureSize);
}

Expand All @@ -213,13 +218,23 @@ CreateSpdmDeviceContext (
Data8 = 0;
ZeroMem (&Parameter, sizeof (Parameter));
Parameter.location = SpdmDataLocationLocal;
SpdmSetData (SpdmContext, SpdmDataCapabilityCTExponent, &Parameter, &Data8, sizeof (Data8));
SpdmReturn = SpdmSetData (SpdmContext, SpdmDataCapabilityCTExponent, &Parameter, &Data8, sizeof (Data8));
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
goto Error;
}

Data32 = 0;
SpdmSetData (SpdmContext, SpdmDataCapabilityFlags, &Parameter, &Data32, sizeof (Data32));
SpdmReturn = SpdmSetData (SpdmContext, SpdmDataCapabilityFlags, &Parameter, &Data32, sizeof (Data32));
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
goto Error;
}

Data8 = SPDM_MEASUREMENT_BLOCK_HEADER_SPECIFICATION_DMTF;
SpdmSetData (SpdmContext, SpdmDataMeasurementSpec, &Parameter, &Data8, sizeof (Data8));
SpdmReturn = SpdmSetData (SpdmContext, SpdmDataMeasurementSpec, &Parameter, &Data8, sizeof (Data8));
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
goto Error;
}

if (SpdmDeviceInfo->BaseAsymAlgo != 0) {
Data32 = SpdmDeviceInfo->BaseAsymAlgo;
} else {
Expand All @@ -231,7 +246,11 @@ CreateSpdmDeviceContext (
SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521;
}

SpdmSetData (SpdmContext, SpdmDataBaseAsymAlgo, &Parameter, &Data32, sizeof (Data32));
SpdmReturn = SpdmSetData (SpdmContext, SpdmDataBaseAsymAlgo, &Parameter, &Data32, sizeof (Data32));
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
goto Error;
}

if (SpdmDeviceInfo->BaseHashAlgo != 0) {
Data32 = SpdmDeviceInfo->BaseHashAlgo;
} else {
Expand All @@ -240,7 +259,10 @@ CreateSpdmDeviceContext (
SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512;
}

SpdmSetData (SpdmContext, SpdmDataBaseHashAlgo, &Parameter, &Data32, sizeof (Data32));
SpdmReturn = SpdmSetData (SpdmContext, SpdmDataBaseHashAlgo, &Parameter, &Data32, sizeof (Data32));
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
goto Error;
}

SpdmReturn = SpdmInitConnection (SpdmContext, FALSE);
if (LIBSPDM_STATUS_IS_ERROR (SpdmReturn)) {
Expand All @@ -251,7 +273,12 @@ CreateSpdmDeviceContext (
ZeroMem (&Parameter, sizeof (Parameter));
Parameter.location = SpdmDataLocationConnection;
DataSize = sizeof (Data16);
SpdmGetData (SpdmContext, SpdmDataSpdmVersion, &Parameter, &Data16, &DataSize);
SpdmReturn = SpdmGetData (SpdmContext, SpdmDataSpdmVersion, &Parameter, &Data16, &DataSize);
if (LIBSPDM_STATUS_IS_ERROR (SpdmReturn)) {
DEBUG ((DEBUG_ERROR, "SpdmInitConnection - %p\n", SpdmReturn));
goto Error;
}

SpdmDeviceContext->SpdmVersion = (Data16 >> 8);

return SpdmDeviceContext;
Expand Down

0 comments on commit 8dcc69f

Please sign in to comment.