Skip to content

Check the PK of the source of an error before closing chans from it #787

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

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

When we receive an error message from a peer, it can indicate a
channel which we should close. However, we previously did not
check that the counterparty who sends us such a message is the
counterparty with whom we have the channel, allowing any
connected peer to make us force-close any channel we have as long
as they know the channel id.

This commit simply changes the force-close logic to check that the
sender matches the channel's counterparty node_id, though as noted
in #105, we eventually need to change the indexing anyway to allow
absurdly terrible peers to open channels with us.

Found during review of #777.

Plus threw in a fix for docs on peer handler which I found while writing a SocketDescriptor wrapper in Java NIO.

@codecov
Copy link

codecov bot commented Feb 3, 2021

Codecov Report

Merging #787 (cd7a64f) into main (c7ddcd3) will decrease coverage by 0.04%.
The diff coverage is 89.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #787      +/-   ##
==========================================
- Coverage   90.79%   90.75%   -0.05%     
==========================================
  Files          38       44       +6     
  Lines       23168    24119     +951     
==========================================
+ Hits        21036    21888     +852     
- Misses       2132     2231      +99     
Impacted Files Coverage Δ
lightning-block-sync/src/lib.rs 0.00% <0.00%> (ø)
lightning/src/ln/chan_utils.rs 97.33% <ø> (ø)
lightning/src/ln/peer_handler.rs 49.79% <0.00%> (+0.06%) ⬆️
lightning/src/routing/router.rs 95.57% <ø> (ø)
lightning-block-sync/src/rest.rs 67.24% <67.24%> (ø)
lightning/src/ln/msgs.rs 89.46% <75.00%> (ø)
lightning-block-sync/src/rpc.rs 79.48% <79.48%> (ø)
lightning-block-sync/src/convert.rs 92.80% <92.80%> (ø)
lightning/src/ln/functional_tests.rs 96.94% <94.73%> (-0.05%) ⬇️
lightning-block-sync/src/http.rs 95.39% <95.39%> (ø)
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7ddcd3...bd8382a. Read the comment docs.

Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

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

I'm sad to hear about this bug. Given that channel id are made of the funding_txid & funding_output_index, a peer could have reasonably guessed our channel ids by observing onchain LN transactions...

Thinking further, we should modify the spec to blind channel id with a secret only known by channel counterparties, maybe even scoping short_chan_id for private channels ?

@@ -3479,7 +3489,7 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
}
} else {
Copy link

Choose a reason for hiding this comment

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

About the zero-value channel id branch, wouldn't be better to sanitize early that case at open_channel reception ? Such value would be a hint of either our CSRNG being burst of the counterparty being buggy or sneaky. Either way we should discard that value from our internal channel map ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm? Not sure exactly what you mean - zero-value channel id means "close all channels with me", its not a specific reference to a channel.

@TheBlueMatt
Copy link
Collaborator Author

Thinking further, we should modify the spec to blind channel id with a secret only known by channel counterparties, maybe even scoping short_chan_id for private channels ?

We should just implement #105 - it'll solve this bug and also we can do per-channel locking at the same time.

@TheBlueMatt TheBlueMatt force-pushed the 2021-02-check-close-source branch from d0c8792 to 7c0b55d Compare February 7, 2021 23:51
@TheBlueMatt
Copy link
Collaborator Author

Added a test, as requested by @ariard on IRC, though I didn't remove the duplicate-closure on [0; 32] errors resulting from the PeerHandler calling peer_disconnected(no_connection_possible: true) after calling handle_error - we should behave correctly whether users have a custom MessageHandler or a custom PeerHandler.

@TheBlueMatt TheBlueMatt force-pushed the 2021-02-check-close-source branch from 7c0b55d to 97d6d91 Compare February 8, 2021 15:48
@ariard
Copy link

ariard commented Feb 9, 2021

Code Review ACK 97d6d91 modulo commit squash. Thanks for adding test!

@naumenkogs
Copy link
Contributor

naumenkogs commented Feb 9, 2021

Two typos (f, isntead) in the commit name f call direct to self.force_close_channel_with_peer isntead?
Could you fix if you touch the code anyway?

When we receive an error message from a peer, it can indicate a
channel which we should close. However, we previously did not
check that the counterparty who sends us such a message is the
counterparty with whom we have the channel, allowing any
connected peer to make us force-close any channel we have as long
as they know the channel id.

This commit simply changes the force-close logic to check that the
sender matches the channel's counterparty node_id, though as noted
in lightningdevkit#105, we eventually need to change the indexing anyway to allow
absurdly terrible peers to open channels with us.

Found during review of lightningdevkit#777.
@TheBlueMatt TheBlueMatt force-pushed the 2021-02-check-close-source branch from 97d6d91 to 8ca03f8 Compare February 10, 2021 00:05
@TheBlueMatt
Copy link
Collaborator Author

Fixed the typo. Note that the "f..." commits, generally are intended to be squashed into previous commits before merge, they exist just to aid reviewers in seeing changes between revisions.

@TheBlueMatt TheBlueMatt force-pushed the 2021-02-check-close-source branch from 8ca03f8 to bd8382a Compare February 10, 2021 00:06
@TheBlueMatt
Copy link
Collaborator Author

Went ahead and squashed, only code change was the doc typo.

@ariard
Copy link

ariard commented Feb 10, 2021

re-Code Review ACK bd8382a, changes are typo/squash

@TheBlueMatt TheBlueMatt merged commit c35002f into lightningdevkit:main Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants