Repository navigation
Conversation
For me/FreeBSD oke.... |
Check that an AF_INET entity_addr_t encodes to the same bytes as on Linux, and that entity_addr_t and entity_addrvec_t both reject an address one byte longer than a sockaddr_in. Both pass on Linux before and after the fix. On macOS, each half of the decode test fails without the matching decode fix in msg_types.h and msg_types.cc. Assisted-by: Claude-Code-v2.1.287:claude-opus-5-5 Signed-off-by: Dan van der Ster <[email protected]>
entity_addr_t and the legacy sockaddr_storage encoding carry the address family as a number, and every reader assumes Linux's values. AF_INET is 2 everywhere, but AF_INET6 is 10 on Linux, 23 on Windows, 28 on FreeBSD and 30 on macOS. encode() and decode() mapped it to and from AF_INET6_LINUX only on Windows, so an IPv6 address from a FreeBSD or macOS daemon reaches a Linux peer with a family the peer does not recognise, and the reverse. Define AF_INET6_LINUX everywhere and map in both the msgr2 and the legacy encoding. On Linux the mapping is a no-op. A FreeBSD or macOS daemon still decodes the native value an older daemon of the same OS sends. Fixes: https://tracker.ceph.com/issues/81504 Assisted-by: Claude-Code-v2.1.287:claude-opus-5-5 Signed-off-by: Dan van der Ster <[email protected]>
entity_addrvec_t::decode() decodes a single msgr2 address (marker 1) with its own copy of entity_addr_t::decode(), and that copy stores the wire family as is. An IPv6 address decoded that way keeps AF_INET6_LINUX (10) on FreeBSD, macOS and Windows, where AF_INET6 is 28, 30 and 23. Split the msgr2 part of entity_addr_t::decode() into decode_after_marker(), alongside decode_legacy_addr_after_marker(), and call it from entity_addrvec_t::decode() instead of the copy. Add a test that decodes an encoded msgr2 IPv6 address as an entity_addrvec_t. Move the comment for the oversized-address test back to that test. Assisted-by: Claude-Code-v2.1.303:claude-opus-5-5 Signed-off-by: Dan van der Ster <[email protected]>
b9f7785 to
aeac809
Compare
| } | ||
| /// the msgr2 encoding, once decode() or entity_addrvec_t::decode() has | ||
| /// read marker 1 | ||
| void decode_after_marker(ceph::buffer::list::const_iterator& bl) { |
There was a problem hiding this comment.
entity_addr_t::decode() never clears the union. so we probably need to have something like
void decode(ceph::buffer::list::const_iterator& bl) {
// the encoding only carries the bytes of this particular address, so
// clear the union: a reused entity_addr_t would otherwise keep stale
// bytes from a previously decoded longer address
memset(&u, 0, sizeof(u));
...
}the ctor already does this. please note, the bug only manifests when decode() is called on an entity_addr_t that already holds a value. the reason why it has not surfaced yet is that the overwhelmingly dominant decode idiom in ceph is decoding into freshly constructed objects. but better safe than sorry..
There was a problem hiding this comment.
Agreed, and it's easy to show: an IPv4 address decoded over an IPv6 one compares unequal to the same address decoded into a new object. Fixed in e61096f. I put the memset in decode_after_marker() and decode_legacy_addr_after_marker() rather than in decode(), so that entity_addrvec_t::decode(), which calls those two directly, is covered as well. Tests for both are in c72ea3a; on macOS they fail without the fixes and pass with them. Not run on Linux or FreeBSD yet.
There was a problem hiding this comment.
Going on the test list for FreeBSD as well.
entity_addr_t's conversions to and from ceph_entity_addr put the address family in network byte order with htons() and ntohs(). sa_family_t is a single byte on the BSDs and macOS, so the swapped value is truncated to 0 and the family is lost. FreeBSD was already excluded by name; macOS was not. Swap only where the family is two bytes wide, which covers both. Suggested-by: Kefu Chai <[email protected]> Assisted-by: Claude-Code-v2.1.322:claude-fable-5-2 Signed-off-by: Dan van der Ster <[email protected]>
decode() only writes the bytes that the encoding carries. When the entity_addr_t already holds an address, the rest of the sockaddr union keeps its old bytes: an IPv4 address decoded over an IPv6 one compares unequal to the same address decoded into a new object, and a blank address leaves the old one in place. Most callers decode into a new object, so this has not shown up. Clear the union in both decode paths, as the constructors do. Suggested-by: Kefu Chai <[email protected]> Assisted-by: Claude-Code-v2.1.322:claude-fable-5-2 Signed-off-by: Dan van der Ster <[email protected]>
TestAddrDecodeIntoUsedAddr decodes an IPv4 and then a blank address into an entity_addr_t that held an IPv6 address, in both encodings, and expects the same value as from a new object. It fails without the previous commit. TestAddrCephEntityAddrRoundTrip converts to ceph_entity_addr and back. On macOS it fails without the byte-swap fix: the family comes back as 0. Assisted-by: Claude-Code-v2.1.322:claude-fable-5-2 Signed-off-by: Dan van der Ster <[email protected]>
Follow-up to #71445, now merged.
entity_addr_tandentity_addrvec_treject anelenone byte too long.entity_addrvec_t::decode()had its own copy of the msgr2 address decode, which kept the wire family as is. It now calls the samedecode_after_marker()asentity_addr_t::decode(), and a new test decodes an IPv6 address through it.On macOS the new tests fail without the fixes and pass with them. @wjwithagen confirmed
unittest_addrspasses on FreeBSD.Fixes: https://tracker.ceph.com/issues/81504
Checklist
🤖 Generated with Claude Code