What changed, and why it matters
This patch fixes a bug in Monero's network connection cleanup code. When the program was walking through its list of active connections and dropping unused ones, destroying a connection could sometimes trigger code that modified the same list while it was still being walked. That could corrupt the list, crash the program, or cause unpredictable behavior. The fix keeps those other connections alive until the walk is finished, so their cleanup happens safely afterward.
Treat as a stability and potential denial-of-service hardening fix. Include in routine release notes; no urgent advisory is required unless crashes in this path are observed in the wild. Review related levin protocol handlers for similar iterator-safety issues.
Security signals we found
iterator invalidation during container mutation
use-after-free / container corruption risk from destructor side effects during iteration
network-facing P2P connection management code
crash / denial-of-service potential from malformed peer interaction
no explicit security framing in commit message
Evidence from the diff
In async_protocol_handler_config::delete_connections(), the code iterates over m_connects while holding m_connects_lock. Previously, when a shared_ptr
Changed components
contrib/epee/include/net/levin_protocol_handler_async.hasync_protocol_handler_config::delete_connections()Monero P2P/levin protocol connection handlerInspect captured patch +9 / −1
### contrib/epee/include/net/levin_protocol_handler_async.h
@@ -718,12 +718,20 @@ template<class t_connection_context>
void async_protocol_handler_config<t_connection_context>::delete_connections(size_t count, bool incoming)
{
std::vector<std::shared_ptr<levin_endpoint>> connections;
+ // Keep non-target connections alive until after releasing m_connects_lock.
+ // Dropping the last reference during iteration can call del_connection()
+ // through the destructor and invalidate the current iterator.
+ std::vector<std::shared_ptr<levin_endpoint>> released;
CRITICAL_REGION_BEGIN(m_connects_lock);
for (auto& c: m_connects)
{
auto locked = c.second.lock();
- if (locked && locked->context.m_is_income == incoming)
+ if (!locked)
+ continue;
+ if (locked->context.m_is_income == incoming)
connections.push_back(std::move(locked));
+ else
+ released.push_back(std::move(locked));
}
// close random connections from the provided setWhy this scored 59/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.