]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Annotate benign race in FIPS deferred self test
authorSimo Sorce <simo@redhat.com>
Tue, 17 Feb 2026 08:09:44 +0000 (03:09 -0500)
committerPauli <paul.dale@oracle.com>
Thu, 19 Feb 2026 04:47:35 +0000 (15:47 +1100)
Move TSAN definitions to threads_common.h to make them available
globally and introduce the ANNOTATE_BENIGN_RACE macro.

Apply this annotation to the state check in ossl_deferred_self_test()
to suppress a benign race warning from ThreadSanitizer, as the race
is intentional and accepted to avoid cpu contention.

Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/30009)

crypto/threads_pthread.c
include/internal/threads_common.h
providers/fips/fipsprov.c

index 76436ed4d8fd8e1e7fe45e8b65a2c74181dc9106..c36e8a6618214063d017c5626bce26868ca13744 100644 (file)
 #endif
 #include "rcu_internal.h"
 
-#if defined(__clang__) && defined(__has_feature)
-#if __has_feature(thread_sanitizer)
-#define __SANITIZE_THREAD__
-#endif
-#endif
-
 #if defined(__SANITIZE_THREAD__)
-#include <sanitizer/tsan_interface.h>
 #define TSAN_FAKE_UNLOCK(x)          \
     __tsan_mutex_pre_unlock((x), 0); \
     __tsan_mutex_post_unlock((x), 0)
index 660fb1e5c65fbb9111663f0680cf420c09fa0cee..98e749d706ccf11fcc4b166aacb446a5234a2dd2 100644 (file)
 #ifndef _CRYPTO_THREADS_COMMON_H_
 #define _CRYPTO_THREADS_COMMON_H_
 
+#if defined(__clang__) && defined(__has_feature)
+#if __has_feature(thread_sanitizer)
+#define __SANITIZE_THREAD__
+#endif
+#endif
+
+#if defined(__SANITIZE_THREAD__)
+#include <sanitizer/tsan_interface.h>
+extern void AnnotateBenignRaceSized(const char *f, int l,
+    const volatile void *mem, unsigned int size, const char *desc);
+#define TSAN_BENIGN(x, desc) \
+    AnnotateBenignRaceSized(__FILE__, __LINE__, &(x), sizeof(x), desc);
+#else
+#define TSAN_BENIGN(x, desc)
+#endif
+
 typedef enum {
     CRYPTO_THREAD_LOCAL_RCU_KEY = 0,
     CRYPTO_THREAD_LOCAL_DRBG_PRIV_KEY,
index 1ba68d6180968ea4e30555e9865bf02830e9ddfe..312003280260b33c01f5a6af14f747282b64a259 100644 (file)
@@ -1482,6 +1482,8 @@ int ossl_deferred_self_test(OSSL_LIB_CTX *libctx, self_test_id_t id)
      * that this function continues until it obtains a lock in FIPS_deferred()
      * and then it will recheck this value and immediately exit.
      */
+
+    TSAN_BENIGN(st_all_tests[id].state, "Fails safe, avoids contention")
     if (st_all_tests[id].state == SELF_TEST_STATE_PASSED)
         return 1;