From: Michael Jeanson Date: Tue, 30 Apr 2024 19:17:52 +0000 (-0400) Subject: fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6dee08cf205eb0c5f9edc37eeb5d10ad61abd0e1;p=lttng-tools.git fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash In 328c2fe7297c941aa9cbcfa4ce944fca1bd7300f, the type of 'lttng_uuid' was changed from a C array of 16 'uint8_t' to a C++ std::array of the same type and length. In 'trace_chunk_registry_ht_key_hash()' we access these 16 bytes as 2 'uint64_t', to do so we used to cast the array to '(uint64_t *)' and then access index 0 and 1. When it was converted to C++, an error was introduced where instead we reinterpret_cast to 'const uint64_t *' the index 0 and 1 of the array which results in a 'uint64_t' pointer to the first and second bytes of the array. These values overlap but since they are used as keys for an hash table it still works. However, on platforms that don't allow unaligned access, the second pointer being only offset by one byte results in a 'Bus error'. Reintroduce the old behavior by applying the index 0 and 1 to the pointer resulting from the reinterpret_cast. Change-Id: I2bc287edbe6864a2a870f9de1f3b4dd8f8a90ace Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-relayd/sessiond-trace-chunks.cpp b/src/bin/lttng-relayd/sessiond-trace-chunks.cpp index 9d793c9bc..2326878fb 100644 --- a/src/bin/lttng-relayd/sessiond-trace-chunks.cpp +++ b/src/bin/lttng-relayd/sessiond-trace-chunks.cpp @@ -78,8 +78,8 @@ struct trace_chunk_registry_ht_element { static unsigned long trace_chunk_registry_ht_key_hash(const struct trace_chunk_registry_ht_key *key) { - const uint64_t uuid_h1 = *reinterpret_cast(&key->sessiond_uuid[0]); - const uint64_t uuid_h2 = *reinterpret_cast(&key->sessiond_uuid[1]); + const uint64_t uuid_h1 = reinterpret_cast(key->sessiond_uuid.data())[0]; + const uint64_t uuid_h2 = reinterpret_cast(key->sessiond_uuid.data())[1]; return hash_key_u64(&uuid_h1, lttng_ht_seed) ^ hash_key_u64(&uuid_h2, lttng_ht_seed); }