Skip to main content
CVE Vulnerability Database
Vulnerability Database/CVE-2026-58051

CVE-2026-58051: Libssh2 Use-After-Free Vulnerability

CVE-2026-58051 is a use-after-free vulnerability in Libssh2 that allows malicious SSH servers to exploit uninitialized memory during publickey parsing. This article covers technical details, affected versions, and mitigation.

Published:

CVE-2026-58051 Overview

CVE-2026-58051 affects libssh2 through version 1.11.1, a widely deployed client-side SSH library used by cURL, Git, and other network utilities. The vulnerability stems from libssh2 growing its publickey list with SSH2_REALLOC without zero-initializing new entries before parsing populates them. When a parse failure reaches the cleanup path, libssh2_publickey_list_free operates on an uninitialized entry. A malicious SSH server that offers the publickey subsystem can send a malformed response to trigger a free on an attacker-influenceable attrs pointer in the connecting client. The flaw is tracked under CWE-908: Use of Uninitialized Resource.

Critical Impact

A malicious SSH server can cause a client using libssh2 to free an attacker-influenceable pointer, enabling memory corruption and potential code execution against connecting clients.

Affected Products

  • libssh2 versions up to and including 1.11.1
  • Applications linking against vulnerable libssh2 builds (cURL, Git, and other SSH clients)
  • Systems using the publickey subsystem during SSH client connections

Discovery Timeline

  • 2026-06-28 - CVE-2026-58051 published to the National Vulnerability Database (NVD)
  • 2026-06-30 - Last updated in NVD database

Technical Details for CVE-2026-58051

Vulnerability Analysis

The defect lives in the publickey subsystem handling code in src/publickey.c. When libssh2 receives publickey list entries from the remote server, it expands its internal list using SSH2_REALLOC. The reallocation returns memory whose new region beyond the previous size is not zeroed. Parsing then fills those entries incrementally.

If the server sends a malformed response, parsing aborts and control transfers to the cleanup routine libssh2_publickey_list_free. The cleanup iterates entries and calls free() on the attrs field of each entry, including entries that parsing never reached. Those unreached entries still hold uninitialized stack- or heap-derived bytes.

Root Cause

The root cause is a missing zero-initialization after SSH2_REALLOC combined with a cleanup path that assumes every allocated entry is fully constructed. This is a classic CWE-908 Use of Uninitialized Resource pattern, where the cleanup contract is violated by an early error return.

Attack Vector

Exploitation requires the victim client to connect to an attacker-controlled SSH server that advertises the publickey subsystem. The malicious server crafts a publickey response that causes list growth followed by a parse failure. The subsequent cleanup passes an attacker-influenceable pointer to free(), corrupting heap metadata. Depending on allocator state, this can lead to arbitrary write primitives and, in some environments, remote code execution in the client process. Technical details are documented in the VulnCheck Security Advisory and a proof of concept is available in the GitHub PoC Repository.

No verified exploitation code is reproduced here. See the libssh2 source in publickey.c for the affected list growth and cleanup routines.

Detection Methods for CVE-2026-58051

Indicators of Compromise

  • Client-side crashes, SIGSEGV, or heap corruption aborts in processes linked against libssh2 immediately after outbound SSH connections
  • Outbound SSH connections from developer workstations, CI runners, or build systems to unexpected or untrusted hosts
  • SSH sessions that negotiate the publickey@libssh.org subsystem and terminate abnormally during list parsing

Detection Strategies

  • Inventory all binaries statically or dynamically linked against libssh2 version 1.11.1 or earlier using software composition analysis
  • Instrument client applications with AddressSanitizer or MemorySanitizer during testing to surface uninitialized reads and invalid frees
  • Correlate process crash telemetry with recent outbound SSH connection metadata to identify targeted clients

Monitoring Recommendations

  • Log outbound SSH connections from workstations and servers, and alert on connections to hosts outside approved allowlists
  • Monitor for repeated abnormal termination of Git, cURL, or automation processes that use libssh2
  • Track package inventories for libssh2 versions across Linux distributions, macOS, and Windows build environments

How to Mitigate CVE-2026-58051

Immediate Actions Required

  • Upgrade libssh2 to the fixed release once published by the maintainers and rebuild or repackage dependent applications
  • Restrict outbound SSH connections from sensitive systems to a defined allowlist of known-good servers
  • Audit CI/CD pipelines, package managers, and Git operations that rely on libssh2 for SSH transport

Patch Information

The libssh2 maintainers track the fix in the upstream repository. Review the current state of src/publickey.c in the libssh2 GitHub repository and apply distribution updates as they become available. Consult the VulnCheck advisory for the authoritative remediation status.

Workarounds

  • Disable use of the publickey subsystem in client configurations where feasible, and prefer direct public key authentication over the publickey@libssh.org subsystem
  • Route SSH traffic through a trusted jump host or bastion that terminates and validates SSH sessions before reaching client libraries
  • Rebuild libssh2 locally with a patch that zero-initializes newly allocated publickey list entries after SSH2_REALLOC until an official release ships
bash
# Verify installed libssh2 version on Linux hosts
ldconfig -p | grep libssh2
dpkg -l | grep libssh2   # Debian/Ubuntu
rpm -q libssh2           # RHEL/Fedora

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.