-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## RFC 4253 §4.2 has a side\n\nThe SSH transport protocol specifies the version exchange in one short paragraph. Two sentences from it carry every constraint that matters for CVE-2026-48108:\n\n> The server MAY send other lines of data before sending the version string. ... The maximum length of the string is 255 characters, including the Carriage Return and Line Feed.\n\nThe permission is a server permission. The cap is a hard length cap on the identification line itself. OpenSSH's `sshd` enforces both: it rejects pre-banner traffic from clients, and it rejects banners longer than the spec allows. Russh, prior to v0.61.0, enforced neither.\n\n## The function with no direction in its name\n\nPre-patch, `russh/src/ssh_read.rs` exposes one method for reading the banner phase. Both the client and server crates use it:\n\n```rust\npub async fn read_ssh_id(&mut self) -> Result<&[u8], Error> {\n let ssh_id = self.id.as_mut().unwrap();\n loop {\n let mut i = 0;\n let n = AsyncReadExt::read(&mut self.r, &mut ssh_id.buf[ssh_id.total..]).await?;\n ssh_id.total += n;\n if n == 0 {\n return Err(Error::Disconnect);\n }\n // ... scan ssh_id.buf[..ssh_id.total] for CRLF, set bytes_read = i + 2 ...\n if ssh_id.bytes_read > 0 {\n if i >= 8 {\n if let Ok(s) = std::str::from_utf8(&ssh_id.buf[..i]) {\n if s.starts_with(\"SSH-1.99-\") || s.starts_with(\"SSH-2.0-\") {\n ssh_id.sshid_len = i;\n return Ok(ssh_id.id());\n }\n }\n }\n // Else, it is a \"preliminary\" (see RFC 4253 §4.2),\n // and we can discard it and read the next one.\n ssh_id.total = 0;\n ssh_id.bytes_read = 0;\n }\n }\n}\n```\n\n`russh/src/client/mod.rs` calls it as `stream.read_ssh_id()` to read the server's banner. `russh/src/server/mod.rs` calls it as `read.read_ssh_id()` to read the client's banner. The function takes no direction parameter; the call sites pass none. The 256-byte buffer is the only constant the function defines for itself. The comment that references RFC 4253 §4.2 is the only mention of the spec in the function body. The comment reads as if the function knows it is implementing a permission. The function does not know whose.\n\n## The patch is one boolean and one call site\n\nThe fix in `ssh_read.rs` keeps the original function and wraps it in two:\n\n```rust\npub async fn read_ssh_id(&mut self) -> Result<&[u8], Error> {\n self.read_ssh_id_inner(true).await\n}\n\npub async fn read_client_ssh_id(&mut self) -> Result<&[u8], Error> {\n self.read_ssh_id_inner(false).await\n}\n\nasync fn read_ssh_id_inner(&mut self, allow_pre_banner_lines: bool) -> Result<&[u8], Error> {\n let ssh_id = self.id.as_mut().ok_or(Error::Inconsistent)?;\n // ... loop, parse a line ...\n if !allow_pre_banner_lines {\n return Err(Error::Version);\n }\n ssh_id.pre_banner_lines += 1;\n if ssh_id.pre_banner_lines > SSH_ID_MAX_PRE_BANNER_LINES {\n return Err(Error::Version);\n }\n // ...\n}\n```\n\nIn `server/mod.rs`, one call site moves:\n\n```diff\n let sshid = if let Some(t) = config.inactivity_timeout {\n- tokio::time::timeout(t, read.read_ssh_id()).await??\n+ tokio::time::timeout(t, read.read_client_ssh_id()).await??\n } else {\n- read.read_ssh_id().await?\n+ read.read_client_ssh_id().await?\n };\n```\n\nThe client's call site in `client/mod.rs` is untouched. The patch deletes no function. It adds one wrapper, one boolean, two constants (`SSH_ID_MAX_LINE_LEN = 255` and `SSH_ID_MAX_PRE_BANNER_LINES = 20`), and updates exactly one call site. The qualifier on the function name is the fix.\n\n## The bound that wasn't there: pre-banner line count\n\nThe pre-patch path discards a non-`SSH-2.0-` line by resetting the buffer:\n\n```rust\nssh_id.total = 0;\nssh_id.bytes_read = 0;\n```\n\nNo counter. No cap. The outer `loop` continues. The only termination conditions inside the function are (a) a line starting with `SSH-2.0-` arrives, or (b) the underlying `read()` returns zero, meaning the peer hung up. Neither fires when the attacker streams CRLF-terminated garbage indefinitely.\n\nThe outer caller in `server/mod.rs` wraps the function in `tokio::time::timeout(config.inactivity_timeout, ...)`. The timeout is the only termination condition the attacker doesn't control. It is configurable; the default `Config` does not set it. A russh server compiled with default settings reads pre-banner garbage from a client until the operator notices.\n\nThe DoS primitive is direct. Open a TCP connection. Write `garbage\\r\\n`. Keep writing it. Never send `SSH-2.0-`. The connection holds a tokio task, a TCP socket, and a 256-byte buffer for as long as the attacker can keep typing. Scale to thousands of attacker connections and the russh server's slots are full of preliminaries that will never become handshakes. The patched cap of 20 preliminary lines puts a ceiling on the per-connection cost; the pre-patch cap was whatever the operator remembered to configure on `inactivity_timeout`.\n\n## The bound that wasn't there: line length\n\nRFC 4253 §4.2's other constraint caps the identification string at 255 characters including CRLF. Pre-patch, russh's buffer is 256 bytes. A 254-character banner plus CRLF fits exactly. A longer banner does not fit; the underlying `read()` writes into `buf[total..]`, where `total == 256`, an empty slice. `AsyncReadExt::read` returns `Ok(0)` into that empty slice, and the function returns `Error::Disconnect`.\n\nThe pre-patch test confirms the contract:\n\n```rust\nlet data = \":\".repeat(SSH_ID_BUF_SIZE + 1);\nlet mut read = SshRead::new(data.as_bytes());\nlet received = read.read_ssh_id().await;\nassert!(matches!(received.err(), Some(Error::Disconnect)));\n```\n\nThat test passed. It was the author's locked-in contract for what happens when a peer sends a too-long banner. `Disconnect` is the error russh returns when `read()` signals end-of-stream, the canonical \"peer hung up\" condition. Logs and metrics that classify `Disconnect` as a transport-level event swallowed every attempt to send an oversized banner. The malformed input and a half-open socket produced the same error.\n\nThe patch flips the assertion:\n\n```diff\n- assert!(matches!(received.err(), Some(Error::Disconnect)));\n+ assert!(matches!(received.err(), Some(Error::Version)));\n```\n\n`Error::Version` is russh's specific error for the version exchange. The patch installs the new taxonomy and the test that locks it in within the same commit. The pre-patch test was the codified statement that an oversized banner is a transport problem. The post-patch test is the codified statement that an oversized banner is a protocol problem. Same input, two different categories. The category had been wrong since the test was written.\n\n## One parser, two roles, a direction-blind parser\n\nThe structural reason is simple. SSH's version exchange is asymmetric:\n\n- The server MAY emit any number of preliminary lines before the canonical `SSH-2.0-` string.\n- The client MUST emit only the canonical line.\n\nA reader that handles both directions must implement both grammars and pick which one applies at each call site. A reader that implements one grammar has chosen which direction it serves. Russh's `read_ssh_id` implemented the looser grammar, the one written for clients reading servers, and the server inherited that grammar for free. This is the shape we call a Direction Blind Parser: one function reading bytes on behalf of two protocol roles that the spec does not treat as one.\n\nThe shape is not russh-specific. SMTP servers emit multi-line greetings; SMTP clients do not. DNS responder records carry a wider grammar than the queries that elicit them. HTTP/1.1 response headers allowed obs-fold long after request headers were narrowed against it, and several CVEs came out of clients that read the wider grammar on the request side. Whenever a protocol gives two roles different permissions and an implementation writes one parser for both, the parser implements the union of the two roles' permissions. The role that should have been stricter ships unbounded. Russh's banner phase is the version of that pattern where the spec asymmetry is two sentences long and the implementation is one function.\n\n## What the missing noun was\n\nThe function is named `read_ssh_id`. There are two SSH identification strings in an SSH handshake. The function did not say which one it read. The patch added the qualifier `client_` to one of the two new wrappers and pointed the server at it. The qualifier had been missing since the file was created in the russh tree in 2022, and the same code path existed in the thrussh fork russh was carved from before that. RFC 4253 §4.2's permission is the only deliberate asymmetry between the SSH server and the SSH client at handshake time. CVE-2026-48108 is what shipped while it was implemented as if it were not: one function reading banners, called from both ends of an asymmetric handshake.\n\nPatch: [Eugeny/russh@22295fa](https://github.com/Eugeny/russh/commit/22295fa5056d25f3f19f8e56e88772dca496ccb2)\n\nAdvisory: [GHSA-76r6-x97p-67vr](https://github.com/Eugeny/russh/security/advisories/GHSA-76r6-x97p-67vr)","closing_line":"The handshake had been ambidextrous for four years.","hook_md":"Russh has shipped a function called `read_ssh_id` since the file was first added to the project. The Rust SSH client called it to read the server's identification string. The Rust SSH server called it to read the client's identification string. RFC 4253 §4.2 grants one of those directions permission to send pre-banner lines, and grants the other none. The function modeled the union: pre-banner lines accepted from either side, with no count, with no line-length cap shorter than the buffer, until the inactivity timeout fired. CVE-2026-48108 is what a russh server reading from a client gets when the function reading the input was written for a client reading from a server.","post_id":610,"slug":"russh-cve-2026-48108-server-called-the-client-banner-parser","title":"CVE-2026-48108: Russh's Server Called The Client's Banner Parser","type":"initial","unreadable_sentence":"Russh wrote one function to read banners and called it from both ends of an asymmetric handshake."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaw98LgAKCRDeZjl4jgkQ Jqm2AQD8TyvEF2xTJkzYRDHd0Te+jdMgaXHR8lGxjnURZYD1UwD/cdOLY8k/he6w qNA3fCd3xQoP8eTiirI9KKJ7Y+cPQQc= =sMdN -----END PGP SIGNATURE-----