You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hybrid KEX shared_secret stack array never wiped in kex_mlkem768x25519_sha256() (CWE-226) #2654
not sure if it is already in your fix list, but thought will post it here in case it is not…
kex_mlkem768x25519_sha256() (src/kex.c) computes the ML-KEM768+X25519 hybrid shared secret into a 64-byte stack array shared_secret (32 bytes ML-KEM768 via ssh2_mlkem_get_sk(), 32 bytes X25519 via ssh2_bn_to_bin()). The array is read exactly once — to derive the SHA-256 digest that becomes exchange_state->k_value — and never referenced again: no memset(), no explicit_bzero(), no ssh2_zero_free().
shared_secret is declared inside the if (exchange_state->state == ssh2_NB_state_created) block; the function's clean_exit: label operates on exchange_state, a different object — the array has already gone out of scope on all four early-error goto clean_exit paths and the normal success path alike. The raw combined classical+PQC secret is left sitting in stack memory.
Suggested fix: wipe the array (e.g. ssh2_explicit_zero() / memset()) before each exit from the block, or hoist the declaration so clean_exit can reach it.
(Found via a static-analysis audit for incomplete zeroization; defense-in-depth, contingent on an independent memory-read primitive.)
Activity
kex: clear shared secret buffer after use in `kex_mlkem768x25519_sha2…
kex: clear shared secret buffer after use in `kex_mlkem768x25519_sha2…
kex: clear buffers holding secrets