Skip to content

Commit 366e796

Browse files
committed
Fix pre-noise outbound peer disconnect panic found by fuzzer
If we make an outbound connection to a peer who we are already connected to, and the outbound connection fails pre-noise-completion, we will remove the original peer connection from our node_id_to_descriptor map. The fuzzer managed to find this by crashing in Channel's assertions that we don't do a get_channel_reestablish() when the Channel isn't already marked disconnected.
1 parent b030e84 commit 366e796

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/ln/peer_handler.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
359359

360360
macro_rules! try_potential_handleerror {
361361
($thing: expr) => {
362+
try_potential_handleerror!($thing, false);
363+
};
364+
($thing: expr, $pre_noise: expr) => {
362365
match $thing {
363366
Ok(x) => x,
364367
Err(e) => {
@@ -367,6 +370,9 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
367370
msgs::ErrorAction::DisconnectPeer { msg: _ } => {
368371
//TODO: Try to push msg
369372
log_trace!(self, "Got Err handling message, disconnecting peer because {}", e.err);
373+
if $pre_noise {
374+
peer.their_node_id = None; // Unset so that we don't generate a peer_disconnected event
375+
}
370376
return Err(PeerHandleError{ no_connection_possible: false });
371377
},
372378
msgs::ErrorAction::IgnoreError => {
@@ -432,12 +438,12 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
432438
let next_step = peer.channel_encryptor.get_noise_step();
433439
match next_step {
434440
NextNoiseStep::ActOne => {
435-
let act_two = try_potential_handleerror!(peer.channel_encryptor.process_act_one_with_key(&peer.pending_read_buffer[..], &self.our_node_secret)).to_vec();
441+
let act_two = try_potential_handleerror!(peer.channel_encryptor.process_act_one_with_key(&peer.pending_read_buffer[..], &self.our_node_secret), true).to_vec();
436442
peer.pending_outbound_buffer.push_back(act_two);
437443
peer.pending_read_buffer = [0; 66].to_vec(); // act three is 66 bytes long
438444
},
439445
NextNoiseStep::ActTwo => {
440-
let act_three = try_potential_handleerror!(peer.channel_encryptor.process_act_two(&peer.pending_read_buffer[..], &self.our_node_secret)).to_vec();
446+
let act_three = try_potential_handleerror!(peer.channel_encryptor.process_act_two(&peer.pending_read_buffer[..], &self.our_node_secret), true).to_vec();
441447
peer.pending_outbound_buffer.push_back(act_three);
442448
peer.pending_read_buffer = [0; 18].to_vec(); // Message length header is 18 bytes
443449
peer.pending_read_is_header = true;
@@ -454,7 +460,7 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
454460
}, 16);
455461
},
456462
NextNoiseStep::ActThree => {
457-
let their_node_id = try_potential_handleerror!(peer.channel_encryptor.process_act_three(&peer.pending_read_buffer[..]));
463+
let their_node_id = try_potential_handleerror!(peer.channel_encryptor.process_act_three(&peer.pending_read_buffer[..]), true);
458464
peer.pending_read_buffer = [0; 18].to_vec(); // Message length header is 18 bytes
459465
peer.pending_read_is_header = true;
460466
peer.their_node_id = Some(their_node_id);

0 commit comments

Comments
 (0)