# CVE-2025-5987: Libssh: invalid return code for chacha20 poly1305 with openssl backend

> Attackers can cause undefined behavior, data compromise, or crashes in libssh by exhausting heap space when using ChaCha20 with OpenSSL.

- **Severity:** High 8.1 (`CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 7 Jul 2025
- **Updated:** 16 Oct 2026
- **Also known as:** ALSA-2025:23483, ALSA-2025:23484, AZL-64794, AZL-64797, BELL-CVE-2025-5987, CLSA-2025-1762361016, DEBIAN-CVE-2025-5987, GHSA-3pvj-q7qj-89fg, JLSEC-2025-332, MINI-5r72-wp6m-mjvx, MINI-r7cp-9fm8-f7g5, OESA-2025-2131, RHSA-2025:23483, RHSA-2025:23484, RHSA-2026:0427, RHSA-2026:0428, RHSA-2026:0430, RHSA-2026:0431, RLSA-2025:23483, RLSA-2025:23484, UBUNTU-CVE-2025-5987

## What is CVE-2025-5987?

CVE-2025-5987 is a high-severity vulnerability in Red Hat Enterprise Linux 10, published on 7 Jul 2025. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

A flaw was found in libssh when using the ChaCha20 cipher with the OpenSSL library. If an attacker manages to exhaust the heap space, this error is not detected and may lead to libssh using a partially initialized cipher context. This occurs because the OpenSSL error code returned aliases with the SSH_OK code, resulting in libssh not properly detecting the error returned by the OpenSSL library. This issue can lead to undefined behavior, including compromised data confidentiality and integrity or crashes.

Weakness: CWE-393 (Return of Wrong Status Code)

## Which versions are affected by CVE-2025-5987?

It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `libssh-config` | AlmaLinux:10 | All versions | 0.11.1-5.el10_1 |
| `libssh` | AlmaLinux:9 | All versions | 0.10.4-17.el9_7 |
| `libssh-config` | AlmaLinux:9 | All versions | 0.10.4-17.el9_7 |
| `libssh-devel` | AlmaLinux:9 | All versions | 0.10.4-17.el9_7 |
| `libssh` | Red Hat:enterprise_linux:10.1 | All versions | 0:0.11.1-5.el10_1 |
| `libssh-config` | Red Hat:enterprise_linux:10.1 | All versions | 0:0.11.1-5.el10_1 |
| `libssh-debuginfo` | Red Hat:enterprise_linux:10.1 | All versions | 0:0.11.1-5.el10_1 |
| `libssh-debugsource` | Red Hat:enterprise_linux:10.1 | All versions | 0:0.11.1-5.el10_1 |
| `libssh-devel` | Red Hat:enterprise_linux:10.1 | All versions | 0:0.11.1-5.el10_1 |
| `libssh-debuginfo` | Red Hat:enterprise_linux:9::appstream | All versions | 0:0.10.4-17.el9_7 |
| `libssh-debugsource` | Red Hat:enterprise_linux:9::appstream | All versions | 0:0.10.4-17.el9_7 |
| `libssh-devel` | Red Hat:enterprise_linux:9::appstream | All versions | 0:0.10.4-17.el9_7 |
| `libssh` | Red Hat:enterprise_linux:9::baseos | All versions | 0:0.10.4-17.el9_7 |
| `libssh-config` | Red Hat:enterprise_linux:9::baseos | All versions | 0:0.10.4-17.el9_7 |
| `libssh-debuginfo` | Red Hat:enterprise_linux:9::baseos | All versions | 0:0.10.4-17.el9_7 |
| `libssh-debugsource` | Red Hat:enterprise_linux:9::baseos | All versions | 0:0.10.4-17.el9_7 |
| `libssh` | Red Hat:enterprise_linux_eus:10.0 | All versions | 0:0.11.1-4.el10_0.1 |
| `libssh` | Red Hat:rhel_e4s:9.2::baseos | All versions | 0:0.10.4-9.el9_2.2 |
| `libssh` | Red Hat:rhel_eus:9.4::baseos | All versions | 0:0.10.4-13.el9_4.2 |
| `libssh` | Red Hat:rhel_eus:9.6::baseos | All versions | 0:0.10.4-15.el9_6.1 |
| `libssh` | Rocky Linux:10 | All versions | 0:0.11.1-5.el10_1 |
| `libssh` | Rocky Linux:9 | All versions | 0:0.10.4-17.el9_7 |

Products: Libssh Libssh.

## How do I fix CVE-2025-5987?

Apply the vendor's patch.

## Is CVE-2025-5987 being exploited?

There is no known exploitation of CVE-2025-5987 in the wild and no public exploit code.

## Other vulnerabilities in Red Hat Enterprise Linux 10

- [CVE-2026-59851](https://insights.sbomify.com/CVE-2026-59851/): Libssh: libssh: authentication bypass via missing gssapi principal check (high 8.8)
- [CVE-2025-14821](https://insights.sbomify.com/CVE-2025-14821/): Libssh: libssh: insecure default configuration leads to local man-in-the-middle attacks on windows (high 7.8)
- [CVE-2012-4560](https://insights.sbomify.com/CVE-2012-4560/): Memory corruption in n/a (high 7.5)
- [CVE-2012-4562](https://insights.sbomify.com/CVE-2012-4562/): Integer overflow in n/a (high 7.5)
- [CVE-2012-6063](https://insights.sbomify.com/CVE-2012-6063/): Use after free in n/a (high 7.5)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2025-5987 and fix it if it is affected.

What it is: CVE-2025-5987 is a high-severity vulnerability in Red Hat Enterprise Linux 10, published on 7 Jul 2025. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2025-5987 in the wild and no public exploit code.

Affected product: Red Hat Enterprise Linux 10. No package-level version data is available, so check the vendor advisory linked from the reference page.

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2025-5987/ (Markdown: https://insights.sbomify.com/CVE-2025-5987/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2025-5987
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2025-5987
- OSV: https://osv.dev/vulnerability/CVE-2025-5987

---
From sbomify Insights: https://insights.sbomify.com/CVE-2025-5987/
Summaries are generated and may contain mistakes; the official description above is the record.
