From 3b933a6e933c46660bf9640153f81e896d855032 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Fri, 6 Sep 2024 17:46:57 +0000 Subject: [PATCH 01/13] Remove submodules (cherry picked from commit ae2e0753685696f30915675d7f76a91bee56c339) --- .gitmodules | 37 ------------------------------------- cloudflare-quiche | 1 - fuzz/corpora | 1 - gost-engine | 1 - krb5 | 1 - oqs-provider | 1 - pyca-cryptography | 1 - python-ecdsa | 1 - tlsfuzzer | 1 - tlslite-ng | 1 - wycheproof | 1 - 11 files changed, 47 deletions(-) delete mode 160000 cloudflare-quiche delete mode 160000 fuzz/corpora delete mode 160000 gost-engine delete mode 160000 krb5 delete mode 160000 oqs-provider delete mode 160000 pyca-cryptography delete mode 160000 python-ecdsa delete mode 160000 tlsfuzzer delete mode 160000 tlslite-ng delete mode 160000 wycheproof diff --git a/.gitmodules b/.gitmodules index b4c756a67b179..e69de29bb2d1d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,37 +0,0 @@ -[submodule "pyca.cryptography"] - path = pyca-cryptography - url = https://github.com/pyca/cryptography.git - -[submodule "krb5"] - path = krb5 - url = https://github.com/krb5/krb5 - -[submodule "gost-engine"] - path = gost-engine - url = https://github.com/gost-engine/engine - update = rebase -[submodule "wycheproof"] - path = wycheproof - url = https://github.com/google/wycheproof -[submodule "tlsfuzzer"] - path = tlsfuzzer - url = https://github.com/tlsfuzzer/tlsfuzzer -[submodule "python-ecdsa"] - path = python-ecdsa - url = https://github.com/tlsfuzzer/python-ecdsa -[submodule "tlslite-ng"] - path = tlslite-ng - url = https://github.com/tlsfuzzer/tlslite-ng -[submodule "oqs-provider"] - path = oqs-provider - url = https://github.com/open-quantum-safe/oqs-provider.git -[submodule "cloudflare-quiche"] - path = cloudflare-quiche - url = https://github.com/cloudflare/quiche -[submodule "fuzz/corpora"] - path = fuzz/corpora - url = https://github.com/openssl/fuzz-corpora - branch = main -[submodule "pkcs11-provider"] - path = pkcs11-provider - url = https://github.com/latchset/pkcs11-provider.git diff --git a/cloudflare-quiche b/cloudflare-quiche deleted file mode 160000 index 7ab6a55cfe471..0000000000000 --- a/cloudflare-quiche +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7ab6a55cfe471267d61e4d28ba43d41defcd87e0 diff --git a/fuzz/corpora b/fuzz/corpora deleted file mode 160000 index ce771805c094d..0000000000000 --- a/fuzz/corpora +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ce771805c094d098c25a218bc8e9f7344eccbc5a diff --git a/gost-engine b/gost-engine deleted file mode 160000 index 74b1f4fddbc2d..0000000000000 --- a/gost-engine +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 74b1f4fddbc2d6de969815b1992ddc1ae7c643fe diff --git a/krb5 b/krb5 deleted file mode 160000 index 784c38f50e70a..0000000000000 --- a/krb5 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 784c38f50e70a739400cdd3f2620bac2e2788e6c diff --git a/oqs-provider b/oqs-provider deleted file mode 160000 index 7bc597c04b534..0000000000000 --- a/oqs-provider +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7bc597c04b534ddea9b6654481deb31ded8e1bbc diff --git a/pyca-cryptography b/pyca-cryptography deleted file mode 160000 index 7e33b0e7739d6..0000000000000 --- a/pyca-cryptography +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7e33b0e7739d633c77b8c478620167f693ed13f4 diff --git a/python-ecdsa b/python-ecdsa deleted file mode 160000 index 4096fa0171592..0000000000000 --- a/python-ecdsa +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4096fa01715929e08b97e73f3173aee9d57f2a3f diff --git a/tlsfuzzer b/tlsfuzzer deleted file mode 160000 index 61f45d9701294..0000000000000 --- a/tlsfuzzer +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 61f45d9701294fd87ef92d2a7e3dfb076653a562 diff --git a/tlslite-ng b/tlslite-ng deleted file mode 160000 index 77ef321dde1a9..0000000000000 --- a/tlslite-ng +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 77ef321dde1a9e6bcf94d73c80f8789a770d8031 diff --git a/wycheproof b/wycheproof deleted file mode 160000 index 2196000605e45..0000000000000 --- a/wycheproof +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2196000605e45d91097147c9c71f26b72af58003 From e48372d2957bf13d03ae69f7a15ed9b41ed29bbb Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Fri, 26 Jan 2024 16:34:22 +0000 Subject: [PATCH 02/13] Msan fixes (cherry picked from commit 35f2869954dd2671ee2f02c808ec0ee34d74eee3) --- crypto/bn/bn_intern.c | 10 ++++++++++ crypto/cpuid.c | 9 +++++++++ providers/implementations/rands/drbg_ctr.c | 12 ++++++++++++ 3 files changed, 31 insertions(+) diff --git a/crypto/bn/bn_intern.c b/crypto/bn/bn_intern.c index bd299cd1442d7..6fa404afce2cd 100644 --- a/crypto/bn/bn_intern.c +++ b/crypto/bn/bn_intern.c @@ -10,6 +10,11 @@ #include "internal/cryptlib.h" #include "bn_local.h" +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) +# include +# endif +#endif /* * Determine the modified width-(w+1) Non-Adjacent Form (wNAF) of 'scalar'. * This is an array r[] of values that are either zero or odd with an @@ -188,6 +193,11 @@ int bn_set_words(BIGNUM *a, const BN_ULONG *words, int num_words) return 0; } +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __msan_unpoison(words, sizeof(BN_ULONG) * num_words); +# endif +#endif memcpy(a->d, words, sizeof(BN_ULONG) * num_words); a->top = num_words; bn_correct_top(a); diff --git a/crypto/cpuid.c b/crypto/cpuid.c index d659135919d1f..18c648148a30c 100644 --- a/crypto/cpuid.c +++ b/crypto/cpuid.c @@ -102,7 +102,16 @@ void OPENSSL_cpuid_setup(void) if (trigger) return; + /// This function is called from .init section before memory sanitizer mmaps shadow memory. + /// Program will crash with segmentation fault when trying access `trigger`, + /// because its address was replaced with some not mapped address. + /// Also see https://github.com/ClickHouse/openssl/pull/5 + /// Unfortunately, __msan_init() is no longer part of msan's public header and there seems to be no replacement. +#if defined(__has_feature) +# if !__has_feature(memory_sanitizer) trigger = 1; +# endif +#endif if ((env = ossl_getenv("OPENSSL_ia32cap")) != NULL) { int off = (env[0] == '~') ? 1 : 0; diff --git a/providers/implementations/rands/drbg_ctr.c b/providers/implementations/rands/drbg_ctr.c index 57da1cfdf33df..fa4a7400ffbd2 100644 --- a/providers/implementations/rands/drbg_ctr.c +++ b/providers/implementations/rands/drbg_ctr.c @@ -25,6 +25,12 @@ #include "internal/provider.h" #include "internal/common.h" +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) +# include +# endif +#endif + static OSSL_FUNC_rand_newctx_fn drbg_ctr_new_wrapper; static OSSL_FUNC_rand_freectx_fn drbg_ctr_free; static OSSL_FUNC_rand_instantiate_fn drbg_ctr_instantiate_wrapper; @@ -72,6 +78,12 @@ static void inc_128(PROV_DRBG_CTR *ctr) p[n] = (u8)c; c >>= 8; } while (n); + +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __msan_unpoison(p, 16); +# endif +#endif } static void ctr_XOR(PROV_DRBG_CTR *ctr, const unsigned char *in, size_t inlen) From e695f2b83f19d418dc76a80a289c16237a77cfd3 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Thu, 25 Jan 2024 11:03:50 +0000 Subject: [PATCH 03/13] Remove dependency on "getrandom" function (cherry picked from commit a6387b8f1883fc074cd92c83a20fa5930accaba6) --- providers/implementations/rands/seeding/rand_unix.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/providers/implementations/rands/seeding/rand_unix.c b/providers/implementations/rands/seeding/rand_unix.c index 0b8a9ec341d92..ed82495e693fc 100644 --- a/providers/implementations/rands/seeding/rand_unix.c +++ b/providers/implementations/rands/seeding/rand_unix.c @@ -351,8 +351,13 @@ static ssize_t syscall_random(void *buf, size_t buflen) * Note: Sometimes getentropy() can be provided but not implemented * internally. So we need to check errno for ENOSYS */ -#if !defined(__DragonFly__) && !defined(__NetBSD__) && !defined(__FreeBSD__) -#if defined(__GNUC__) && __GNUC__ >= 2 && defined(__ELF__) && !defined(__hpux) +# if !defined(__DragonFly__) && !defined(__NetBSD__) && !defined(__FreeBSD__) + + /// Disable the usage of "getentropy" function from libc (on static link time) to avoid dependency on too new libc version. + /// Otherwise, if we build ClickHouse on a system with new libc and run the built binary on a system with old libc, it will fail. + /// + /// Note that there is a fallback below to (1) runtime symbol lookup and (2) direct syscall, that are equivalent. +# if 0 && defined(__GNUC__) && __GNUC__>=2 && defined(__ELF__) && !defined(__hpux) extern int getentropy(void *buffer, size_t length) __attribute__((weak)); if (getentropy != NULL) { From 7d1f427605cfabaa51006ade4012a6ef07db5f89 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Mon, 11 Mar 2024 14:03:58 +0000 Subject: [PATCH 04/13] Remove dependency on glibc 2.14 sendmmsg/recvmmsg (cherry picked from commit a5c57bbdeca0042282b6427ee72c2abcbba4ec23) --- crypto/bio/bss_dgram.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crypto/bio/bss_dgram.c b/crypto/bio/bss_dgram.c index 968104a062086..8d802bb020a45 100644 --- a/crypto/bio/bss_dgram.c +++ b/crypto/bio/bss_dgram.c @@ -49,7 +49,9 @@ #define M_METHOD_WSARECVMSG 4 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ) -#if !(__GLIBC_PREREQ(2, 14)) +/// ClickHouse-specific patch: Pretend to use a stone age glibc because we use a stone age glibc. +/// Otherwise, system calls sendmmsg and recvmmsg are used which work only with too-new glibc 2.14. +/// #if !(__GLIBC_PREREQ(2, 14)) #undef NO_RECVMMSG /* * Some old glibc versions may have recvmmsg and MSG_WAITFORONE flag, but @@ -57,7 +59,7 @@ * versions */ #define NO_RECVMMSG -#endif +/// #endif #endif #if defined(__GNU__) /* GNU/Hurd does not have IP_PKTINFO yet */ From fb58a0f16aaa9a4e721056746f5ce2c6e5071cb6 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Wed, 20 Mar 2024 12:22:40 +0000 Subject: [PATCH 05/13] Suppress tsan failures: use locks instead of atomics ----- E Exception: Sanitizer assert found for instance ================== E WARNING: ThreadSanitizer: data race (pid=1) E Write of size 8 at 0x7b2800025d30 by thread T2 (mutexes: write M0, write M1): E #0 free (clickhouse+0x709a3e5) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #1 CRYPTO_free build_docker/./contrib/openssl/crypto/mem.c:282:5 (clickhouse+0x2015f8ea) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #2 EVP_PKEY_free build_docker/./contrib/openssl/crypto/evp/p_lib.c:1809:5 (clickhouse+0x2012a751) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #3 Poco::Crypto::EVPPKey::~EVPPKey() build_docker/./base/poco/Crypto/src/EVPPKey.cpp:121:17 (clickhouse+0x1d00ffa9) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #4 DB::CertificateReloader::Data::~Data() build_docker/./src/Server/CertificateReloader.h:71:12 (clickhouse+0x194fb42d) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #5 std::__1::default_delete::operator()[abi:v15000](DB::CertificateReloader::Data const*) const build_docker/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:48:5 (clickhouse+0x194fb42d) E #6 std::__1::__shared_ptr_pointer, std::__1::allocator>::__on_zero_shared() build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:263:5 (clickhouse+0x194fb42d) E #7 std::__1::__shared_count::__release_shared[abi:v15000]() build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:174:9 (clickhouse+0x194fade0) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #8 std::__1::__shared_weak_count::__release_shared[abi:v15000]() build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:215:27 (clickhouse+0x194fade0) E #9 std::__1::shared_ptr::~shared_ptr[abi:v15000]() build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:702:23 (clickhouse+0x194fade0) E #10 std::__1::shared_ptr::operator=[abi:v15000](std::__1::shared_ptr&&) build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:723:9 (clickhouse+0x194fade0) E #11 MultiVersion::set(std::__1::unique_ptr>&&) build_docker/./src/Common/MultiVersion.h:76:25 (clickhouse+0x194fade0) E #12 DB::CertificateReloader::tryLoad(Poco::Util::AbstractConfiguration const&) build_docker/./src/Server/CertificateReloader.cpp:83:18 (clickhouse+0x194f94ca) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #13 DB::Server::main(std::__1::vector, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_6::operator()(Poco::AutoPtr, bool) const build_docker/./programs/server/Server.cpp:1546:45 (clickhouse+0xf384df7) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #14 decltype(std::declval, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_6&>()(std::declval>(), std::declval())) std::__1::__invoke[abi:v15000], std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_6&, Poco::AutoPtr, bool>(DB::Server::main(std::__1::vector, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_6&, Poco::AutoPtr&&, bool&&) build_docker/./contrib/llvm-project/libcxx/include/__functional/invoke.h:394:23 (clickhouse+0xf3827a9) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #15 void std::__1::__invoke_void_return_wrapper::__call, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_6&, Poco::AutoPtr, bool>(DB::Server::main(std::__1::vector, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_6&, Poco::AutoPtr&&, bool&&) build_docker/./contrib/llvm-project/libcxx/include/__functional/invoke.h:479:9 (clickhouse+0xf3827a9) E #16 std::__1::__function::__default_alloc_func, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_6, void (Poco::AutoPtr, bool)>::operator()[abi:v15000](Poco::AutoPtr&&, bool&&) build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:235:12 (clickhouse+0xf3827a9) E #17 void std::__1::__function::__policy_invoker, bool)>::__call_impl, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_6, void (Poco::AutoPtr, bool)>>(std::__1::__function::__policy_storage const*, Poco::AutoPtr&&, bool) build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:716:16 (clickhouse+0xf3827a9) E #18 std::__1::__function::__policy_func, bool)>::operator()[abi:v15000](Poco::AutoPtr&&, bool&&) const build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:848:16 (clickhouse+0x19fd2cbe) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #19 std::__1::function, bool)>::operator()(Poco::AutoPtr, bool) const build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:1187:12 (clickhouse+0x19fd2cbe) E #20 DB::ConfigReloader::reloadIfNewer(bool, bool, bool, bool) build_docker/./src/Common/Config/ConfigReloader.cpp:150:13 (clickhouse+0x19fd2cbe) E #21 DB::ConfigReloader::reload() build_docker/./src/Common/Config/ConfigReloader.h:51:21 (clickhouse+0xf38767c) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #22 DB::Server::main(std::__1::vector, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_13::operator()() const build_docker/./programs/server/Server.cpp:1731:31 (clickhouse+0xf38767c) E #23 decltype(std::declval, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_13&>()()) std::__1::__invoke[abi:v15000], std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_13&>(DB::Server::main(std::__1::vector, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_13&) build_docker/./contrib/llvm-project/libcxx/include/__functional/invoke.h:394:23 (clickhouse+0xf38767c) E #24 void std::__1::__invoke_void_return_wrapper::__call, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_13&>(DB::Server::main(std::__1::vector, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_13&) build_docker/./contrib/llvm-project/libcxx/include/__functional/invoke.h:479:9 (clickhouse+0xf38767c) E #25 std::__1::__function::__default_alloc_func, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_13, void ()>::operator()[abi:v15000]() build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:235:12 (clickhouse+0xf38767c) E #26 void std::__1::__function::__policy_invoker::__call_impl, std::__1::allocator>, std::__1::allocator, std::__1::allocator>>> const&)::$_13, void ()>>(std::__1::__function::__policy_storage const*) build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:716:16 (clickhouse+0xf38767c) E #27 std::__1::__function::__policy_func::operator()[abi:v15000]() const build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:848:16 (clickhouse+0x16907aa0) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #28 std::__1::function::operator()() const build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:1187:12 (clickhouse+0x16907aa0) E #29 DB::Context::reloadConfig() const build_docker/./src/Interpreters/Context.cpp:4357:5 (clickhouse+0x16907aa0) E #30 DB::InterpreterSystemQuery::execute() build_docker/./src/Interpreters/InterpreterSystemQuery.cpp:577:29 (clickhouse+0x17e78c19) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #31 DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr, DB::QueryFlags, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) build_docker/./src/Interpreters/executeQuery.cpp:1195:40 (clickhouse+0x17e3e462) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #32 DB::executeQuery(std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr, DB::QueryFlags, DB::QueryProcessingStage::Enum) build_docker/./src/Interpreters/executeQuery.cpp:1374:26 (clickhouse+0x17e39837) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #33 DB::TCPHandler::runImpl() build_docker/./src/Server/TCPHandler.cpp:518:54 (clickhouse+0x195cc651) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #34 DB::TCPHandler::run() build_docker/./src/Server/TCPHandler.cpp:2329:9 (clickhouse+0x195e8707) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #35 Poco::Net::TCPServerConnection::start() build_docker/./base/poco/Net/src/TCPServerConnection.cpp:43:3 (clickhouse+0x1d00d942) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #36 Poco::Net::TCPServerDispatcher::run() build_docker/./base/poco/Net/src/TCPServerDispatcher.cpp:115:20 (clickhouse+0x1d00e1b1) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #37 Poco::PooledThread::run() build_docker/./base/poco/Foundation/src/ThreadPool.cpp:188:14 (clickhouse+0x1d20f2e6) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #38 Poco::(anonymous namespace)::RunnableHolder::run() build_docker/./base/poco/Foundation/src/Thread.cpp:45:11 (clickhouse+0x1d20d5af) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #39 Poco::ThreadImpl::runnableEntry(void*) build_docker/./base/poco/Foundation/src/Thread_POSIX.cpp:335:27 (clickhouse+0x1d20ba69) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E E Previous atomic write of size 4 at 0x7b2800025d30 by thread T3 (mutexes: write M2): E #0 CRYPTO_DOWN_REF build_docker/./contrib/openssl/include/internal/refcount.h:51:12 (clickhouse+0x2012a6e6) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #1 EVP_PKEY_free build_docker/./contrib/openssl/crypto/evp/p_lib.c:1795:5 (clickhouse+0x2012a6e6) E #2 ssl_cert_clear_certs build_docker/./contrib/openssl/ssl/ssl_cert.c:246:9 (clickhouse+0x1ffafd37) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #3 ssl_cert_free build_docker/./contrib/openssl/ssl/ssl_cert.c:277:5 (clickhouse+0x1ffafd37) E #4 ossl_ssl_connection_free build_docker/./contrib/openssl/ssl/ssl_lib.c:1458:5 (clickhouse+0x1ffba6af) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #5 SSL_free build_docker/./contrib/openssl/ssl/ssl_lib.c:1417:9 (clickhouse+0x1ffb920e) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #6 Poco::Net::SecureSocketImpl::reset() build_docker/./base/poco/NetSSL_OpenSSL/src/SecureSocketImpl.cpp:583:3 (clickhouse+0x1cfaac60) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #7 Poco::Net::SecureSocketImpl::~SecureSocketImpl() build_docker/./base/poco/NetSSL_OpenSSL/src/SecureSocketImpl.cpp:80:3 (clickhouse+0x1cfaac60) E #8 Poco::Net::SecureStreamSocketImpl::~SecureStreamSocketImpl() build_docker/./base/poco/NetSSL_OpenSSL/src/SecureStreamSocketImpl.cpp:52:1 (clickhouse+0x1cfb15dd) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #9 Poco::Net::SecureStreamSocketImpl::~SecureStreamSocketImpl() build_docker/./base/poco/NetSSL_OpenSSL/src/SecureStreamSocketImpl.cpp:43:1 (clickhouse+0x1cfb15dd) E #10 Poco::RefCountedObject::release() const build_docker/./base/poco/Foundation/include/Poco/RefCountedObject.h:86:13 (clickhouse+0x1cffc81e) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #11 Poco::Net::Socket::~Socket() build_docker/./base/poco/Net/src/Socket.cpp:68:10 (clickhouse+0x1cffc81e) E #12 Poco::Net::StreamSocket::~StreamSocket() build_docker/./base/poco/Net/src/StreamSocket.cpp:63:1 (clickhouse+0x1d009c39) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #13 Poco::Net::TCPConnectionNotification::~TCPConnectionNotification() build_docker/./base/poco/Net/src/TCPServerDispatcher.cpp:43:2 (clickhouse+0x1d00ef50) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #14 Poco::Net::TCPConnectionNotification::~TCPConnectionNotification() build_docker/./base/poco/Net/src/TCPServerDispatcher.cpp:42:2 (clickhouse+0x1d00ef50) E #15 Poco::RefCountedObject::release() const build_docker/./base/poco/Foundation/include/Poco/RefCountedObject.h:86:13 (clickhouse+0x1d00e203) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #16 Poco::AutoPtr::~AutoPtr() build_docker/./base/poco/Foundation/include/Poco/AutoPtr.h:91:19 (clickhouse+0x1d00e203) E #17 Poco::Net::TCPServerDispatcher::run() build_docker/./base/poco/Net/src/TCPServerDispatcher.cpp:122:3 (clickhouse+0x1d00e203) E #18 Poco::PooledThread::run() build_docker/./base/poco/Foundation/src/ThreadPool.cpp:188:14 (clickhouse+0x1d20f2e6) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #19 Poco::(anonymous namespace)::RunnableHolder::run() build_docker/./base/poco/Foundation/src/Thread.cpp:45:11 (clickhouse+0x1d20d5af) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #20 Poco::ThreadImpl::runnableEntry(void*) build_docker/./base/poco/Foundation/src/Thread_POSIX.cpp:335:27 (clickhouse+0x1d20ba69) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) (cherry picked from commit 5b50434b7180034ff7b427cf76838098673e9232) --- include/internal/refcount.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/internal/refcount.h b/include/internal/refcount.h index 61eb78ae41205..5c11c80fc15fa 100644 --- a/include/internal/refcount.h +++ b/include/internal/refcount.h @@ -21,8 +21,9 @@ #define HAVE_C11_ATOMICS #endif -#if defined(HAVE_C11_ATOMICS) && defined(ATOMIC_INT_LOCK_FREE) \ - && ATOMIC_INT_LOCK_FREE > 0 +# if defined(HAVE_C11_ATOMICS) && defined(ATOMIC_INT_LOCK_FREE) \ + && ATOMIC_INT_LOCK_FREE > 0 \ + && 0 /// ClickHouse-specific patch: if we use atomics, tsan complains :( #define HAVE_ATOMICS 1 @@ -74,7 +75,8 @@ static inline int CRYPTO_GET_REF(CRYPTO_REF_COUNT *refcnt, int *ret) return 1; } -#elif defined(__GNUC__) && defined(__ATOMIC_RELAXED) && __GCC_ATOMIC_INT_LOCK_FREE > 0 +# elif defined(__GNUC__) && defined(__ATOMIC_RELAXED) && __GCC_ATOMIC_INT_LOCK_FREE > 0 \ + && 0 /// ClickHouse-specific patch: if we use atomics, tsan complains :( #define HAVE_ATOMICS 1 From bd256c6e464bd42038fb992cbafcd4952748ac8e Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Tue, 11 Jun 2024 19:25:32 +0000 Subject: [PATCH 06/13] Suppress leaky memory warning During my testing (*), I got below stack about leaked memory. - at database startup, Azure is registered as an object storage (--> registerAzureObjectStorage) - this calls into Azure, then into curl, and then into OpenSSL - curl asks OpenSSL for a bunch of random numbers (--> function 'ossl_random' in curl's OpenSSL wrapper) - OpenSSL initializes the random number generator and stores it in some random number generator context object (--> *RAND_get0_public) - this object is registered via pthread_key_create and pthread_setspecific registered in TLS - if registerAzureObjectStorage was the only place which initializes the RNG, we could argue that the leaked memory does not matter anyways as it is released after shutdown - RAND_get0_public also registers a free handler (rand_delete_thread_state) that runs in TLS, so the memory is released also if registration is called from arbitrary other threads. In sum: this is a false positive. (*) https://github.com/ClickHouse/clickhouse-private/issues/10107#issuecomment-2161282313 ``` ================================================================= ==2757181==ERROR: LeakSanitizer: detected memory leaks Direct leak of 48 byte(s) in 1 object(s) allocated from: #0 0x5672f4a48083 in malloc (/data/ch4/build_asan/programs/clickhouse+0xa2b7083) (BuildId: 4d868624feaa8b5598d9d0b327749c877bfb6cfd) #1 0x567321d05c7e in CRYPTO_malloc build_asan/./contrib/openssl/crypto/mem.c:202:11 #2 0x567321d05c7e in CRYPTO_zalloc build_asan/./contrib/openssl/crypto/mem.c:222:11 #3 0x567321d5f9cf in EVP_RAND_CTX_new build_asan/./contrib/openssl/crypto/evp/evp_rand.c:353:11 #4 0x567321d627db in rand_new_drbg build_asan/./contrib/openssl/crypto/rand/rand_lib.c:658:11 #5 0x567321d61e7b in RAND_get0_public build_asan/./contrib/openssl/crypto/rand/rand_lib.c:777:16 #6 0x567321d61d4f in RAND_bytes_ex build_asan/./contrib/openssl/crypto/rand/rand_lib.c:378:12 #7 0x56731cfe9267 in ossl_random openssl.c #8 0x56731cf534ae in Curl_rand (/data/ch4/build_asan/programs/clickhouse+0x327c24ae) (BuildId: 4d868624feaa8b5598d9d0b327749c877bfb6cfd) #9 0x56731cf757dc in Curl_socketpair (/data/ch4/build_asan/programs/clickhouse+0x327e47dc) (BuildId: 4d868624feaa8b5598d9d0b327749c877bfb6cfd) #10 0x56731cf40bfe in Curl_multi_handle (/data/ch4/build_asan/programs/clickhouse+0x327afbfe) (BuildId: 4d868624feaa8b5598d9d0b327749c877bfb6cfd) #11 0x56731cecb260 in curl_easy_perform (/data/ch4/build_asan/programs/clickhouse+0x3273a260) (BuildId: 4d868624feaa8b5598d9d0b327749c877bfb6cfd) #12 0x56731cd4a351 in Azure::Core::Http::CurlConnection::CurlConnection(Azure::Core::Http::Request&, Azure::Core::Http::CurlTransportOptions const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::basic_string, std::__1::allocator> const&) build_asan/./contrib/azure/sdk/core/azure-core/src/http/curl/curl.cpp:2441:24 #13 0x56731cd3176b in std::__1::__unique_if::__unique_single std::__1::make_unique[abi:v15000], std::__1::allocator> const&, std::__1::basic_string, std::__1::allocator> const&>(Azure::Core::Http::Request&, Azure::Core::H ttp::CurlTransportOptions const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::basic_string, std::__1::allocator> const&) build_asan/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:714:32 #14 0x56731cd3176b in Azure::Core::Http::_detail::CurlConnectionPool::ExtractOrCreateCurlConnection(Azure::Core::Http::Request&, Azure::Core::Http::CurlTransportOptions const&, bool) build_asan/./contrib/azure/sdk/core/azure-core/src/http/curl/curl.cpp:2126:10 #15 0x56731cd2f891 in Azure::Core::Http::CurlTransport::Send(Azure::Core::Http::Request&, Azure::Core::Context const&) build_asan/./contrib/azure/sdk/core/azure-core/src/http/curl/curl.cpp:351:48 #16 0x56731cdd66db in Azure::Core::Http::Policies::_internal::TransportPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_asan/./contrib/azure/sdk/core/azure-core/src/http/transport_policy.cpp:121:40 #17 0x56731cd7c75b in Azure::Core::Http::Policies::_internal::LogPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_asan/./contrib/azure/sdk/core/azure-core/src/http/log_policy.cpp:114:23 #18 0x56731cdd0218 in Azure::Core::Http::Policies::_internal::RequestActivityPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_asan/./contrib/azure/sdk/core/azure-core/src/http/request_activity_policy.cpp:110:23 #19 0x56731cec5f18 in Azure::Storage::_internal::StoragePerRetryPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_asan/./contrib/azure/sdk/storage/azure-storage-common/src/storage_per_retry_policy.cpp:57:23 #20 0x56731cec6d0b in Azure::Storage::_internal::StorageSwitchToSecondaryPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_asan/./contrib/azure/sdk/storage/azure-storage-common/src/storage_switch_to_secondary_policy.cpp:36:32 #21 0x56731cdcd019 in Azure::Core::Http::Policies::_internal::RetryPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_asan/./contrib/azure/sdk/core/azure-core/src/http/retry_policy.cpp:146:34 #22 0x56731cdd6e17 in Azure::Core::Http::Policies::_internal::TelemetryPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_asan/./contrib/azure/sdk/core/azure-core/src/http/telemetry_policy.cpp:23:21 #23 0x56731cdb0ef5 in Azure::Core::Http::Policies::_internal::RequestIdPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_asan/./contrib/azure/sdk/core/azure-core/inc/azure/core/http/policies/policy.hpp:453:27 #24 0x56731cdfc53e in Azure::Storage::_internal::StorageServiceVersionPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_asan/./contrib/azure/sdk/storage/azure-storage-common/inc/azure/storage/common/internal/storage_service_version_policy.hpp:34:25 #25 0x56731ce4bff1 in Azure::Core::Http::_internal::HttpPipeline::Send(Azure::Core::Http::Request&, Azure::Core::Context const&) const build_asan/./contrib/azure/sdk/core/azure-core/inc/azure/core/internal/http/pipeline.hpp:230:29 #26 0x56731ce4bff1 in Azure::Storage::Blobs::_detail::BlobContainerClient::Create(Azure::Core::Http::_internal::HttpPipeline&, Azure::Core::Url const&, Azure::Storage::Blobs::_detail::BlobContainerClient::CreateBlobContainerOptions const&, Azure::Core::Context const&) build_asan/./contrib/azure/sdk/storage/azure-storage-blobs/src/rest_client.cpp:1415:36 #27 0x56731ce0bdd8 in Azure::Storage::Blobs::BlobContainerClient::Create(Azure::Storage::Blobs::CreateBlobContainerOptions const&, Azure::Core::Context const&) const build_asan/./contrib/azure/sdk/storage/azure-storage-blobs/src/blob_container_client.cpp:258:12 #28 0x56731ce396dc in Azure::Storage::Blobs::BlobServiceClient::CreateBlobContainer(std::__1::basic_string, std::__1::allocator> const&, Azure::Storage::Blobs::CreateBlobContainerOptions const&, Azure::Core::Context const&) const build_asan/./contrib/azure/sdk/storage/azure-storage-blobs/src/blob_service_client.cpp:264:41 #29 0x56731018fcff in DB::getAzureBlobContainerClient(Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&) build_asan/./src/Disks/ObjectStorages/AzureBlobStorage/AzureBlobStorageAuth.cpp:236:75 #30 0x5673115a7352 in DB::registerAzureObjectStorage(DB::ObjectStorageFactory&)::$_0::operator()(std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool) const build_asan/./src/Disks/ObjectStorages/ObjectStorageFactory.cpp:315:13 #31 0x5673115a7352 in decltype(std::declval()(std::declval, std::__1::allocator> const&>(), std::declval(), std::declval, std::__1::allocator> const&>(), std::declval const&>(), std::declval() )) std::__1::__invoke[abi:v15000], std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool>(DB::registerAzureObjectStorage(DB::ObjectStorageFactory&)::$_0&, std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool&&) build_asan/./contrib/llvm-project/libcxx/include/__functional/invoke.h:394:23 #32 0x5673115a7352 in std::__1::shared_ptr std::__1::__invoke_void_return_wrapper, false>::__call, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_pt r const&, bool>(DB::registerAzureObjectStorage(DB::ObjectStorageFactory&)::$_0&, std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool&&) build_asan/./contrib/llvm-project/libcxx/include/__functional/invoke.h:470:16 #33 0x5673115a7352 in std::__1::__function::__default_alloc_func (std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool)>::operator()[abi:v 15000](std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool&&) build_asan/./contrib/llvm-project/libcxx/include/__functional/function.h:235:12 #34 0x5673115a7352 in std::__1::shared_ptr std::__1::__function::__policy_invoker (std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool)>::__call_impl (std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool)>>(std::__1::__function::__policy_storage const*, std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool) build_asan/./contrib/llvm-project/libcxx/include/__functional/function.h:716:16 #35 0x5673115a0780 in std::__1::__function::__policy_func (std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool)>::operator()[abi:v15000](std::__1::basic_string, std::_ _1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool&&) const build_asan/./contrib/llvm-project/libcxx/include/__functional/function.h:848:16 #36 0x5673115a0780 in std::__1::function (std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool)>::operator()(std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool) const build_asan/./contrib/llvm-project/libcxx/include/__functional/function.h:1187:12 #37 0x5673115a0780 in DB::ObjectStorageFactory::create(std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr const&, bool) const build_asan/./src/Disks/ObjectStorages/ObjectStorageFactory.cpp:135:12 #38 0x56731159ef45 in DB::registerDiskObjectStorage(DB::DiskFactory&, bool)::$_0::operator()(std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr, std::__1::map, std::__1::allocator>, std::__1: :shared_ptr, std::__1::less, std::__1::allocator>>, std::__1::allocator, std::__1::allocator> const, std::__1::shared_ptr>>> const&, bool, bool) const build_asan/./src/Disks/ObjectStorages/RegisterDiskObjectStorage.cpp:27:64 #39 0x56731159ef45 in decltype(std::declval()(std::declval, std::__1::allocator> const&>(), std::declval(), std::declval, std::__1::allocator> const&>(), std::declval>(), std::declval, std::__1::allocator>, std::__1::shared_ptr, std::__1::less, std::__1::allocator>>, std::__1::allocator, std::__1::allocator> const, std::__1::shared_ptr>>> const&>(), std::declval(), std::declval())) std::__1::__invoke[abi:v15000], std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr, std::__1::map, std::__1::allocator>, std::__1::shared_ptr, std::__1::less, std::__1::allocator>>, std::__1::allocator, std::__1::allocator> const, std::__1::shared_ptr>>> const&, bool, bool>(DB::registerDiskObjectStorage(DB::DiskFactory&, bool)::$_0&, std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_ string, std::__1::allocator> const&, std::__1::shared_ptr&&, std::__1::map, std::__1::allocator>, std::__1::shared_ptr, std::__1::less, std::__1::allocator>>, std::__1::allocator, std::__1::allocator> const, std::__1::shared_ptr>>> const&, bool&&, bool&&) build_asan/./contrib/llvm-project/libcxx/include/__functional/invoke.h:394:23 #40 0x56731159ef45 in std::__1::shared_ptr std::__1::__invoke_void_return_wrapper, false>::__call, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr, std::__1::map, std::__1::allocator>, std::__1::shared_ptr, std::__1::less, std::__1::allocator>>, std::__1::allocator, std::__1::allocator> const, std::__1::shared_ptr>>> const&, bool, bool>(DB::registerDiskObjectStorage(DB::DiskFactory&, bool)::$_0 &, std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr&&, std::__1::map, std::__1::allocator>, std::__1::shared_ptr, std::__1::less, std::__1::allocator>>, std::__1::allocator, std::__1::allocator> const, std::__1::shared_ptr>>> const&, bool&&, bool&&) build_asan/./contrib/llvm-project/libcxx/include/__functional/invoke.h:470:16 #41 0x56731159ef45 in std::__1::__function::__default_alloc_func (std::__1::basic_string, std::__1::allocator> const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr, std::__1::map, std::__1::allocator>, std::__1::shared_ptr, std::__1::less, std::__1::allocator>>, std::__1::allocator, std::__1::allocator> const, std::__1::shared_ptr>>> const&, bool, bool)>::operator()[abi:v15000](std::__1::basic_string, std::__1::allocator > const&, Poco::Util::AbstractConfiguration const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::shared_ptr&&, std::__1::map, std::__1::allocator>, std::__1::shared_ptr, std::__1::less, std::__1::allocator>>, std::__1::allocator, std::__1::allocator> const, std::__1::shared_ptr>>> const&, bool&&, bool&&) build_asan/./contrib/llvm-project/libcxx/include/__functional/function.h:235:12 ``` (cherry picked from commit 8eaedf35d2f9077f1ead2d89478812ba437d860b) --- crypto/rand/rand_lib.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c index df70d1c2b1dad..3f0d6585f46e9 100644 --- a/crypto/rand/rand_lib.c +++ b/crypto/rand/rand_lib.c @@ -103,6 +103,13 @@ static RAND_GLOBAL *rand_get_global(OSSL_LIB_CTX *libctx) return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_DRBG_INDEX); } + +#if defined(__has_feature) +# if __has_feature(address_sanitizer) +#include +# endif +#endif + #ifndef FIPS_MODULE #include #include @@ -857,8 +864,18 @@ static EVP_RAND_CTX *rand_get0_public(OSSL_LIB_CTX *ctx, RAND_GLOBAL *dgbl) if (CRYPTO_THREAD_get_local(&dgbl->private) == NULL && !ossl_init_thread_start(NULL, ctx, rand_delete_thread_state)) return NULL; +#if defined(__has_feature) +# if __has_feature(address_sanitizer) + __lsan_disable(); +# endif +#endif rand = rand_new_drbg(ctx, primary, SECONDARY_RESEED_INTERVAL, SECONDARY_RESEED_TIME_INTERVAL); +#if defined(__has_feature) +# if __has_feature(address_sanitizer) + __lsan_enable(); +# endif +#endif if (!CRYPTO_THREAD_set_local(&dgbl->public, rand)) { EVP_RAND_CTX_free(rand); rand = NULL; From 737ce357c58a60a11ed8858292a59356e30baa07 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Tue, 11 Jun 2024 20:59:59 +0000 Subject: [PATCH 07/13] Suppress leaky memory warning in OpenSSL's error handling The leak was reported in https://github.com/ClickHouse/ClickHouse/issues/63792 - a SSL session is established - somewhere down in OpenSSL, the per-thread error queue is clear'ed - when no error queue exists (e.g. because the thread was just spawned), a new error queue is allocated - the error queue is stored in TLS, and a free handler is registered which deletes it when the thread ends - Leak sanitizer does not understand ^^ (false positive) ``` Direct leak of 9944 byte(s) in 11 object(s) allocated from: #0 0x5571bf7e04cf in malloc (/usr/bin/clickhouse+0xa39a4cf) (BuildId: 06c4931100f632dde9d0ecd3cf6a67776742e29b) #1 0x5571ecbc06be in CRYPTO_malloc build_docker/./contrib/openssl/crypto/mem.c:202:11 #2 0x5571ecbc06be in CRYPTO_zalloc build_docker/./contrib/openssl/crypto/mem.c:222:11 #3 0x5571ecb03c6a in ossl_err_get_state_int build_docker/./contrib/openssl/crypto/err/err.c:691:17 #4 0x5571ecb037b5 in ERR_clear_error build_docker/./contrib/openssl/crypto/err/err.c:339:10 #5 0x5571ec9cf0d0 in state_machine build_docker/./contrib/openssl/ssl/statem/statem.c:366:5 #6 0x5571ec90c7d4 in SSL_do_handshake build_docker/./contrib/openssl/ssl/ssl_lib.c:4746:19 #7 0x5571e70cc501 in Poco::Net::SecureSocketImpl::connectSSL(bool) build_docker/./base/poco/NetSSL_OpenSSL/src/SecureSocketImpl.cpp:206:11 #8 0x5571e70cce6b in Poco::Net::SecureSocketImpl::connect(Poco::Net::SocketAddress const&, Poco::Timespan const&, bool) build_docker/./base/poco/NetSSL_OpenSSL/src/SecureSocketImpl.cpp:149:2 #9 0x5571e70d81f7 in Poco::Net::SecureStreamSocketImpl::connect(Poco::Net::SocketAddress const&, Poco::Timespan const&) build_docker/./base/poco/NetSSL_OpenSSL/src/SecureStreamSocketImpl.cpp:87:8 #10 0x5571e0ca708a in DB::Connection::connect(DB::ConnectionTimeouts const&) build_docker/./src/Client/Connection.cpp:158:29 ``` (cherry picked from commit 9e7862cea9fde8af56859f38714bba979a1de75d) --- crypto/err/err.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crypto/err/err.c b/crypto/err/err.c index a995c4e2422de..2a0af875b44d2 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -26,6 +26,12 @@ #include "internal/e_os.h" #include "err_local.h" +#if defined(__has_feature) +# if __has_feature(address_sanitizer) +#include +# endif +#endif + /* Forward declaration in case it's not published because of configuration */ ERR_STATE *ERR_get_state(void); @@ -689,7 +695,17 @@ ERR_STATE *ossl_err_get_state_int(void) if (!CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE *)-1)) return NULL; +#if defined(__has_feature) +# if __has_feature(address_sanitizer) + __lsan_disable(); +# endif +#endif state = OSSL_ERR_STATE_new(); +#if defined(__has_feature) +# if __has_feature(address_sanitizer) + __lsan_enable(); +# endif +#endif if (state == NULL) { CRYPTO_THREAD_set_local(&err_thread_local, NULL); return NULL; From b67a86667c968c4248c068d61771ef2d9d441fc8 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Tue, 18 Jun 2024 19:59:52 +0000 Subject: [PATCH 08/13] Suppress leaksan false positive (cherry picked from commit b50f55132d05d51e92a9bcd1e0f7698c831703f0) --- crypto/engine/eng_lib.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c index 04a2602ed2d8c..bc643a1b4e67f 100644 --- a/crypto/engine/eng_lib.c +++ b/crypto/engine/eng_lib.c @@ -12,6 +12,12 @@ #include #include "internal/refcount.h" +#if defined(__has_feature) +# if __has_feature(address_sanitizer) +#include +# endif +#endif + CRYPTO_RWLOCK *global_engine_lock; CRYPTO_ONCE engine_lock_init = CRYPTO_ONCE_STATIC_INIT; @@ -33,8 +39,18 @@ ENGINE *ENGINE_new(void) ERR_raise(ERR_LIB_ENGINE, ERR_R_CRYPTO_LIB); return 0; } +#if defined(__has_feature) +# if __has_feature(address_sanitizer) + __lsan_disable(); +# endif +#endif if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) return NULL; +#if defined(__has_feature) +# if __has_feature(address_sanitizer) + __lsan_enable(); +# endif +#endif if (!CRYPTO_NEW_REF(&ret->struct_ref, 1)) { OPENSSL_free(ret); return NULL; From 5781b0ffd9aea9498fc9c0eedb176321d29bf879 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Sun, 30 Jun 2024 14:35:04 +0000 Subject: [PATCH 09/13] Suppress leaky memory warning, pt. II ClickHouse issue https://github.com/ClickHouse/clickhouse-private/issues/10107#issuecomment-2189755698 reports this memory leak: (note how it is very similar to https://github.com/ClickHouse/clickhouse-private/issues/10107#issue-2314912657) ``` Direct leak of 528 byte(s) in 11 object(s) allocated from: #0 0x561369af24cf in malloc (/usr/bin/clickhouse+0xa6cf4cf) (BuildId: 22880fad595a96b17eb9add20e7a01f8ded54c49) #1 0x561397b86a7e in CRYPTO_malloc build_docker/./contrib/openssl/crypto/mem.c:202:11 #2 0x561397b86a7e in CRYPTO_zalloc build_docker/./contrib/openssl/crypto/mem.c:222:11 #3 0x561397be07cf in EVP_RAND_CTX_new build_docker/./contrib/openssl/crypto/evp/evp_rand.c:353:11 #4 0x561397be35fb in rand_new_drbg build_docker/./contrib/openssl/crypto/rand/rand_lib.c:665:11 #5 0x561397be2a9b in RAND_get0_private build_docker/./contrib/openssl/crypto/rand/rand_lib.c:827:16 #6 0x561397be296f in RAND_priv_bytes_ex build_docker/./contrib/openssl/crypto/rand/rand_lib.c:356:12 #7 0x5613978d7cd8 in SSL_CTX_new_ex build_docker/./contrib/openssl/ssl/ssl_lib.c:4016:13 #8 0x561392d1eabd in ossl_connect_common openssl.c #9 0x561392d11e23 in ssl_cf_connect vtls.c #10 0x561392c13a1f in cf_setup_connect connect.c #11 0x561392c1b0e5 in cf_hc_connect cf-https-connect.c #12 0x561392c0a332 in Curl_conn_connect (/usr/bin/clickhouse+0x337e7332) (BuildId: 22880fad595a96b17eb9add20e7a01f8ded54c49) #13 0x561392c7a28a in multi_runsingle multi.c #14 0x561392c78f6d in curl_multi_perform (/usr/bin/clickhouse+0x33855f6d) (BuildId: 22880fad595a96b17eb9add20e7a01f8ded54c49) #15 0x561392bfd53e in curl_easy_perform (/usr/bin/clickhouse+0x337da53e) (BuildId: 22880fad595a96b17eb9add20e7a01f8ded54c49) #16 0x561392a7c411 in Azure::Core::Http::CurlConnection::CurlConnection(Azure::Core::Http::Request&, Azure::Core::Http::CurlTransportOptions const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::basic_string, std::__1::allocator> const&) build_docker/./contrib/azure/sdk/core/azure-core/src/http/curl/curl.cpp:2441:24 #17 0x561392a6382b in std::__1::__unique_if::__unique_single std::__1::make_unique[abi:v15000], std::__1::allocator> const&, std::__1::basic_string, std::__1::allocator> const&>(Azure::Core::Http::Request&, Azure::Core::Http::CurlTransportOptions const&, std::__1::basic_string, std::__1::allocator> const&, std::__1::basic_string, std::__1::allocator> const&) build_docker/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:714:32 #18 0x561392a6382b in Azure::Core::Http::_detail::CurlConnectionPool::ExtractOrCreateCurlConnection(Azure::Core::Http::Request&, Azure::Core::Http::CurlTransportOptions const&, bool) build_docker/./contrib/azure/sdk/core/azure-core/src/http/curl/curl.cpp:2126:10 #19 0x561392a61951 in Azure::Core::Http::CurlTransport::Send(Azure::Core::Http::Request&, Azure::Core::Context const&) build_docker/./contrib/azure/sdk/core/azure-core/src/http/curl/curl.cpp:351:48 #20 0x561392b0879b in Azure::Core::Http::Policies::_internal::TransportPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_docker/./contrib/azure/sdk/core/azure-core/src/http/transport_policy.cpp:121:40 #21 0x561392aae81b in Azure::Core::Http::Policies::_internal::LogPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_docker/./contrib/azure/sdk/core/azure-core/src/http/log_policy.cpp:114:23 #22 0x561392b022d8 in Azure::Core::Http::Policies::_internal::RequestActivityPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_docker/./contrib/azure/sdk/core/azure-core/src/http/request_activity_policy.cpp:110:23 #23 0x561392b2e02a in Azure::Storage::_internal::SharedKeyPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_docker/./contrib/azure/sdk/storage/azure-storage-common/inc/azure/storage/common/internal/shared_key_policy.hpp:36:25 #24 0x561392bf7fd8 in Azure::Storage::_internal::StoragePerRetryPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_docker/./contrib/azure/sdk/storage/azure-storage-common/src/storage_per_retry_policy.cpp:57:23 #25 0x561392bf8dcb in Azure::Storage::_internal::StorageSwitchToSecondaryPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_docker/./contrib/azure/sdk/storage/azure-storage-common/src/storage_switch_to_secondary_policy.cpp:36:32 #26 0x561392aff0d9 in Azure::Core::Http::Policies::_internal::RetryPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_docker/./contrib/azure/sdk/core/azure-core/src/http/retry_policy.cpp:146:34 #27 0x561392b08ed7 in Azure::Core::Http::Policies::_internal::TelemetryPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_docker/./contrib/azure/sdk/core/azure-core/src/http/telemetry_policy.cpp:23:21 #28 0x561392ae2fb5 in Azure::Core::Http::Policies::_internal::RequestIdPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_docker/./contrib/azure/sdk/core/azure-core/inc/azure/core/http/policies/policy.hpp:453:27 #29 0x561392b2e5fe in Azure::Storage::_internal::StorageServiceVersionPolicy::Send(Azure::Core::Http::Request&, Azure::Core::Http::Policies::NextHttpPolicy, Azure::Core::Context const&) const build_docker/./contrib/azure/sdk/storage/azure-storage-common/inc/azure/storage/common/internal/storage_service_version_policy.hpp:34:25 #30 0x561392b7e0b1 in Azure::Core::Http::_internal::HttpPipeline::Send(Azure::Core::Http::Request&, Azure::Core::Context const&) const build_docker/./contrib/azure/sdk/core/azure-core/inc/azure/core/internal/http/pipeline.hpp:230:29 #31 0x561392b7e0b1 in Azure::Storage::Blobs::_detail::BlobContainerClient::Create(Azure::Core::Http::_internal::HttpPipeline&, Azure::Core::Url const&, Azure::Storage::Blobs::_detail::BlobContainerClient::CreateBlobContainerOptions const&, Azure::Core::Context const&) build_docker/./contrib/azure/sdk/storage/azure-storage-blobs/src/rest_client.cpp:1415:36 #32 0x561392b3de98 in Azure::Storage::Blobs::BlobContainerClient::Create(Azure::Storage::Blobs::CreateBlobContainerOptions const&, Azure::Core::Context const&) const build_docker/./contrib/azure/sdk/storage/azure-storage-blobs/src/blob_container_client.cpp:258:12 ``` - at database startup, Azure is registered as an object storage (--> registerAzureObjectStorage) - this calls into Azure, then into curl, and then into OpenSSL - curl asks OpenSSL for a bunch of random numbers (--> function 'ossl_random' in curl's OpenSSL wrapper) - OpenSSL initializes the random number generator and stores it in some random number generator context object (--> *RAND_get0_private) - this object is registered via pthread_key_create and pthread_setspecific registered in TLS - if registerAzureObjectStorage was the only place which initializes the RNG, we could argue that the leaked memory does not matter anyways as it is released after shutdown - RAND_get0_public also registers a free handler (rand_delete_thread_state) that runs in TLS, so the memory is released also if registration is called from arbitrary other threads. In sum: this is a false positive. As a result, the fix is similar to earlier fix https://github.com/ClickHouse/openssl/commit/5c4b034785bf04f80380138cf49bf9743400f144 (cherry picked from commit 499f1ee900142f6b714dee99280d31df7b2eb4c0) --- crypto/rand/rand_lib.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c index 3f0d6585f46e9..893cadd22bb79 100644 --- a/crypto/rand/rand_lib.c +++ b/crypto/rand/rand_lib.c @@ -916,8 +916,18 @@ static EVP_RAND_CTX *rand_get0_private(OSSL_LIB_CTX *ctx, RAND_GLOBAL *dgbl) if (CRYPTO_THREAD_get_local(&dgbl->public) == NULL && !ossl_init_thread_start(NULL, ctx, rand_delete_thread_state)) return NULL; +#if defined(__has_feature) +# if __has_feature(address_sanitizer) + __lsan_disable(); +# endif +#endif rand = rand_new_drbg(ctx, primary, SECONDARY_RESEED_INTERVAL, SECONDARY_RESEED_TIME_INTERVAL); +#if defined(__has_feature) +# if __has_feature(address_sanitizer) + __lsan_enable(); +# endif +#endif if (!CRYPTO_THREAD_set_local(&dgbl->private, rand)) { EVP_RAND_CTX_free(rand); rand = NULL; From bc7c427151eca667ebd6d55c79546543e48dabd3 Mon Sep 17 00:00:00 2001 From: Konstantin Bogdanov Date: Mon, 30 Jun 2025 08:27:07 +0200 Subject: [PATCH 10/13] Remove submodules (cherry picked from commit 6e1c68f6d03d3607c2ff468f2a59e3200dbabccd) --- pkcs11-provider | 1 - 1 file changed, 1 deletion(-) delete mode 160000 pkcs11-provider diff --git a/pkcs11-provider b/pkcs11-provider deleted file mode 160000 index 64fc325ac0f91..0000000000000 --- a/pkcs11-provider +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 64fc325ac0f91d03d76b3546df2998d3a38c525b From bbe6690dbf06b237161d8b578ee43f4a15bf9f81 Mon Sep 17 00:00:00 2001 From: Konstantin Bogdanov Date: Mon, 27 Oct 2025 10:16:08 +0100 Subject: [PATCH 11/13] Add msan_unpoison around SHA3 assembly calls Related MSan error log: ==2046343==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x556f1dce43f2 in sample_scalar /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/ml_kem/ml_kem.c:449:47 #1 0x556f1dce43f2 in matrix_expand /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/ml_kem/ml_kem.c:999:21 #2 0x556f1dcdec79 in genkey /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/ml_kem/ml_kem.c:1391:10 #3 0x556f1dcde895 in ossl_ml_kem_genkey /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/ml_kem/ml_kem.c:1879:15 #4 0x556f1dd71e1b in ml_kem_gen /home/thevar1able/nvmemount/clickhouse/contrib/openssl/providers/implementations/keymgmt/ml_kem_kmgmt.c:771:13 #5 0x556f1da6add2 in evp_keymgmt_gen /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/evp/keymgmt_meth.c:464:11 #6 0x556f1da68160 in evp_keymgmt_util_gen /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/evp/keymgmt_lib.c:518:20 #7 0x556f1da8f2f4 in EVP_PKEY_generate /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/evp/pmeth_gn.c:189:13 #8 0x556f1da570d4 in evp_pkey_keygen /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/evp/evp_lib.c:1216:15 #9 0x556f1da570d4 in EVP_PKEY_Q_keygen /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/evp/evp_lib.c:1242:11 #10 0x556f1dd763f8 in mlx_kem_gen /home/thevar1able/nvmemount/clickhouse/contrib/openssl/providers/implementations/keymgmt/mlx_kmgmt.c:707:17 #11 0x556f1da6add2 in evp_keymgmt_gen /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/evp/keymgmt_meth.c:464:11 #12 0x556f1da68160 in evp_keymgmt_util_gen /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/evp/keymgmt_lib.c:518:20 #13 0x556f1da8f2f4 in EVP_PKEY_generate /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/evp/pmeth_gn.c:189:13 #14 0x556f1da8f972 in EVP_PKEY_keygen /home/thevar1able/nvmemount/clickhouse/contrib/openssl/crypto/evp/pmeth_gn.c:274:12 #15 0x556f1d8355b3 in ssl_generate_pkey_group /home/thevar1able/nvmemount/clickhouse/contrib/openssl/ssl/s3_lib.c:4935:9 #16 0x556f1d884598 in add_key_share /home/thevar1able/nvmemount/clickhouse/contrib/openssl/ssl/statem/extensions_clnt.c:661:25 #17 0x556f1d88417f in tls_construct_ctos_key_share /home/thevar1able/nvmemount/clickhouse/contrib/openssl/ssl/statem/extensions_clnt.c:766:18 #18 0x556f1d87cdec in tls_construct_extensions /home/thevar1able/nvmemount/clickhouse/contrib/openssl/ssl/statem/extensions.c:910:15 #19 0x556f1d8a777c in tls_construct_client_hello /home/thevar1able/nvmemount/clickhouse/contrib/openssl/ssl/statem/statem_clnt.c:1357:10 #20 0x556f1d8a2465 in write_state_machine /home/thevar1able/nvmemount/clickhouse/contrib/openssl/ssl/statem/statem.c:902:26 #21 0x556f1d8a2465 in state_machine /home/thevar1able/nvmemount/clickhouse/contrib/openssl/ssl/statem/statem.c:492:21 #22 0x556f1d8a1536 in ossl_statem_connect /home/thevar1able/nvmemount/clickhouse/contrib/openssl/ssl/statem/statem.c:301:12 #23 0x556f1d858378 in SSL_do_handshake /home/thevar1able/nvmemount/clickhouse/contrib/openssl/ssl/ssl_lib.c:5007:19 #24 0x556f1d858680 in SSL_connect /home/thevar1able/nvmemount/clickhouse/contrib/openssl/ssl/ssl_lib.c:2243:12 #25 0x556f1ab7f511 in Poco::Net::SecureSocketImpl::connectSSL(bool) /home/thevar1able/nvmemount/clickhouse/base/poco/NetSSL_OpenSSL/src/SecureS ocketImpl.cpp:205:11 #26 0x556f1ab80143 in Poco::Net::SecureSocketImpl::connect(Poco::Net::SocketAddress const&, Poco::Timespan const&, bool) /home/thevar1able/nvme mount/clickhouse/base/poco/NetSSL_OpenSSL/src/SecureSocketImpl.cpp:148:2 #27 0x556f1ab8dd4a in Poco::Net::SecureStreamSocketImpl::connect(Poco::Net::SocketAddress const&, Poco::Timespan const&) /home/thevar1able/nvme mount/clickhouse/base/poco/NetSSL_OpenSSL/src/SecureStreamSocketImpl.cpp:99:8 #28 0x556f1ab3d96d in Poco::Net::StreamSocket::connect(Poco::Net::SocketAddress const&, Poco::Timespan const&) /home/thevar1able/nvmemount/clic khouse/base/poco/Net/src/StreamSocket.cpp:89:10 #29 0x556f1aabfaa7 in Poco::Net::HTTPSession::connect(Poco::Net::SocketAddress const&) /home/thevar1able/nvmemount/clickhouse/base/poco/Net/src /HTTPSession.cpp:239:10 #30 0x556f1ab55f54 in Poco::Net::HTTPSClientSession::connect(Poco::Net::SocketAddress const&) /home/thevar1able/nvmemount/clickhouse/base/poco/ NetSSL_OpenSSL/src/HTTPSClientSession.cpp:182:16 #31 0x556f1aa86972 in Poco::Net::HTTPClientSession::reconnect(unsigned long*) /home/thevar1able/nvmemount/clickhouse/base/poco/Net/src/HTTPClie ntSession.cpp:471:13 #32 0x556ee2448df8 in DB::EndpointConnectionPool::PooledConnection::doConnect(unsigned long*) /home/thevar1able/ nvmemount/clickhouse/src/Common/HTTPConnectionPool.cpp:515:22 #33 0x556ee2448df8 in DB::EndpointConnectionPool::prepareNewConnection(DB::ConnectionTimeouts const&, unsigned l ong*) /home/thevar1able/nvmemount/clickhouse/src/Common/HTTPConnectionPool.cpp:690:25 #34 0x556ee2445eed in DB::EndpointConnectionPool::getConnection(DB::ConnectionTimeouts const&, unsigned long*) / home/thevar1able/nvmemount/clickhouse/src/Common/HTTPConnectionPool.cpp:603:16 #35 0x556ee248e8c9 in DB::makeHTTPSession(DB::HTTPConnectionGroupType, Poco::URI const&, DB::ConnectionTimeouts const&, DB::ProxyConfiguration const&, unsigned long*) /home/thevar1able/nvmemount/clickhouse/src/IO/HTTPCommon.cpp:63:29 #36 0x556ee91f3da5 in DB::ReadWriteBufferFromHTTP::callImpl(Poco::Net::HTTPResponse&, std::__1::basic_string, std::__1::allocator> const&, std::__1::optional const&, bool) const /home/thevar1able/nvmemount/clic khouse/src/IO/ReadWriteBufferFromHTTP.cpp:272:20 #37 0x556ee91f44b9 in DB::ReadWriteBufferFromHTTP::callWithRedirects(Poco::Net::HTTPResponse&, std::__1::basic_string, std::__1::allocator> const&, std::__1::optional const&) /home/thevar1able/nvmemount/clickho use/src/IO/ReadWriteBufferFromHTTP.cpp:290:19 #38 0x556ee91f6182 in DB::ReadWriteBufferFromHTTP::initialize() /home/thevar1able/nvmemount/clickhouse/src/IO/ReadWriteBufferFromHTTP.cpp:413:1 9 (cherry picked from commit 2720d8c08f0853b6388988fc600ca4b6370e4ed9) --- crypto/sha/sha3.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/crypto/sha/sha3.c b/crypto/sha/sha3.c index 21e1070beed27..1cdc8e983e8e8 100644 --- a/crypto/sha/sha3.c +++ b/crypto/sha/sha3.c @@ -13,6 +13,12 @@ #endif #include "internal/sha3.h" +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) +# include +# endif +#endif + void SHA3_squeeze(uint64_t A[5][5], unsigned char *out, size_t len, size_t r, int next); void ossl_sha3_reset(KECCAK1600_CTX *ctx) @@ -122,8 +128,21 @@ int ossl_sha3_final(KECCAK1600_CTX *ctx, unsigned char *out, size_t outlen) (void)SHA3_absorb(ctx->A, ctx->buf, bsz, bsz); +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __msan_unpoison(ctx->buf, bsz); +# endif +#endif + ctx->xof_state = XOF_STATE_FINAL; SHA3_squeeze(ctx->A, out, outlen, bsz, 0); + +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __msan_unpoison(out, outlen); +# endif +#endif + return 1; } @@ -191,6 +210,13 @@ int ossl_sha3_squeeze(KECCAK1600_CTX *ctx, unsigned char *out, size_t outlen) if (outlen >= bsz) { len = bsz * (outlen / bsz); SHA3_squeeze(ctx->A, out, len, bsz, next); + +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __msan_unpoison(out, len); +# endif +#endif + next = 1; out += len; outlen -= len; @@ -198,6 +224,13 @@ int ossl_sha3_squeeze(KECCAK1600_CTX *ctx, unsigned char *out, size_t outlen) if (outlen > 0) { /* Step 3. Squeeze one more block into a buffer */ SHA3_squeeze(ctx->A, ctx->buf, bsz, bsz, next); + +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __msan_unpoison(ctx->buf, bsz); +# endif +#endif + memcpy(out, ctx->buf, outlen); /* Step 4. Remember the leftover part of the squeezed block */ ctx->bufsz = bsz - outlen; From 66764a1148caf82c71371c0524f5a0ace0b942c8 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 15 Feb 2026 17:32:11 +0100 Subject: [PATCH 12/13] Add __msan_unpoison for X25519 assembly output buffers x25519_scalar_mult and related functions may use assembly implementations (x25519-x86_64.s) that MSan cannot instrument. Add __msan_unpoison annotations after assembly writes, following the same pattern used in sha3.c, bn_intern.c, and eng_rdrand.c. (cherry picked from commit f3b2f0273ed59cef874db0d6943f8d7d1804bd31) --- crypto/ec/curve25519.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crypto/ec/curve25519.c b/crypto/ec/curve25519.c index c6886763aba7e..5661d33485832 100644 --- a/crypto/ec/curve25519.c +++ b/crypto/ec/curve25519.c @@ -21,6 +21,12 @@ #include "internal/numbers.h" +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) +# include +# endif +#endif + #if defined(X25519_ASM) && (defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)) #define BASE_2_64_IMPLEMENTED @@ -5846,6 +5852,12 @@ int ossl_x25519(uint8_t out_shared_key[32], const uint8_t private_key[32], { static const uint8_t kZeros[32] = { 0 }; x25519_scalar_mult(out_shared_key, private_key, peer_public_value); +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + /* x25519_scalar_mult may use assembly that MSan cannot instrument. */ + __msan_unpoison(out_shared_key, 32); +# endif +#endif /* The all-zero output results when the input is a point of small order. */ return CRYPTO_memcmp(kZeros, out_shared_key, 32) != 0; } @@ -5875,5 +5887,11 @@ void ossl_x25519_public_from_private(uint8_t out_public_value[32], fe_mul(zplusy, zplusy, zminusy_inv); fe_tobytes(out_public_value, zplusy); +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __msan_unpoison(out_public_value, 32); +# endif +#endif + OPENSSL_cleanse(e, sizeof(e)); } From d1c98c3c7ebad8eccd0199d4f180a8e54a5de5af Mon Sep 17 00:00:00 2001 From: Konstantin Bogdanov Date: Sat, 4 Jul 2026 10:38:24 +0200 Subject: [PATCH 13/13] Use getauxval for ARM CPU feature detection on musl OSSL_IMPLEMENT_GETAUXVAL is only enabled for glibc >= 2.16, Android, FreeBSD and OpenBSD, so on musl OPENSSL_cpuid_setup fell back to the brute-force SIGILL-based probing: install a SIGILL handler, execute each optional instruction, and siglongjmp out of the handler when it traps. That scheme breaks under ThreadSanitizer with static libc interception: the sigaction/sigsetjmp/siglongjmp round-trip through TSan's interceptors during a library constructor leads to a null pointer call inside the probe, an unrecoverable startup failure in every TSan aarch64 musl binary (OPENSSL_cpuid_setup runs as an __attribute__((constructor)) before main). musl has always provided an unversioned getauxval, so take the same HWCAP-based path as glibc. This also removes the last SIGILL-probing user in the binary and keeps CPU detection free of signal-handler tricks. The __MUSL__ macro is defined globally by the ClickHouse musl toolchain files. (cherry picked from commit 26868a38972e80dd15f56212c3677d77363f5c74) --- crypto/armcap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crypto/armcap.c b/crypto/armcap.c index 3005d295cfd0b..415c55cb46fc9 100644 --- a/crypto/armcap.c +++ b/crypto/armcap.c @@ -77,6 +77,10 @@ void OPENSSL_cpuid_setup(void) __attribute__((constructor)); #include #define OSSL_IMPLEMENT_GETAUXVAL #endif +#elif defined(__MUSL__) +/* musl has always provided getauxval(), unversioned. */ +#include +#define OSSL_IMPLEMENT_GETAUXVAL #endif #if defined(__FreeBSD__) || defined(__OpenBSD__) #include