Skip to content

Commit 6159325

Browse files
authored
Merge pull request #2974 from benthecarman/dang-value
Add DecodeError::DangerousValue for decoding invalid channel managers
2 parents d59a527 + 712d97d commit 6159325

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

fuzz/src/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
157157
msgs::DecodeError::ShortRead => panic!("We picked the length..."),
158158
msgs::DecodeError::Io(e) => panic!("{:?}", e),
159159
msgs::DecodeError::UnsupportedCompression => return,
160+
msgs::DecodeError::DangerousValue => return,
160161
}
161162
}
162163
}}

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10927,7 +10927,7 @@ where
1092710927
}
1092810928
}
1092910929
if chan.get_latest_unblocked_monitor_update_id() > max_in_flight_update_id {
10930-
// If the channel is ahead of the monitor, return InvalidValue:
10930+
// If the channel is ahead of the monitor, return DangerousValue:
1093110931
log_error!(logger, "A ChannelMonitor is stale compared to the current ChannelManager! This indicates a potentially-critical violation of the chain::Watch API!");
1093210932
log_error!(logger, " The ChannelMonitor for channel {} is at update_id {} with update_id through {} in-flight",
1093310933
chan.context.channel_id(), monitor.get_latest_update_id(), max_in_flight_update_id);
@@ -10936,7 +10936,7 @@ where
1093610936
log_error!(logger, " client applications must ensure that ChannelMonitor data is always available and the latest to avoid funds loss!");
1093710937
log_error!(logger, " Without the latest ChannelMonitor we cannot continue without risking funds.");
1093810938
log_error!(logger, " Please ensure the chain::Watch API requirements are met and file a bug report at https://github.com/lightningdevkit/rust-lightning");
10939-
return Err(DecodeError::InvalidValue);
10939+
return Err(DecodeError::DangerousValue);
1094010940
}
1094110941
} else {
1094210942
// We shouldn't have persisted (or read) any unfunded channel types so none should have been

lightning/src/ln/msgs.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ pub enum DecodeError {
9191
Io(io::ErrorKind),
9292
/// The message included zlib-compressed values, which we don't support.
9393
UnsupportedCompression,
94+
/// Value is validly encoded but is dangerous to use.
95+
///
96+
/// This is used for things like [`ChannelManager`] deserialization where we want to ensure
97+
/// that we don't use a [`ChannelManager`] which is in out of sync with the [`ChannelMonitor`].
98+
/// This indicates that there is a critical implementation flaw in the storage implementation
99+
/// and it's unsafe to continue.
100+
///
101+
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
102+
/// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
103+
DangerousValue,
94104
}
95105

96106
/// An [`init`] message to be sent to or received from a peer.
@@ -1860,6 +1870,7 @@ impl fmt::Display for DecodeError {
18601870
DecodeError::BadLengthDescriptor => f.write_str("A length descriptor in the packet didn't describe the later data correctly"),
18611871
DecodeError::Io(ref e) => fmt::Debug::fmt(e, f),
18621872
DecodeError::UnsupportedCompression => f.write_str("We don't support receiving messages with zlib-compressed fields"),
1873+
DecodeError::DangerousValue => f.write_str("Value would be dangerous to continue execution with"),
18631874
}
18641875
}
18651876
}

lightning/src/ln/peer_handler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
15531553
}
15541554
(msgs::DecodeError::BadLengthDescriptor, _) => return Err(PeerHandleError { }),
15551555
(msgs::DecodeError::Io(_), _) => return Err(PeerHandleError { }),
1556+
(msgs::DecodeError::DangerousValue, _) => return Err(PeerHandleError { }),
15561557
}
15571558
}
15581559
};

lightning/src/ln/reload_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
412412
}
413413

414414
let mut nodes_0_read = &nodes_0_serialized[..];
415-
if let Err(msgs::DecodeError::InvalidValue) =
415+
if let Err(msgs::DecodeError::DangerousValue) =
416416
<(BlockHash, ChannelManager<&test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestKeysInterface, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestRouter, &test_utils::TestLogger>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
417417
default_config: UserConfig::default(),
418418
entropy_source: keys_manager,

0 commit comments

Comments
 (0)