From daedbbe714e56a155e089f6c6b14a25b480d9c25 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 19 Nov 2020 16:16:50 -0500 Subject: [PATCH] [fuzz] fix deadlock in chanmon_consistency due to new reentrancy 60d83efcd9825bed3e9490c7d1479533efd399ec introduced reentrancy when calling channel_monitor_updated. This commit fixes the chanmon_consistency fuzzer to no longer deadlock as a result of this reentrancy. --- fuzz/src/chanmon_consistency.rs | 48 ++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index e180805f2..dbc14ce1d 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -748,23 +748,27 @@ pub fn do_test(data: &[u8], out: Out) { 0x06 => *monitor_c.update_ret.lock().unwrap() = Ok(()), 0x08 => { - if let Some((id, _)) = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding) { - nodes[0].channel_monitor_updated(&chan_1_funding, *id); + let mon_id = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[0].channel_monitor_updated(&chan_1_funding, id); } }, 0x09 => { - if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding) { - nodes[1].channel_monitor_updated(&chan_1_funding, *id); + let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[1].channel_monitor_updated(&chan_1_funding, id); } }, 0x0a => { - if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding) { - nodes[1].channel_monitor_updated(&chan_2_funding, *id); + let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[1].channel_monitor_updated(&chan_2_funding, id); } }, 0x0b => { - if let Some((id, _)) = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding) { - nodes[2].channel_monitor_updated(&chan_2_funding, *id); + let mon_id = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[2].channel_monitor_updated(&chan_2_funding, id); } }, @@ -919,17 +923,29 @@ pub fn do_test(data: &[u8], out: Out) { *monitor_b.update_ret.lock().unwrap() = Ok(()); *monitor_c.update_ret.lock().unwrap() = Ok(()); - if let Some((id, _)) = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding) { - nodes[0].channel_monitor_updated(&chan_1_funding, *id); + { + let mon_id = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[0].channel_monitor_updated(&chan_1_funding, id); + } } - if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding) { - nodes[1].channel_monitor_updated(&chan_1_funding, *id); + { + let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_1_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[1].channel_monitor_updated(&chan_1_funding, id); + } } - if let Some((id, _)) = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding) { - nodes[1].channel_monitor_updated(&chan_2_funding, *id); + { + let mon_id = monitor_b.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[1].channel_monitor_updated(&chan_2_funding, id); + } } - if let Some((id, _)) = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding) { - nodes[2].channel_monitor_updated(&chan_2_funding, *id); + { + let mon_id = monitor_c.latest_monitors.lock().unwrap().get(&chan_2_funding).map(|(id, _)| *id); + if let Some(id) = mon_id { + nodes[2].channel_monitor_updated(&chan_2_funding, id); + } } // Next, make sure peers are all connected to each other -- 2.39.5