Repository navigation
Conversation
By applying two bound checks to non-debug builds. Reported-by: Vladimir Eli Tokarev Fixes GHSA-c4f7-cvfc-33j7 Follow-up to 3c953c0 libssh2#797
vszakats
marked this pull request as draft
July 23, 2026 08:54
ssh2_cipher_crypt()ssh2_cipher_crypt()
There was a problem hiding this comment.
Pull request overview
This PR hardens the OpenSSL cipher implementation by replacing debug-only assertions in ssh2_cipher_crypt() with runtime bounds checks, preventing potential out-of-bounds reads/writes in non-debug builds (including the AES-GCM first/last-block handling added in #797).
Changes:
- Add runtime validation that
blocksizefits within the local stack buffer and cannot underflow when subtracting AAD and authentication tag lengths. - Compute
cryptlenonly after validating bounds to avoid wrap/underflow scenarios in release builds.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
vszakats
marked this pull request as ready for review
July 23, 2026 09:07
This was referenced Jul 26, 2026
Merged
shivammathur
added a commit
to winlibs/libssh2
that referenced
this pull request
Aug 2, 2026
Backport upstream libssh2 runtime bounds checks for AES-GCM block processing in src/openssl.c. CVE-2026-66033: pre-authentication integer underflow and out-of-bounds access in _libssh2_cipher_crypt via AES-GCM negotiation, remotely triggerable by a malicious SSH server in libssh2 through 1.11.1. CWE: CWE-125, CWE-191 CVSS: 4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N (8.7 HIGH) Upstream-Commit: a2ed82d40964bbc0d64cd717aa0a5a892117d2e6 Upstream-PR: libssh2/libssh2#2401
vszakats
added a commit
that referenced
this pull request
Aug 4, 2026
In addition to the original patch: - simplify cipher object. drop the allocation and double redirection, drop redundant `encrypt` member, shorten/dedupe names, replace `algo` with `is_gcm`. - replace heap alloc with stack buffer for GCM in `ssh2_cipher_crypt()`. - use the algo argument instead of the context copy. (for speed and to match OpenSSL sibling code.) - fix returned error value on GCM auth fail. - increment IV on decrypt auth fail. Copilot suggestion. I cannot confirm this, so erring on the side caution to avoid a potential IV reuse. - support mbedTLS builds without GCM built-in, via `MBEDTLS_GCM_C`. - retrofit bounds check applied to OpenSSL backend earlier. Follow-up to a2ed82d #2401 - misc tidy-ups. Original-patch-by: Adrian Moran Closes #1764 Closes #2505
Member
Author
|
Updated the PR message to mention that this patch also fixes #1491. |
This was referenced Oct 26, 2026
This was referenced Nov 2, 2026
This was referenced Nov 9, 2026
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By applying two bounds checks to non-debug builds.
Reported-by: Vladimir Eli Tokarev
Fixes GHSA-c4f7-cvfc-33j7
Reported-by: Trzik on github
Fixes #1491
Thanks-to: Afonso Januário
Follow-up to 3c953c0 #797