Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c8f8bf7
Remove submodules
rschu1ze Sep 6, 2024
7d3e482
Msan fixes
rschu1ze Jan 26, 2024
dbd8308
Remove dependency on "getrandom" function
rschu1ze Jan 25, 2024
c7aee19
Remove dependency on glibc 2.14 sendmmsg/recvmmsg
rschu1ze Mar 11, 2024
673dfb1
Suppress tsan failures: use locks instead of atomics
rschu1ze Mar 20, 2024
5ebf903
Suppress leaky memory warning
rschu1ze Jun 11, 2024
47cfd6a
Suppress leaky memory warning in OpenSSL's error handling
rschu1ze Jun 11, 2024
cb65872
Suppress leaksan false positive
rschu1ze Jun 18, 2024
ffe8be8
Suppress leaky memory warning, pt. II
rschu1ze Jun 30, 2024
19ca75b
Remove submodules
Jun 30, 2025
577c394
Add msan_unpoison around SHA3 assembly calls
Oct 27, 2025
22e83c0
Add __msan_unpoison for X25519 assembly output buffers
alexey-milovidov Feb 15, 2026
9321dc5
Use getauxval for ARM CPU feature detection on musl
thevar1able Jul 4, 2026
ae68e3a
Call stack and sparse array callbacks through typed thunks
Algunenano Nov 12, 2026
a88c02c
Call digest update functions with the dispatch table type
Algunenano Nov 12, 2026
337e0ec
Exempt the Poly1305 assembly calls from cfi-icall
Algunenano Nov 12, 2026
6e7be15
Sort stacks through the comparison thunk
Algunenano Nov 17, 2026
ae74915
Build the stack test without the allocation failure framework
Algunenano Nov 17, 2026
15fe39d
Sort typed stacks with a merge sort through the thunk
Algunenano Nov 17, 2026
3a617a6
Install the stack thunks only in Clang CFI builds
Algunenano Nov 17, 2026
c2ddefa
Match the `const` of `X509V3_EXT_V2I` in the alternative name methods
Algunenano Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion cloudflare-quiche
Submodule cloudflare-quiche deleted from 7ab6a5
4 changes: 4 additions & 0 deletions crypto/armcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ void OPENSSL_cpuid_setup(void) __attribute__((constructor));
#include <sys/auxv.h>
#define OSSL_IMPLEMENT_GETAUXVAL
#endif
#elif defined(__MUSL__)
/* musl has always provided getauxval(), unversioned. */
#include <sys/auxv.h>
#define OSSL_IMPLEMENT_GETAUXVAL
#endif
#if defined(__FreeBSD__) || defined(__OpenBSD__)
#include <sys/param.h>
Expand Down
6 changes: 4 additions & 2 deletions crypto/bio/bss_dgram.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@
#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
* not sendmmsg. We need both so force this to be disabled on these old
* versions
*/
#define NO_RECVMMSG
#endif
/// #endif
#endif
#if defined(__GNU__)
/* GNU/Hurd does not have IP_PKTINFO yet */
Expand Down
10 changes: 10 additions & 0 deletions crypto/bn/bn_intern.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#include "bn_local.h"
#include "internal/constant_time.h"

#if defined(__has_feature)
# if __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h>
# 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
Expand Down Expand Up @@ -226,6 +231,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);
Expand Down
17 changes: 15 additions & 2 deletions crypto/bsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include <limits.h>
#include "internal/cryptlib.h"

