You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Crash on decrypt operation using OpenSSL backend #1491
Hi, we noticed some crashes from our userbase after updating to v1.11.1. The stack trace seems consistent in all cases, the crash happens during initial handshake on memcpy call:
memcpy() at memcpy.asm(436)
_libssh2_cipher_crypt(evp_cipher_ctx_st * * ctx, const evp_cipher_st *(*)() algo, int encrypt, unsigned char * block, unsigned __int64 blocksize, int firstlast) at openssl.c(1132)
decrypt(_LIBSSH2_SESSION * session, unsigned char * source, unsigned char * dest, __int64 len, int firstlast) at transport.c(159)
_libssh2_transport_read(_LIBSSH2_SESSION * session) at transport.c(827)
_libssh2_packet_require(_LIBSSH2_SESSION * session, unsigned char packet_type, unsigned char * * data, unsigned __int64 * data_len, int match_ofs, const unsigned char * match_buf, unsigned __int64 match_len, packet_require_state_t * state) at packet.c(1503)
session_startup(_LIBSSH2_SESSION * session, unsigned __int64 sock) at session.c(830)
libssh2_session_handshake(_LIBSSH2_SESSION * session, unsigned __int64 sock) at session.c(878)
We're using OpenSSL 3.2.2. The issue was observed on Windows 10 and 11, 64b.
Reproduction steps are not currently known but the issue does not seem to be super rare, we already have couple of reports.
From the minidump I have at hand, I noticed that the size passed to memcpy function is negative. It comes from this piece of code in openssl.c:
/* length to encrypt */
const int cryptlen = (unsigned int)blocksize - aadlen - authenticationtag;
and is calculated as 4 - 0 - 16 and ends up being -12 which is definitely not supposed to happen. Looks like the input variable blocksize or algo (which affects authenticationtag) is not correct.
It seems _libssh2_transport_read() is passing a too small numdecrypt value to the decrypt function?
That area has seen modifications in 492bc54. If you can test
without it or roll back before that patch, it might help locating this.
Looks like this is the same underlying issue as GHSA-c4f7-cvfc-33j7, which got fixed back in July (a2ed82d, closing #2401). The root cause matches exactly: cryptlen used to be guarded only by assert(cryptlen >= 0), and asserts get compiled out of release/NDEBUG builds, which is presumably why this only showed up for your userbase and not in debug testing. Current master replaces those asserts with a real bounds check before computing cryptlen, so a crafted or malformed packet can no longer drive it negative.
Might be worth closing this as a duplicate of #2401 once a release with that fix ships, since the code path and the crash signature (negative size into memcpy inside ssh2_cipher_crypt) line up.
Activity
vszakats commentedon Nov 8, 2024
Thanks for your report. This calculation appeared in 1.11.0 with AES-GCM support, did you upgrade from that or from an earlier version?
Trzik commentedon Nov 8, 2024
We were using 1.11.0 for quite a while, the issue did not appear there.
vszakats commentedon Nov 8, 2024
It seems
_libssh2_transport_read()is passing a too smallnumdecryptvalue to the decrypt function?That area has seen modifications in 492bc54. If you can test
without it or roll back before that patch, it might help locating this.
vszakats commentedon Mar 19, 2025
clang-tidy is reporting issues in this code part. Unclear if it's related, but 4 warnings in these functions may be worthy of attention.
willco007 commentedon Mar 20, 2025
Link to clang tidy logs. #1561 (comment)
afonsojanu commentedon Sep 4, 2026
Looks like this is the same underlying issue as GHSA-c4f7-cvfc-33j7, which got fixed back in July (a2ed82d, closing #2401). The root cause matches exactly: cryptlen used to be guarded only by assert(cryptlen >= 0), and asserts get compiled out of release/NDEBUG builds, which is presumably why this only showed up for your userbase and not in debug testing. Current master replaces those asserts with a real bounds check before computing cryptlen, so a crafted or malformed packet can no longer drive it negative.
Might be worth closing this as a duplicate of #2401 once a release with that fix ships, since the code path and the crash signature (negative size into memcpy inside ssh2_cipher_crypt) line up.
vszakats commentedon Sep 4, 2026
Closing as confirmed fixed by #2401. I'll also link that commit to this issue in the release notes.
Thank you @afonsojanu!
edit: Ref: 260fe5b