Skip to content

k_value (raw DH/ECDH shared secret) freed without wipe in KEX state cleanup (CWE-226) #2653

Closed

Description

@ravikanthreddy89

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

  1. added 3 commits that reference this issue on Oct 6, 2026
    789a488
    d0895ac
    6a3d70f
  2. vszakats commented on Oct 6, 2026

    @vszakats
    Member

    Thanks for reporting. Fix proposal, also for #2654: #2655

  3. added a commit that references this issue on Oct 6, 2026
    826fdb2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions