Skip to content

Commit 55507ea

Browse files
committed
Fix race condition when generating OOB data
The GenericSecurityManager tracks the most recent OOB data generated by the PAL and the PAL function to generate OOB data is expected to be asynchronous such that the OOB data is returned via a callback. There was a race condition on the security manager's oob data variable because it was cleared (set to all zeros) after calling PAL generate. The expectation was that the clear operation would occur before the callback executed, but this is proving to not be the case. Instead, the callback is being executed as if it were syncronous with PAL generate, then PAL generate returns and the oob data is cleared, thereby losing the generated oob data that was set in the callback. To fix the issue, clear the oob data variables before calling into the PAL.
1 parent 307bdd7 commit 55507ea

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,14 +653,20 @@ ble_error_t GenericSecurityManager::generateOOB(
653653
/* Secure connections. Avoid generating if we're already waiting for it.
654654
* If a local random is set to 0 it means we're already calculating. */
655655
if (!is_all_zeros(_oob_local_random)) {
656-
status = _pal.generate_secure_connections_oob();
656+
/* save the current values in case the call to
657+
* generate_secure_connections_oob fails */
658+
address_t orig_local_address = _oob_local_address;
659+
oob_lesc_value_t orig_local_random = _oob_local_random;
660+
661+
_oob_local_address = *address;
662+
/* this will be updated when calculation completes,
663+
* a value of all zeros is an invalid random value */
664+
set_all_zeros(_oob_local_random);
657665

658-
if (status == BLE_ERROR_NONE) {
659-
_oob_local_address = *address;
660-
/* this will be updated when calculation completes,
661-
* a value of all zeros is an invalid random value */
662-
set_all_zeros(_oob_local_random);
663-
} else if (status != BLE_ERROR_NOT_IMPLEMENTED) {
666+
status = _pal.generate_secure_connections_oob();
667+
if (status != BLE_ERROR_NONE && status != BLE_ERROR_NOT_IMPLEMENTED) {
668+
_oob_local_address = orig_local_address;
669+
_oob_local_random = orig_local_random;
664670
return status;
665671
}
666672
} else {

0 commit comments

Comments
 (0)