esp_ds: ignore releasing mutex if not called from same task (IDFGH-10131) #11402
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The mutex
s_ds_lock
inesp_rsa_sign_alt.c
is always unlocked unconditionally whether or not it was locked before. In our case, working with multiple connections, this resulted in triggering the assertion inesp-idf/components/freertos/FreeRTOS-Kernel/queue.c
Lines 881 to 885 in 54576b7
When connecting, the mutex is locked in
esp_create_mbedtls_handle -> set_client_config -> set_pki_context -> esp_mbedtls_init_pk_ctx_for_ds -> esp_ds_init_data_ctx
but only if there is a client certificate ords_data
set.Unlocking the mutex is done unconditionally from multiple places, e.g. after handshake (
esp_mbedtls_handshake -> esp_ds_release_ds_lock
) or on cleanup (esp_mbedtls_cleanup -> esp_ds_release_ds_lock
).Consider following scenario:
This might trigger the following:
esp_create_mbedtls_handle
with client certificate ords_data
fields filled -> locks mutexesp_create_mbedtls_handle
without client certificate, thus not locking the mutexesp_ds_release_ds_lock
, and the assertion will trigger because the mutex was locked by task 1, but the releasing task is differentFYI @KonssnoK