openssl/openssl

TSAN: data race in ossl_default_provider_init in openssl 3.5.4

已关闭

#28,935 创建于 2025年10月16日

 (3 条评论) (0 个反应) (0 位负责人)C (11,262 个派生)batch import
branch: 3.0branch: 3.3branch: 3.4branch: 3.5branch: 3.6branch: 4.0branch: masterhelp wantedtriaged: bug

仓库指标

星标
 (30,157 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

OpenSSL 3.5.4 built with -fsanitize=thread.

It looks like ossl_default_provider_init always overwrites the global c_get_params and c_gettable_params. This leads to a data race when OSSL_PROVIDER_load is called by different threads.

https://github.com/openssl/openssl/blob/5aaf9746f649d15b3ad006acdc6a958819acc536/providers/defltprov.c#L765-L768

I'm not sure if those could be changed to be local variables instead?

The reason my application calls OSSL_PROVIDER_load on different threads is that it uses a different OSSL_LIB_CTX per thread to reduce contention, and OSSL_PROVIDER_load is used to load the "default" provider into each context.

WARNING: ThreadSanitizer: data race (pid=1810)
  Write of size 8 at 0x7ff0d5f0a540 by thread T3:
    #0 ossl_default_provider_init openssl-3.5.4/providers/defltprov.c:737:31 (libcrypto.so.3+0x5b7450)
    #1 provider_init openssl-3.5.4/crypto/provider_core.c:1045:10 (libcrypto.so.3+0x3ea936)
    #2 provider_activate openssl-3.5.4/crypto/provider_core.c:1271:14 (libcrypto.so.3+0x3ea936)
    #3 ossl_provider_activate openssl-3.5.4/crypto/provider_core.c:1412:18 (libcrypto.so.3+0x3ea552)
    #4 OSSL_PROVIDER_try_load_ex openssl-3.5.4/crypto/provider.c:31:10 (libcrypto.so.3+0x3e6c4e)
    #5 OSSL_PROVIDER_load_ex openssl-3.5.4/crypto/provider.c:62:16 (libcrypto.so.3+0x3e6dc0)
    #6 OSSL_PROVIDER_load openssl-3.5.4/crypto/provider.c:68:12 (libcrypto.so.3+0x3e6dc0)
    ...

  Previous write of size 8 at 0x7ff0d5f0a540 by thread T2:
    #0 ossl_default_provider_init openssl-3.5.4/providers/defltprov.c:737:31 (libcrypto.so.3+0x5b7450)
    #1 provider_init openssl-3.5.4/crypto/provider_core.c:1045:10 (libcrypto.so.3+0x3ea936)
    #2 provider_activate openssl-3.5.4/crypto/provider_core.c:1271:14 (libcrypto.so.3+0x3ea936)
    #3 ossl_provider_activate openssl-3.5.4/crypto/provider_core.c:1412:18 (libcrypto.so.3+0x3ea552)
    #4 OSSL_PROVIDER_try_load_ex openssl-3.5.4/crypto/provider.c:31:10 (libcrypto.so.3+0x3e6c4e)
    #5 OSSL_PROVIDER_load_ex openssl-3.5.4/crypto/provider.c:62:16 (libcrypto.so.3+0x3e6dc0)
    #6 OSSL_PROVIDER_load openssl-3.5.4/crypto/provider.c:68:12 (libcrypto.so.3+0x3e6dc0)
    ...

贡献者指南