fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash
authorMichael Jeanson <mjeanson@efficios.com>
Tue, 30 Apr 2024 19:17:52 +0000 (15:17 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 1 May 2024 14:56:42 +0000 (10:56 -0400)
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 <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-relayd/sessiond-trace-chunks.cpp

index 9d793c9bcf79315e722447fcb3c205f785a60c54..2326878fb9fd6a9dd2f9d6dfd8dc8dd4504243f1 100644 (file)
@@ -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<const uint64_t *>(&key->sessiond_uuid[0]);
-       const uint64_t uuid_h2 = *reinterpret_cast<const uint64_t *>(&key->sessiond_uuid[1]);
+       const uint64_t uuid_h1 = reinterpret_cast<const uint64_t *>(key->sessiond_uuid.data())[0];
+       const uint64_t uuid_h2 = reinterpret_cast<const uint64_t *>(key->sessiond_uuid.data())[1];
 
        return hash_key_u64(&uuid_h1, lttng_ht_seed) ^ hash_key_u64(&uuid_h2, lttng_ht_seed);
 }
This page took 0.025793 seconds and 4 git commands to generate.