Skip to content

Commit

Permalink
fix: handle linkstate decoding error (#1743)
Browse files Browse the repository at this point in the history
Panicking here was causing a major security breach concerning every
non-encrypted transport, especially UDP ones. An attacker could simply
forge a invalid OAM linkstate message to make the transport panic.
Regarding UDP multicast network, a single message could make the whole
network instantly unresponsive.
  • Loading branch information
wyfo authored Jan 29, 2025
1 parent eb3a7a4 commit 1b918b1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion zenoh/src/net/routing/hat/linkstate_peer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,9 @@ impl HatBaseTrait for HatCode {
use zenoh_codec::RCodec;
let codec = Zenoh080Routing::new();
let mut reader = buf.reader();
let list: LinkStateList = codec.read(&mut reader).unwrap();
let Ok(list): Result<LinkStateList, _> = codec.read(&mut reader) else {
bail!("failed to decode link state");
};

let whatami = transport.get_whatami()?;
if whatami != WhatAmI::Client {
Expand Down
4 changes: 3 additions & 1 deletion zenoh/src/net/routing/hat/p2p_peer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ impl HatBaseTrait for HatCode {
use zenoh_codec::RCodec;
let codec = Zenoh080Routing::new();
let mut reader = buf.reader();
let list: LinkStateList = codec.read(&mut reader).unwrap();
let Ok(list): Result<LinkStateList, _> = codec.read(&mut reader) else {
bail!("failed to decode link state");
};

net.link_states(list.link_states, zid, whatami);
}
Expand Down
4 changes: 3 additions & 1 deletion zenoh/src/net/routing/hat/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,9 @@ impl HatBaseTrait for HatCode {
use zenoh_codec::RCodec;
let codec = Zenoh080Routing::new();
let mut reader = buf.reader();
let list: LinkStateList = codec.read(&mut reader).unwrap();
let Ok(list): Result<LinkStateList, _> = codec.read(&mut reader) else {
bail!("failed to decode link state");
};

let whatami = transport.get_whatami()?;
match whatami {
Expand Down

0 comments on commit 1b918b1

Please sign in to comment.