Skip to content

Commit

Permalink
fixed GHSA-vgvv-x7xg-6cqg - OOM Denial of Service due to allocation o…
Browse files Browse the repository at this point in the history
…f untrusted packet size
  • Loading branch information
Eugeny committed Aug 14, 2024
1 parent 4178268 commit f660ea3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion russh/src/cipher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,13 @@ pub(crate) async fn read<'a, R: AsyncRead + Unpin>(
buffer.buffer.extend(&len);
debug!("reading, seqn = {:?}", seqn);
let len = cipher.decrypt_packet_length(seqn, &len);
buffer.len = BigEndian::read_u32(&len) as usize + cipher.tag_len();
let len = BigEndian::read_u32(&len) as usize;

if len > MAXIMUM_PACKET_LEN {
return Err(Error::PacketSize(len));
}

buffer.len = len + cipher.tag_len();
debug!("reading, clear len = {:?}", buffer.len);
}
}
Expand Down Expand Up @@ -278,5 +284,6 @@ pub(crate) async fn read<'a, R: AsyncRead + Unpin>(
pub(crate) const PACKET_LENGTH_LEN: usize = 4;

const MINIMUM_PACKET_LEN: usize = 16;
const MAXIMUM_PACKET_LEN: usize = 256 * 1024;

const PADDING_LENGTH_LEN: usize = 1;
4 changes: 4 additions & 0 deletions russh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ pub enum Error {
#[error("Wrong server signature")]
WrongServerSig,

/// Excessive packet size.
#[error("Bad packet size: {0}")]
PacketSize(usize),

/// Message received/sent on unopened channel.
#[error("Channel not open")]
WrongChannel,
Expand Down

0 comments on commit f660ea3

Please sign in to comment.