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

notifications/libp2p: Punish notification protocol misbehavior on outbound substreams #7781

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

lexnv
Copy link
Contributor

@lexnv lexnv commented Mar 3, 2025

This PR punishes behaviors that deviate from the notification spec. When a peer misbehaves by writing data on an unidirectional read stream, the peer is banned and disconnected immediately.

In this PR:

  • The NotificationOutError is enriched with termination reason and made publically available for higher levels
  • The protocol misbehavior is propagated through the CloseDesired events
  • The network behavior of the protocol is responsible for banning the peer.
    • The peer is banned immediately and, as a result, the reputation system disconnects the malicious / misbehaving peer
  • Logs are enriched with protocol names

Closes: #7722

cc @paritytech/networking

@lexnv lexnv added the T0-node This PR/Issue is related to the topic “node”. label Mar 3, 2025
@lexnv lexnv self-assigned this Mar 3, 2025
@lexnv lexnv requested a review from a team March 3, 2025 17:15
Signed-off-by: Alexandru Vasile <[email protected]>
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we are 1000% sure that this behavior is not triggered by our own implementation? :D

let index: usize = set_id.into();
let protocol_name = self.notification_protocols.get(index);

error!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
error!(
debug!(

What should the operator do with this line?

@@ -479,11 +479,13 @@ where
Poll::Pending => {},
Poll::Ready(Some(result)) => match result {
Ok(_) => {
error!(
warn!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
warn!(
debug!(


error!(
target: LOG_TARGET,
"Received protocol mismatch for peer {:?} on protocol {:?}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be generate the same message as in the reputation change below to better describe the error? "Protocol mismatch" sounds too cryptic.

@@ -399,6 +399,14 @@ pub enum NotificationsOut {
/// Message that has been received.
message: BytesMut,
},

/// The remote peer has misbehaved and the connection has been closed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would explain that right now this corresponds to the specific case of receiving data in outbound substream.

@@ -329,6 +329,9 @@ pub enum NotifsHandlerOut {
CloseDesired {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be also update the comment above to reflect that CloseDesired is emitted when the remote either wishes to close the connection or misbehaves?

@@ -329,6 +329,9 @@ pub enum NotifsHandlerOut {
CloseDesired {
/// Index of the protocol in the list of protocols passed at initialization.
protocol_index: usize,

/// Whether the remote has misbehaved and did not comply with the notification spec.
protocol_misbehavior: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: may be introduce

enum CloseReason {
    ClosedByRemoteOrIoError,  // naming could be better, may be just `Connection`?
    ProtocolMisbehavior,
}

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T0-node This PR/Issue is related to the topic “node”.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

network/libp2p: Occasional Unexpected incoming data in NotificationsOutSubstream on kusama validators
3 participants