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

fix: warn on mismatched underlay #2464

Merged
merged 1 commit into from
Sep 7, 2021
Merged

fix: warn on mismatched underlay #2464

merged 1 commit into from
Sep 7, 2021

Conversation

notanatol
Copy link
Contributor

@notanatol notanatol commented Sep 1, 2021

SWA-01-008 WP2: Injection of corrupted underlay into P2P handshake (Medium)

While auditing libp2p and the handshake protocol, it was observed that the underlay address is retrieved from the unsigned part of the SynAck structure (second packet within the handshake), thereby being unprotected.
An attacker could leverage this and modify that part of the message without the client noticing during the initial handshake, which would result in corrupting the underlay network information provided to the client.

This change is Reviewable

@notanatol notanatol requested a review from janos September 1, 2021 09:08
@notanatol notanatol requested a review from acud September 1, 2021 12:56
@notanatol notanatol marked this pull request as draft September 1, 2021 12:56
@notanatol notanatol force-pushed the cure53-handshake branch 2 times, most recently from 7198e9f to 2c27287 Compare September 1, 2021 14:11
Copy link
Member

@acud acud left a comment

Choose a reason for hiding this comment

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

Maybe just good to amend the PR title

@notanatol notanatol changed the title fix: read correct underlay fix: warn on mismatched underlay Sep 1, 2021
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 6, 2021

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
14.0% 14.0% Duplication


if s.libp2pID != observedUnderlayAddrInfo.ID {
//NOTE eventually we will return error here, but for now we want to gather some statistics
s.logger.Warningf("received peer ID %s does not match ours: %s", observedUnderlayAddrInfo.ID, s.libp2pID)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@acud normally we should return error here but we thought about maybe leaving it as a warning to gather some statistics about how often it happens.
Do you think this kind of data would be valuable or should we error here right away?

Copy link
Member

Choose a reason for hiding this comment

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

sure 👍

@mrekucci mrekucci requested review from acud and janos September 6, 2021 14:19
Copy link
Contributor

@mrekucci mrekucci left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @acud and @janos)


pkg/p2p/libp2p/internal/handshake/handshake.go, line 160 at r2 (raw file):

Previously, notanatol (Anatol) wrote…

@acud normally we should return error here but we thought about maybe leaving it as a warning to gather some statistics about how often it happens.
Do you think this kind of data would be valuable or should we error here right away?

I think you can return an error after the logline!?

Copy link
Contributor Author

@notanatol notanatol left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @acud and @janos)


pkg/p2p/libp2p/internal/handshake/handshake.go, line 160 at r2 (raw file):

Previously, mrekucci wrote…

I think you can return an error after the logline!?

Yes, technically it's doable, but it's just a general concern when it comes to introducing such a change to the behavior of the handshake protocol.
We are not sure how often this condition would be met "in the wild" where some peers might be behind NAT and the underlays might not match.


if s.libp2pID != observedUnderlayAddrInfo.ID {
//NOTE eventually we will return error here, but for now we want to gather some statistics
s.logger.Warningf("received peer ID %s does not match ours: %s", observedUnderlayAddrInfo.ID, s.libp2pID)
Copy link
Member

Choose a reason for hiding this comment

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

sure 👍

Copy link
Member

@janos janos left a comment

Choose a reason for hiding this comment

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

LGTM.

@notanatol notanatol marked this pull request as ready for review September 7, 2021 08:13
@notanatol notanatol merged commit ac11ddd into master Sep 7, 2021
@notanatol notanatol deleted the cure53-handshake branch September 7, 2021 08:14
@acud acud added this to the v1.2.0 milestone Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants