Skip to content

Commit f45f668

Browse files
guy-msjanc
authored andcommitted
host/sm: Reject Legacy pairing confirm reflection attack
When the responder mirrors the initiator's confirm and random values (Sconfirm=Mconfirm, Srand=Mrand), the c1 check passes trivially, bypassing mismatch detection and causing an HCI encryption failure (0x06) instead of Pairing Failed (0x04). Detect Srand==Mrand in ble_sm_lgcy_random_rx and abort with LE_SM_ERR_CONFIRM_MISMATCH. Fixes SM/CEN/JW/BI-06-C and SM/CEN/PKE/BI-03-C
1 parent bd6d94c commit f45f668

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

nimble/host/src/ble_sm_lgcy.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ ble_sm_lgcy_random_rx(struct ble_sm_proc *proc, struct ble_sm_result *res)
215215

216216
ble_sm_ia_ra(proc, &iat, ia, &rat, ra);
217217

218+
/* If the peer echoed our own random back (Srand == Mrand), the c1 check
219+
* would trivially pass because the peer also mirrored Mconfirm.
220+
* Reject this immediately with Confirm Value Failed.
221+
*/
222+
if ((proc->flags & BLE_SM_PROC_F_INITIATOR) &&
223+
memcmp(ble_sm_peer_pair_rand(proc), ble_sm_our_pair_rand(proc), 16) == 0) {
224+
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_CONFIRM_MISMATCH);
225+
res->sm_err = BLE_SM_ERR_CONFIRM_MISMATCH;
226+
res->enc_cb = 1;
227+
return;
228+
}
229+
218230
rc = ble_sm_alg_c1(proc->tk, ble_sm_peer_pair_rand(proc), proc->pair_req,
219231
proc->pair_rsp, iat, rat, ia, ra, confirm_val);
220232
if (rc != 0) {

0 commit comments

Comments
 (0)