Skip to content

Commit 421becc

Browse files
committed
Port Cordio SMP control block improvements from Packetcraft
This change is provided by Packetcraft (which maintains the Cordio BLE stack) to address possible Sweyntooth vulnerabilities. (cherry picked from commit 0402fe4)
1 parent 565ab14 commit 421becc

File tree

6 files changed

+17
-0
lines changed

6 files changed

+17
-0
lines changed

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/smp/smp_main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -233,6 +234,7 @@ static void smpDmConnCback(dmEvt_t *pDmEvt)
233234
pCcb->attempts = SmpDbGetFailureCount((dmConnId_t) pDmEvt->hdr.param);
234235
pCcb->lastSentKey = 0;
235236
pCcb->state = 0;
237+
pCcb->keyReady = FALSE;
236238

237239
/* Resume the attempts state if necessary */
238240
smpResumeAttemptsState((dmConnId_t) pDmEvt->hdr.param);
@@ -710,6 +712,11 @@ uint8_t *SmpDmGetStk(dmConnId_t connId, uint8_t *pSecLevel)
710712
/* get connection control block */
711713
pCcb = smpCcbByConnId(connId);
712714

715+
if ((pCcb == NULL) || (pCcb->keyReady == FALSE))
716+
{
717+
return NULL;
718+
}
719+
713720
if (smpCb.lescSupported && pCcb->pScCcb->lescEnabled && (pCcb->pScCcb->pLtk != NULL))
714721
{
715722
/* set security level */

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/smp/smp_main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -314,6 +315,7 @@ typedef struct
314315
uint8_t token; /* AES transaction token */
315316
uint8_t attempts; /* Failed pairing attempts */
316317
uint8_t lastSentKey; /* Command code of last sent key */
318+
bool_t keyReady; /* Encryption key is ready */
317319
smpScCcb_t *pScCcb; /* LE Secure Connection control blocks */
318320
} smpCcb_t;
319321

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/smp/smpi_act.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -269,6 +270,7 @@ void smpiActStkEncrypt(smpCcb_t *pCcb, smpMsg_t *pMsg)
269270
/* adjust key based on max key length */
270271
memcpy(buf, pMsg->aes.pCiphertext, encKeyLen);
271272
memset((buf + encKeyLen), 0, (SMP_KEY_LEN - encKeyLen));
273+
pCcb->keyReady = TRUE;
272274

273275
secLevel = (pCcb->auth & SMP_AUTH_MITM_FLAG) ? DM_SEC_LEVEL_ENC_AUTH : DM_SEC_LEVEL_ENC;
274276
DmSmpEncryptReq(pCcb->connId, secLevel, buf);

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/smp/smpi_sc_act.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -463,6 +464,7 @@ void smpiScActDHKeyCheckVerify(smpCcb_t *pCcb, smpMsg_t *pMsg)
463464
/* Adjust key based on max key length */
464465
memcpy(buf, pCcb->pScCcb->pLtk->ltk_t, encKeyLen);
465466
memset((buf + encKeyLen), 0, (SMP_KEY_LEN - encKeyLen));
467+
pCcb->keyReady = TRUE;
466468

467469
/* Initiate encryption */
468470
DmSmpEncryptReq(pCcb->connId, smpGetScSecLevel(pCcb), buf);

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/smp/smpr_act.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -284,6 +285,7 @@ void smprActSendPairRandom(smpCcb_t *pCcb, smpMsg_t *pMsg)
284285
/* store STK and adjust based on max key length */
285286
memcpy(pCcb->pScr->buf.b3, pMsg->aes.pCiphertext, encKeyLen);
286287
memset((pCcb->pScr->buf.b3 + encKeyLen), 0, (SMP_KEY_LEN - encKeyLen));
288+
pCcb->keyReady = TRUE;
287289

288290
/* start smp response timer */
289291
smpStartRspTimer(pCcb);

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/smp/smpr_sc_act.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2009-2019 Arm Limited
2+
* Copyright (c) 2019-2020 Packetcraft, Inc.
23
* SPDX-License-Identifier: Apache-2.0
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -524,6 +525,7 @@ void smprScActDHKeyCheckSend(smpCcb_t *pCcb, smpMsg_t *pMsg)
524525
pCcb->pairReq[SMP_MAXKEY_POS] : pCcb->pairRsp[SMP_MAXKEY_POS];
525526

526527
memset((pCcb->pScCcb->pLtk->ltk_t + encKeyLen), 0, (SMP_KEY_LEN - encKeyLen));
528+
pCcb->keyReady = TRUE;
527529

528530
/* Send the DH Key check Eb to the initiator */
529531
smpScSendDHKeyCheck(pCcb, pMsg, pCcb->pScCcb->pScratch->Nb_Eb);

0 commit comments

Comments
 (0)