Skip to content

kex: fix mismatched ECDSA private key free in ML-KEM cleanup - #2200

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:mlkemfree
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:mlkemfree

Conversation

@vszakats

@vszakats vszakats commented Jul 3, 2026 •

Copy link
Copy Markdown
Member

Replace SSH2_FREE() with ssh2_ecdsa_free() in
kex_method_mlkem_nistp_cleanup(). This buffer is allocated with the
crypto backend's allocator, and may also require backend-specific
cleanup beforehand.

Follow-up to 3ba252e #1644
Cherry-picked from #2196

Instead of libssh2's `SSH2_FREE()`, in
`kex_method_mlkem_nistp_cleanup()`. This buffer is allocated with the
crypto backend's allocator, and may need backend-specific cleanup
beforehand.

Follow-up to 3ba252e libssh2#1644
Cherry-picked from libssh2#2196
@vszakats vszakats changed the title kex: fix to free ECDSA private key with ssh2_ecdsa_free() kex: fix freeing ECDSA private key when using ML-KEM Jul 3, 2026
@vszakats vszakats changed the title kex: fix freeing ECDSA private key when using ML-KEM kex: fix mismatched ECDSA private key free in ML-KEM cleanup Jul 3, 2026
@vszakats
vszakats requested a review from Copilot July 3, 2026 22:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes cleanup for the ML-KEM+NISTP hybrid key exchange by freeing the ECDH/ECDSA private key using the crypto-backend-specific destructor, matching how the key is allocated and how other ECDH cleanup paths already behave in the codebase.

Changes:

  • Replace SSH2_FREE(session, key_state->private_key) with ssh2_ecdsa_free(key_state->private_key) in kex_method_mlkem_nistp_cleanup().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vszakats vszakats closed this in 8c744ad Jul 4, 2026
@vszakats
vszakats deleted the mlkemfree branch July 4, 2026 09:58
@vszakats

vszakats commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

FTR this did not fix the ML-KEM flakiness seen in CI, ref : #1644 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants