libssh2 (versions 1.11.1 and below)
A C library that gives software the ability to connect to SSH servers — it is embedded inside widely-used tools including curl, Git, and PHP, meaning it quietly runs inside many applications you use every day without advertising its presence.
Root Cause
The packet-parsing code read an attacker-controlled length value from the incoming SSH packet but only rejected values below 1. No upper limit was enforced. When a very large length value is supplied, arithmetic to calculate the required buffer size wraps around to a tiny number (this is an integer overflow — when a number exceeds the maximum a fixed-size counter can hold and loops back to near zero). libssh2 then allocates a small buffer but later writes the full oversized packet into it, writing past the end of that buffer in memory — a heap out-of-bounds write (writing data beyond the boundary of an allocated memory block). The fix adds a single check rejecting any length above the permitted maximum before the arithmetic runs.
Attack Vector
An attacker who controls or compromises an SSH server waits for a vulnerable client to connect. During the handshake, the server sends a crafted packet with an oversized length field. libssh2 miscalculates the buffer size, allocates too little memory, and then overwrites adjacent memory. Depending on the application and how libssh2 is embedded, this can lead to code running under that application's privileges. No user interaction is required beyond initiating the connection.
Detection Notes
- Unexplained crashes or memory errors in applications that make SSH connections (curl jobs, Git operations, backup agents)
- Anomalous outbound connections following an SSH handshake to an external server
- SSH client processes spawning unexpected child processes or making unusual network connections
Recommended Actions
- Inventory every application and appliance that uses libssh2, including statically bundled copies — curl, Git, and PHP deployments are the most common carriers
- Apply the patch by using distro backports where available (Debian already has a repaired build in testing) or build from source including commit 97acf3d
- Until patched, restrict outbound SSH connections to trusted, verified servers and confirm host keys are checked before connecting

