Repository navigation
Conversation
|
looking good to me |
There was a problem hiding this comment.
Pull request overview
This pull request addresses a security issue in the SSH transport receive path by adding a size guard during Encrypt-Then-MAC (ETM) packet decryption to prevent a potential heap overflow when allocating/copying decrypted data.
Changes:
- Add a lower-bound check for
decrypt_sizebefore allocating and copyingblocksize - 1bytes into the decrypt buffer. - Return
LIBSSH2_ERROR_DECRYPTwhen the ETM decrypt buffer would be undersized.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if(decrypt_size < blocksize - 1) | ||
| return LIBSSH2_ERROR_DECRYPT; |
There was a problem hiding this comment.
Looks like a pre-existing issue to me, where several of the non-EAGAIN fail paths from
this function leak the p→payload buffer.
Reported-by: Vladimir Eli Tokarev Fixes GHSA-6c79-444r-wx26
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/transport.c:242
decrypt_sizeis derived from attacker-controlled packet length in ETM mode, but the new guard only checks< blocksize - 1. That still allows values likedecrypt_size == blocksize - 1(or other non-block-aligned sizes), causingtransport_decrypt(..., blocksize, ...)to consume bytes beyond the ciphertext boundary (into the MAC region) and potentially triggering theassert((len % blocksize) == 0)invariants on the follow-up decrypt. Also, the new early-return path leavesp->payloadallocated.
Tighten the validation to require at least one full block and block alignment, and free p->payload before returning on failure.
decrypt_size = p->total_num - mac_len - 4;
if(decrypt_size < blocksize - 1)
return LIBSSH2_ERROR_DECRYPT;
"`decrypt_size` is computed from `p->total_num` (size_t) and `mac_len` (size_t) using unsigned arithmetic, then assigned to `ssize_t`. If `p->total_num < mac_len + 4`, the subtraction underflows before the assignment, and the conversion to `ssize_t` is implementation-defined. That can make the subsequent bounds check unreliable and still allow decrypting/allocating with an invalid size. Also, the first-block decrypt reads `blocksize` bytes, so the encrypted portion should be validated to be at least `blocksize` bytes (not just `blocksize - 1`)." libssh2#2198 (comment)
|
Also reported by: RuiZhi Zhang |
Backport upstream libssh2 lower-bound validation for Encrypt-then-MAC packet decryption in src/transport.c. CVE-2026-66035: pre-authentication heap buffer overflow via a packet length smaller than the negotiated cipher block size, remotely triggerable by a malicious SSH server in libssh2 through 1.11.1. CWE: CWE-122 CVSS: 4.0/AV:N/AC:H/AT:N/PR:N/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N (7.7 HIGH) Upstream-Commit: 42e33d81577ed4b95d4b4f6f845e5ee8efe5eeb4 Upstream-PR: libssh2/libssh2#2198
Reported-by: RuiZhi Zhang
Reported-by: Hananto Adi
Reported-by: Vladimir Eli Tokarev
Fixes GHSA-6c79-444r-wx26