## Summary
libssh2 through 1.11.1 contains an integer overflow in the publickey-subsystem attribute parsing logic. A malicious SSH server can send a crafted response that causes an undersized heap allocation and then trigger a heap buffer overflow in a connecting libssh2 client.
## Technical Details
- Root issue: libssh2 reads an attacker-controlled 32-bit num_attrs from a publickey-subsystem response and allocates num_attrs * sizeof(libssh2_publickey_attribute) without bounds checking.
- On 32-bit platforms, the multiplication can overflow, producing an undersized buffer.
- The attribute parsing loop then processes attacker-controlled fields and writes past the allocated region, resulting in a heap buffer overflow.
- Reference material also describes two exploit paths:
- Win32 allocation-wrap chain: num_attrs * sizeof(...) wraps to a 4-byte allocation; subsequent parsing overwrites adjacent heap structures, with a harness that “grooms an adjacent callback slot” and triggers execution.
- Win64 publickey-list cleanup chain: a malformed response sequence leads to attacker-influenced heap layout; cleanup walks attacker-shaped list entries and frees attacker-selected pointers, with execution via a stale callback.
- Hardening controls mentioned in the references include:
- “zero list[keys] immediately after list growth”
- “reject num_attrs values that overflow the attrs allocation multiplication”
## Affected
- libssh2 <= 1.11.1
## Impact
- Heap buffer overflow in a connecting client (CWE-190).
- Attack is network-based with no client authentication required (AV:N, PR:N), and exploitation requires attacker control of the SSH server response.
- Potential outcomes include memory corruption leading to code execution in the provided PoC scenarios.
## Mitigation
1. Upgrade libssh2 to a version that includes the referenced parser hardening (reject overflowed num_attrs and apply the list zeroing behavior).
2. If upgrade is not immediately possible, restrict outbound SSH connections to trusted servers to reduce exposure to malicious publickey-subsystem responses.
3. Monitor for anomalous SSH publickey-subsystem responses and client-side crashes during authentication/key exchange attempts.
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:H
CWE-190