Skip to content

Hybrid KEX shared_secret stack array never wiped in kex_mlkem768x25519_sha256() (CWE-226) #2654

Closed

Description

@ravikanthreddy89

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

  1. added 2 commits that reference this issue on Oct 6, 2026
    ab810bc
    a16c917
  2. 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