fix(mbedtls): correct inverted NULL check in esp_hmac_abort_opaque

esp_hmac_abort_opaque() had an inverted guard that called
mbedtls_platform_zeroize() on the context only when the context pointer
was NULL, dereferencing NULL and skipping cleanup of valid contexts.

Effect:
* Calling the abort path with a NULL pointer crashes (NULL write)
  instead of being a safe no-op.
* The valid (non-NULL) HMAC opaque operation context is never zeroized
  on abort, leaving sensitive intermediate HMAC state and key handle
  references in operation memory until the buffer is overwritten or
  freed.

Fix: invert the check so zeroization runs only when the context pointer
is non-NULL.
This commit is contained in:
Aditya Patwardhan
2026-04-14 11:10:32 +05:30
committed by Mahavir Jain
parent 96194f19a6
commit e1d01809dc
@@ -64,7 +64,7 @@ psa_status_t esp_hmac_import_key_opaque(
psa_status_t esp_hmac_abort_opaque(esp_hmac_opaque_operation_t *esp_hmac_ctx)
{
if (!esp_hmac_ctx) {
if (esp_hmac_ctx != NULL) {
mbedtls_platform_zeroize(esp_hmac_ctx, sizeof(esp_hmac_opaque_operation_t));
}
return PSA_SUCCESS;