libssh2 - Out-of-Bounds Write via Unchecked packet_length in transport.c
Description
libssh2 through 1.11.1, fixed in commit 7acf3df contains an out-of-bounds write vulnerability in ssh2_transport_read() that fails to enforce upper bounds on packet_length field. Remote attackers can send crafted SSH packets with excessively large packet_length values to corrupt heap memory and achieve remote code execution.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Affected products
1Patches
Vulnerability mechanics
Root cause
"Missing upper-bound validation on the packet_length field in ssh2_transport_read() allows an out-of-bounds heap write."
Attack vector
A remote, unauthenticated attacker can send a crafted SSH handshake or protocol message where the `packet_length` field (the first 4 bytes of the packet) is set to a value larger than `LIBSSH2_PACKET_MAXPAYLOAD`. The vulnerable `ssh2_transport_read()` function trusts this value without an upper-bound check, leading to a heap buffer overflow. This can corrupt adjacent heap metadata and potentially achieve remote code execution. The precondition is only that the attacker can establish an SSH connection to a service using libssh2.
Affected code
The vulnerability resides in `ssh2_transport_read()` in `src/transport.c`. The function reads a `packet_length` field from the network but previously only checked that it was not less than 1; no upper-bound check existed, allowing an attacker to supply an arbitrarily large value that would cause an out-of-bounds write into heap memory.
What the fix does
The patch adds an `else if` branch in `ssh2_transport_read()` that returns `LIBSSH2_ERROR_OUT_OF_BOUNDARY` when `p->packet_length > LIBSSH2_PACKET_MAXPAYLOAD`. This rejects any packet whose declared length exceeds the maximum allowed payload size, preventing the subsequent code from using the attacker-controlled large value in a memory copy or allocation that would overflow the heap buffer.
Preconditions
- networkThe attacker must be able to establish an SSH network connection to a service that uses libssh2.
- inputThe attacker sends a crafted SSH packet with a packet_length field exceeding LIBSSH2_PACKET_MAXPAYLOAD.
Generated on Jun 18, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
3- github.com/libssh2/libssh2/commit/97acf3dfda80c91c3a8c9f2372546301d4a1a7a8mitrepatch
- www.vulncheck.com/advisories/libssh2-out-of-bounds-write-via-unchecked-packet-length-in-transport-cmitrethird-party-advisory
- github.com/libssh2/libssh2/pull/2052mitreissue-tracking
News mentions
0No linked articles in our index yet.