1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-10-24 03:48:58 +03:00

kex: free mlkem-nistp hybrid shared secret on NEWKEYS EAGAIN

kex_mlkem_nistp() allocates shared_secret on the heap, hashes it into K,
zeroes it, and frees it only at the clean_free label. The NEWKEYS send
returns EAGAIN with a bare `return rc` that skips clean_free, so in
non-blocking mode a stalled write there leaks the buffer once per hybrid
handshake; the resumed call re-enters at ssh2_NB_state_sent and never
allocates (or frees) it again. Route that EAGAIN return through
clean_free, matching the kex_finish EAGAIN path just below it. The
buffer is already consumed by that point, and exchange_state is
untouched so the resume still works.

Only kex_mlkem_nistp has this: the sibling kex_mlkem768x25519_sha256()
keeps its shared secret on the stack and the other kex methods hold
their buffers in exchange_state, freed by their cleanup.

Closes #2670
This commit is contained in:
syed abdul khaliq
2026-10-15 14:45:04 +05:30
committed by Viktor Szakats
parent 87a0fb354f
commit 6cf2e3da1e

View File

@@ -2002,8 +2002,10 @@ static int kex_mlkem_nistp(LIBSSH2_SESSION *session,
if(exchange_state->state == ssh2_NB_state_sent) {
rc = ssh2_transport_send(session, &exchange_state->c, 1, NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN)
return rc;
if(rc == LIBSSH2_ERROR_EAGAIN) {
ret = rc;
goto clean_free;
}
else if(rc) {
ret = ssh2_err(session, rc,
"Unable to send NEWKEYS message mlkemnistp");