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

add validation of allowed CrdsValues in gossip #4764

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions gossip/src/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Definitions for the base of all Gossip protocol messages
use {
crate::{
crds_data::MAX_WALLCLOCK,
crds_data::{CrdsData, MAX_WALLCLOCK},
crds_gossip_pull::CrdsFilter,
crds_value::CrdsValue,
ping_pong::{self, Pong},
Expand Down Expand Up @@ -42,10 +43,10 @@ const GOSSIP_PING_TOKEN_SIZE: usize = 32;
pub(crate) const PULL_RESPONSE_MIN_SERIALIZED_SIZE: usize = 161;

// TODO These messages should go through the gpu pipeline for spam filtering
/// Gossip protocol messages base enum
#[derive(Serialize, Deserialize, Debug)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum Protocol {
/// Gossip protocol messages
PullRequest(CrdsFilter, CrdsValue),
PullResponse(Pubkey, Vec<CrdsValue>),
PushMessage(Pubkey, Vec<CrdsValue>),
Expand Down Expand Up @@ -152,10 +153,23 @@ impl Sanitize for Protocol {
match self {
Protocol::PullRequest(filter, val) => {
filter.sanitize()?;
// PullRequest is only allowed to have ContactInfo in its CrdsData
match val.data() {
CrdsData::LegacyContactInfo(_) | CrdsData::ContactInfo(_) => val.sanitize(),
_ => Err(SanitizeError::InvalidValue),
}
}
Protocol::PullResponse(_, val) => {
// PullResponse is allowed to carry anything in its CrdsData, including deprecated Crds
// such that a deprecated Crds does not get pulled and then rejected.
val.sanitize()
}
Protocol::PushMessage(_, val) => {
// PushMessage is allowed to carry anything in its CrdsData, including deprecated Crds
// such that a deprecated Crds gets ingested instead of the node having to pull it from
// other nodes that have inserted it into their Crds table
val.sanitize()
}
Protocol::PullResponse(_, val) => val.sanitize(),
Protocol::PushMessage(_, val) => val.sanitize(),
Protocol::PruneMessage(from, val) => {
if *from != val.pubkey {
Err(SanitizeError::InvalidValue)
Expand Down
Loading