typedef int (*cmpthunk_fn)(const void *, const void *);
const void *ossl_bsearch(const void *key, const void *base, int num,
int size, int (*cmp)(const void *, const void *),
int (*cmp_thunk)(cmpthunk_fn real_cmp_fn, const void *, const void *),
int flags)
{
const char *base_ = base;
Expand All @@ -26,7 +28,10 @@ const void *ossl_bsearch(const void *key, const void *base, int num,
while (l < h) {
i = l + (h - l) / 2;
p = &(base_[i * size]);
c = (*cmp)(key, p);
if (cmp_thunk != NULL)
c = cmp_thunk((cmpthunk_fn)cmp, key, (const void *)p);
else
c = cmp(key, p);
if (c < 0)
h = i;
else if (c > 0)
Expand All @@ -37,8 +42,16 @@ const void *ossl_bsearch(const void *key, const void *base, int num,
if (c != 0 && !(flags & OSSL_BSEARCH_VALUE_ON_NOMATCH))
p = NULL;
else if (c == 0 && (flags & OSSL_BSEARCH_FIRST_VALUE_ON_MATCH)) {
while (i > 0 && (*cmp)(key, &(base_[(i - 1) * size])) == 0)
while (i > 0) {
if (cmp_thunk != NULL) {
if (cmp_thunk((cmpthunk_fn)cmp, key, (const void *)&(base_[(i - 1) * size])))
break;
} else {
if (cmp(key, &(base_[(i - 1) * size])))
break;
}
i--;
}
p = &(base_[i * size]);
}
return p;
Expand Down
9 changes: 9 additions & 0 deletions crypto/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CPU setup trigger skipped on GCC

Low Severity

trigger = 1 is compiled only when __has_feature exists and MemorySanitizer is off. Compilers without __has_feature (notably GCC) never set trigger, so OPENSSL_cpuid_setup runs again from both the .init snippet and ossl_init_base instead of returning early. The MSan workaround was meant to skip the store only under MSan, not on every non-Clang toolchain.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c2ddefa. Configure here.

if ((env = ossl_getenv("OPENSSL_ia32cap")) != NULL) {
int off = (env[0] == '~') ? 1 : 0;

Expand Down
18 changes: 18 additions & 0 deletions crypto/ec/curve25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@

#include "internal/numbers.h"

#if defined(__has_feature)
# if __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h>
# endif
#endif

#if defined(X25519_ASM) && (defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64))

#define BASE_2_64_IMPLEMENTED
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
}
16 changes: 16 additions & 0 deletions crypto/engine/eng_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#include <openssl/rand.h>
#include "internal/refcount.h"

#if defined(__has_feature)
# if __has_feature(address_sanitizer)
#include <sanitizer/lsan_interface.h>
# endif
#endif

CRYPTO_RWLOCK *global_engine_lock;

CRYPTO_ONCE engine_lock_init = CRYPTO_ONCE_STATIC_INIT;
Expand All @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LSAN left disabled after allocation failure

Low Severity

__lsan_disable() wraps the ENGINE allocation, but a failed OPENSSL_zalloc returns before __lsan_enable(). Leak checking then stays off for that thread, and a later successful ENGINE_new only does disable/enable around an already-elevated counter, so LSAN never recovers. The same suppressions in error-state and DRBG setup re-enable before the NULL check.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c2ddefa. Configure here.

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;
Expand Down
16 changes: 16 additions & 0 deletions crypto/err/err.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
#include "internal/e_os.h"
#include "err_local.h"

#if defined(__has_feature)
# if __has_feature(address_sanitizer)
#include <sanitizer/lsan_interface.h>
# endif
#endif

/* Forward declaration in case it's not published because of configuration */
ERR_STATE *ERR_get_state(void);

Expand Down Expand Up @@ -693,7 +699,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;
Expand Down
2 changes: 1 addition & 1 deletion crypto/objects/obj_dat.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ const void *OBJ_bsearch_ex_(const void *key, const void *base, int num,
int (*cmp)(const void *, const void *),
int flags)
{
const char *p = ossl_bsearch(key, base, num, size, cmp, flags);
const char *p = ossl_bsearch(key, base, num, size, cmp, NULL, flags);

#ifdef CHARSET_EBCDIC
/*
Expand Down
15 changes: 13 additions & 2 deletions crypto/poly1305/poly1305.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,20 @@ void Poly1305_Init(POLY1305 *ctx, const unsigned char key[32])
*/
#define poly1305_blocks (*poly1305_blocks_p)
#define poly1305_emit (*poly1305_emit_p)
/*
* The assembly `poly1305_init` stores raw addresses of assembly routines in
* `ctx->func`: they have no Clang CFI type, so these calls cannot be checked.
*/
#if defined(__clang__)
#define POLY1305_NO_CFI_ICALL __attribute__((no_sanitize("cfi-icall")))
#else
#define POLY1305_NO_CFI_ICALL
#endif
#else
#define POLY1305_NO_CFI_ICALL
#endif

void Poly1305_Update(POLY1305 *ctx, const unsigned char *inp, size_t len)
POLY1305_NO_CFI_ICALL void Poly1305_Update(POLY1305 *ctx, const unsigned char *inp, size_t len)
{
#ifdef POLY1305_ASM
/*
Expand Down Expand Up @@ -477,7 +488,7 @@ void Poly1305_Update(POLY1305 *ctx, const unsigned char *inp, size_t len)
ctx->num = rem;
}

void Poly1305_Final(POLY1305 *ctx, unsigned char mac[16])
POLY1305_NO_CFI_ICALL void Poly1305_Final(POLY1305 *ctx, unsigned char mac[16])
{
#ifdef POLY1305_ASM
poly1305_blocks_f poly1305_blocks_p = ctx->func.blocks;
Expand Down
2 changes: 1 addition & 1 deletion crypto/property/property_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ossl_property_find_property(const OSSL_PROPERTY_LIST *list,
return NULL;

return ossl_bsearch(&name_idx, list->properties, list->num_properties,
sizeof(*list->properties), &property_idx_cmp, 0);
sizeof(*list->properties), &property_idx_cmp, NULL, 0);
}

OSSL_PROPERTY_TYPE ossl_property_get_type(const OSSL_PROPERTY_DEFINITION *prop)
Expand Down
27 changes: 27 additions & 0 deletions crypto/rand/rand_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sanitizer/lsan_interface.h>
# endif
#endif

#ifndef FIPS_MODULE
#include <stdio.h>
#include <time.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -899,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;
Expand Down
Loading