]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
hyperscan: prevent LTO opmitizing out hash calculation
authorLukas Sismis <lsismis@oisf.net>
Tue, 22 Jul 2025 07:57:38 +0000 (09:57 +0200)
committerJason Ish <jason.ish@oisf.net>
Fri, 1 Aug 2025 16:54:17 +0000 (10:54 -0600)
Since cached_hash was updated through reference (hash), it seems
LTO did not notice this and optimized the whole code block, returning
zero.
This in turn caused all caches to have the same name and to overwrite.
On subsequent runs, only the last cache was loaded for all SGHs
causing wrong MPM assignment.

Ticket: 7824

src/util-mpm-hs-cache.c

index 4aaf5da84c2fd93271e6be3ef8442e09eae5ce07..2e58676fa94b1ade5d6416f3aa92f585f37d1e01 100644 (file)
@@ -222,14 +222,12 @@ cleanup:
 
 uint64_t HSHashDb(const PatternDatabase *pd)
 {
-    uint64_t cached_hash = 0;
-    uint32_t *hash = (uint32_t *)(&cached_hash);
+    uint32_t hash[2] = { 0 };
     hashword2(&pd->pattern_cnt, 1, &hash[0], &hash[1]);
     for (uint32_t i = 0; i < pd->pattern_cnt; i++) {
         SCHSCachePatternHash(pd->parray[i], &hash[0], &hash[1]);
     }
-
-    return cached_hash;
+    return ((uint64_t)hash[1] << 32) | hash[0];
 }
 
 void HSSaveCacheIterator(void *data, void *aux)