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
k_value (raw DH/ECDH shared secret) freed without wipe in KEX state cleanup (CWE-226) #2653
not sure if it is already in your fix list, but thought will post it here in case it is not…
In kex_diffie_hellman_state_cleanup() and kex_ecdh_exchange_state_cleanup() (src/kex.c), the raw serialized DH/ECDH shared secret state->k_value — used directly to derive the exchange hash H and transitively every session key — is released via a plain free (SSH2_SAFEFREE).
What makes this worth flagging: in the same cleanup functions, the derived session encryption/MAC keys are correctly released through ssh2_zero_free(), and the BIGNUM form of the identical secret goes through BN_clear_free() — only the serialized-byte-buffer sibling of an otherwise fully-protected value is missed. Reached on every DH/ECDH exchange, success and error paths.
ssh2_zero_free() itself was checked and is correctly implemented, so this is a call-site omission, not a primitive bug. Suggested fix: route k_value through ssh2_zero_free() at both cleanup sites.
(Found via a static-analysis audit for incomplete zeroization; defense-in-depth, contingent on an independent memory-read primitive.)
Activity
kex: clear `k_value` buffer in `kex_*_state_cleanup()` functions
kex: clear `k_value` buffer in `kex_*_state_cleanup()` functions
kex: clear `k_value` buffer in `kex_*_state_cleanup()` functions
vszakats commentedon Oct 6, 2026
Thanks for reporting. Fix proposal, also for #2654: #2655
kex: clear buffers holding secrets