-
Notifications
You must be signed in to change notification settings - Fork 407
Makes ChannelManager::force_close_channel fail for unknown chan_ids #777
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
Conversation
75d9ee0
to
e6e0cf6
Compare
Codecov Report
@@ Coverage Diff @@
## main #777 +/- ##
==========================================
- Coverage 91.24% 91.24% -0.01%
==========================================
Files 37 37
Lines 22866 22847 -19
==========================================
- Hits 20865 20846 -19
Misses 2001 2001
Continue to review full report at Codecov.
|
lightning/src/ln/channelmanager.rs
Outdated
} | ||
|
||
/// Force close all channels, immediately broadcasting the latest local commitment transaction | ||
/// for each to the chain and rejecting new HTLCs on each. | ||
pub fn force_close_all_channels(&self) { | ||
for chan in self.list_channels() { | ||
self.force_close_channel(&chan.channel_id); | ||
self.force_close_channel(&chan.channel_id).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is race-y - if we close a channel in another thread while this is running we'll panic needlessly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased in 0e83723
@@ -918,7 +918,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> | |||
|
|||
/// Force closes a channel, immediately broadcasting the latest local commitment transaction to | |||
/// the chain and rejecting new HTLCs on the given channel. | |||
pub fn force_close_channel(&self, channel_id: &[u8; 32]) { | |||
pub fn force_close_channel(&self, channel_id: &[u8; 32]) -> Result<(), APIError>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to update the docs here to state that we only fail in case the channel is not found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased in 0e83723
e6e0cf6
to
0e83723
Compare
lightning/src/ln/channelmanager.rs
Outdated
} | ||
} | ||
} else { | ||
self.force_close_channel(&msg.channel_id); | ||
self.force_close_channel(&msg.channel_id).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This handles an untrusted message from a peer - if they send us a garbage channel_id we shouldn't crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ups, didn't realize that came from a peer.
Rebased in 03a72f1
lightning/src/ln/channelmanager.rs
Outdated
@@ -3471,11 +3473,11 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K: | |||
if msg.channel_id == [0; 32] { | |||
for chan in self.list_channels() { | |||
if chan.remote_network_id == *counterparty_node_id { | |||
self.force_close_channel(&chan.channel_id); | |||
self.force_close_channel(&chan.channel_id).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also race-y, I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased in 03a72f1
0e83723
to
03a72f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK-modulo-adding-warning-comment.
@@ -3471,11 +3473,11 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K: | |||
if msg.channel_id == [0; 32] { | |||
for chan in self.list_channels() { | |||
if chan.remote_network_id == *counterparty_node_id { | |||
self.force_close_channel(&chan.channel_id); | |||
let _ = self.force_close_channel(&msg.channel_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a code comment here and below : "Untrusted messages from peer, we throw away the error if id points to a non-existent channel". A good warning to avoid vulns in in case of new work around this code path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 821f6cd
ChannelManager::force_close_channel does not fail if a non-existing channel id is being passed, making it hard to catch from an API point of view. Makes force_close_channel return in the same way close_channel does so the user calling the method with an unknown id can be warned.
03a72f1
to
821f6cd
Compare
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.
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.
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.
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.
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.
ChannelManager::force_close_channel does not fail if a non-existing channel id is being passed, making it hard to catch from an API point of view.
Makes force_close_channel return in the same way close_channel does so the user calling the method with an unknown id can be warned.
There's a couple of things that may need fixing:
close #773