Skip to content

Commit 8dcc69f

Browse files
qizhangzjyao1
authored andcommitted
DeviceSecurityPkg: check return value of libspdm.
Signed-off-by: Qi Zhang <[email protected]>
1 parent 2da8439 commit 8dcc69f

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

DeviceSecurityPkg/Library/SpdmSecurityLib/SpdmConnectionInit.c

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ CreateSpdmDeviceContext (
105105
ScratchBuffer = AllocateZeroPool (ScratchBufferSize);
106106
ASSERT (ScratchBuffer != NULL);
107107

108-
SpdmInitContext (SpdmContext);
108+
SpdmReturn = SpdmInitContext (SpdmContext);
109+
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
110+
goto Error;
111+
}
109112
SpdmRegisterDeviceIoFunc (
110113
SpdmContext,
111114
SpdmDeviceInfo->SendMessage,
@@ -200,8 +203,10 @@ CreateSpdmDeviceContext (
200203

201204
ZeroMem (&Parameter, sizeof (Parameter));
202205
Parameter.location = SpdmDataLocationLocal;
203-
SpdmSetData (SpdmContext, SpdmDataPeerPublicRootCert, &Parameter, Data, DataSize);
204-
206+
SpdmReturn = SpdmSetData (SpdmContext, SpdmDataPeerPublicRootCert, &Parameter, Data, DataSize);
207+
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
208+
goto Error;
209+
}
205210
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)Cert + DbList->SignatureSize);
206211
}
207212

@@ -213,13 +218,23 @@ CreateSpdmDeviceContext (
213218
Data8 = 0;
214219
ZeroMem (&Parameter, sizeof (Parameter));
215220
Parameter.location = SpdmDataLocationLocal;
216-
SpdmSetData (SpdmContext, SpdmDataCapabilityCTExponent, &Parameter, &Data8, sizeof (Data8));
221+
SpdmReturn = SpdmSetData (SpdmContext, SpdmDataCapabilityCTExponent, &Parameter, &Data8, sizeof (Data8));
222+
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
223+
goto Error;
224+
}
217225

218226
Data32 = 0;
219-
SpdmSetData (SpdmContext, SpdmDataCapabilityFlags, &Parameter, &Data32, sizeof (Data32));
227+
SpdmReturn = SpdmSetData (SpdmContext, SpdmDataCapabilityFlags, &Parameter, &Data32, sizeof (Data32));
228+
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
229+
goto Error;
230+
}
220231

221232
Data8 = SPDM_MEASUREMENT_BLOCK_HEADER_SPECIFICATION_DMTF;
222-
SpdmSetData (SpdmContext, SpdmDataMeasurementSpec, &Parameter, &Data8, sizeof (Data8));
233+
SpdmReturn = SpdmSetData (SpdmContext, SpdmDataMeasurementSpec, &Parameter, &Data8, sizeof (Data8));
234+
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
235+
goto Error;
236+
}
237+
223238
if (SpdmDeviceInfo->BaseAsymAlgo != 0) {
224239
Data32 = SpdmDeviceInfo->BaseAsymAlgo;
225240
} else {
@@ -231,7 +246,11 @@ CreateSpdmDeviceContext (
231246
SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521;
232247
}
233248

234-
SpdmSetData (SpdmContext, SpdmDataBaseAsymAlgo, &Parameter, &Data32, sizeof (Data32));
249+
SpdmReturn = SpdmSetData (SpdmContext, SpdmDataBaseAsymAlgo, &Parameter, &Data32, sizeof (Data32));
250+
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
251+
goto Error;
252+
}
253+
235254
if (SpdmDeviceInfo->BaseHashAlgo != 0) {
236255
Data32 = SpdmDeviceInfo->BaseHashAlgo;
237256
} else {
@@ -240,7 +259,10 @@ CreateSpdmDeviceContext (
240259
SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512;
241260
}
242261

243-
SpdmSetData (SpdmContext, SpdmDataBaseHashAlgo, &Parameter, &Data32, sizeof (Data32));
262+
SpdmReturn = SpdmSetData (SpdmContext, SpdmDataBaseHashAlgo, &Parameter, &Data32, sizeof (Data32));
263+
if (LIBSPDM_STATUS_IS_ERROR(SpdmReturn)) {
264+
goto Error;
265+
}
244266

245267
SpdmReturn = SpdmInitConnection (SpdmContext, FALSE);
246268
if (LIBSPDM_STATUS_IS_ERROR (SpdmReturn)) {
@@ -251,7 +273,12 @@ CreateSpdmDeviceContext (
251273
ZeroMem (&Parameter, sizeof (Parameter));
252274
Parameter.location = SpdmDataLocationConnection;
253275
DataSize = sizeof (Data16);
254-
SpdmGetData (SpdmContext, SpdmDataSpdmVersion, &Parameter, &Data16, &DataSize);
276+
SpdmReturn = SpdmGetData (SpdmContext, SpdmDataSpdmVersion, &Parameter, &Data16, &DataSize);
277+
if (LIBSPDM_STATUS_IS_ERROR (SpdmReturn)) {
278+
DEBUG ((DEBUG_ERROR, "SpdmInitConnection - %p\n", SpdmReturn));
279+
goto Error;
280+
}
281+
255282
SpdmDeviceContext->SpdmVersion = (Data16 >> 8);
256283

257284
return SpdmDeviceContext;

0 commit comments

Comments
 (0)