Skip to content

Release the DRBG mutex when generation fails - #412

Open
EdouardMALOT wants to merge 1 commit into
eclipse-threadx:devfrom
EdouardMALOT:fix/drbg-mutex-release-on-error
Open

Release the DRBG mutex when generation fails#412
EdouardMALOT wants to merge 1 commit into
eclipse-threadx:devfrom
EdouardMALOT:fix/drbg-mutex-release-on-error

Conversation

@EdouardMALOT

Copy link
Copy Markdown
Contributor

Summary

_nx_crypto_drbg() takes NX_CRYPTO_DRBG_MUTEX_GET at the top, but returns early when _nx_crypto_drbg_generate() fails, so the mutex is never released.

Both macros are empty by default and nothing in the repository defines them, so a default build is unaffected. Ports that do define them get a permanent deadlock instead of a returned error.

Found while working on #399.

Changes

  • crypto_libraries/src/nx_crypto_drbg.c — move NX_CRYPTO_DRBG_MUTEX_PUT to just after _nx_crypto_drbg_generate(), before the status check. This also leaves the masking of the extra bits outside the critical section, which is fine since it only touches the caller's buffer.

I left the ignored _nx_crypto_drbg_initialize() return value on the line above alone; that is a separate question, and happy to look at it if you would like it in the same PR.

Test plan

  • No behaviour change in a default build, where both macros expand to nothing
  • Compiles clean under -Wall -Wextra -Wconversion
  • Expanded both macros to function calls and checked there is exactly one get and one put, with the put now unconditional
  • Not exercised at runtime: I have no port here that defines the mutex macros, so the deadlock itself is reasoned from the code rather than reproduced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant