p2p: unpack memory layout of peerlist entries
What changed, and why it matters
This commit removes compiler directives that forced a tightly packed memory layout for Monero peer list data structures. The old packing caused shared-pointer fields inside network addresses to be stored at unaligned memory addresses, which can trigger crashes or subtle memory corruption on some CPU architectures. The fix restores normal alignment. It is a stability/reliability fix with possible security side effects rather than a clearly exploitable vulnerability.
Treat as a reliability/stability fix. Apply the patch and monitor for any peerlist serialization regressions. No immediate incident response is warranted unless crashes or corruption have already been observed.
Security signals we found
Unaligned memory access due to packed struct containing shared pointer
Potential undefined behavior / memory corruption in P2P peerlist structures
Defensive fix removing unsafe #pragma pack directive
No explicit vulnerability or exploit described in commit message
Evidence from the diff
The diff removes #pragma pack(push, 1) and #pragma pack(pop) around peerlist_entry_base and anchor_peerlist_entry_base in src/p2p/p2p_protocol_defs.h. Those templates contain epee::net_utils::network_address, which internally holds a boost::shared_ptr (or similar shared pointer). Packing the struct to byte alignment misaligned that shared pointer, leading to unaligned memory accesses. Because the peerlist file is serialized with Boost serialization, removing packing should not break on-disk format compatibility. The change is defensive: it eliminates undefined behavior / potential memory corruption in P2P peer-list handling.
Changed components
src/p2p/p2p_protocol_defs.hnodetool::peerlist_entry_basenodetool::anchor_peerlist_entry_baseepee::net_utils::network_address shared pointer alignmentInspect captured patch +0 / −4
diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h
index 5f0fb1b..43cc6b0 100644
--- a/src/p2p/p2p_protocol_defs.h
+++ b/src/p2p/p2p_protocol_defs.h
@@ -54,8 +54,6 @@ namespace nodetool
s << std::hex << peer_id;
return epee::string_tools::pad_string(s.str(), 16, '0', true);
}
-
-#pragma pack (push, 1)
template<typename AddressType>
struct peerlist_entry_base
@@ -108,8 +106,6 @@ namespace nodetool
};
typedef anchor_peerlist_entry_base<epee::net_utils::network_address> anchor_peerlist_entry;
-#pragma pack(pop)
-
inline
std::string print_peerlist_to_string(const std::vector<peerlist_entry>& pl)
{
Why this scored 46/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.