Skip to content

[v26.1.x] CORE-15653 crypto/ossl: prevent openssl.cnf loading - #30141

Merged
pgellert merged 3 commits into
redpanda-data:v26.1.xfrom
vbotbuildovich:backport-pr-29763-v26.1.x-693
Apr 13, 2026
Merged

[v26.1.x] CORE-15653 crypto/ossl: prevent openssl.cnf loading#30141
pgellert merged 3 commits into
redpanda-data:v26.1.xfrom
vbotbuildovich:backport-pr-29763-v26.1.x-693

Conversation

@vbotbuildovich

Copy link
Copy Markdown
Collaborator

Backport of PR #29763

To avoid indirectly calling `OPENSSL_init_crypto` during static
initialization and loading the openssl.cnf file.

(cherry picked from commit ac5996e)
Prevent the default OpenSSL config from being loaded (OPENSSL_CONF
env var or /etc/ssl/openssl.cnf file) as we want to control the
initialization of OpenSSL and avoid any incompatibilities between the
OS-provided openssl.cnf and our statically linked OpenSSL version.

OpenSSL uses internal RUN_ONCE guards for initialization flags. The
NO_* flags are sticky: once NO_LOAD_CONFIG wins, subsequent calls
with LOAD_CONFIG are silently ignored. This is also why we can remove
OPENSSL_INIT_NO_LOAD_CONFIG from OPENSSL_init_ssl — it is a flag for
OPENSSL_init_crypto and has no effect once already set.

Since NO_LOAD_CONFIG opts out of automatic config loading, the
internal call to OPENSSL_load_builtin_modules that would normally
happen during OPENSSL_config is skipped. Per the
OPENSSL_load_builtin_modules(3) docs, applications that use
configuration functions directly must call this before any other
configuration code, so we call it explicitly early in start().

This must happen while the thread-local default context is still the
global default: the CONF module list is protected by a global RCU
lock (conf_mod.c) that is initialized exactly once via pthread_once.
That initialization resolves a NULL OSSL_LIB_CTX* to the current
thread-local default and permanently stores the pointer in the lock.
Without this early call, the first OSSL_LIB_CTX_load_config (on the
thread worker) would trigger the initialization after a custom
context had been set as the thread-local default, causing the lock to
capture a pointer to that context. Freeing the context later (e.g.
between test runs) leaves the lock with a dangling pointer, resulting
in a use-after-free on subsequent config loads.

We also add a regression test that failed before this change.

Ref:
- https://docs.openssl.org/3.5/man3/OPENSSL_init_ssl/#description
- https://docs.openssl.org/3.5/man3/OPENSSL_init_crypto/#description
- https://docs.openssl.org/3.5/man3/OPENSSL_load_builtin_modules/#description

(cherry picked from commit d9cbab9)
Cluster config validation uses OpenSSL functions for validating that the
configured tls ciphers are valid.

To ensure that openssl is correctly initialized, we need to move openssl
initialization to before cluster config validation.

Before:
load node configs -> load cluster configs (triggers cipher validation) -> ... init openssl

After:
load node configs -> init openssl -> load cluster configs

(cherry picked from commit c7fffc8)
@vbotbuildovich
vbotbuildovich requested a review from a team as a code owner April 13, 2026 13:25
@vbotbuildovich vbotbuildovich added this to the v26.1.x-next milestone Apr 13, 2026
@vbotbuildovich vbotbuildovich added the kind/backport PRs targeting a stable branch label Apr 13, 2026
@vbotbuildovich
vbotbuildovich requested review from pgellert and removed request for a team April 13, 2026 13:25
@pgellert pgellert self-assigned this Apr 13, 2026
@pgellert
pgellert enabled auto-merge April 13, 2026 13:27
@pgellert
pgellert merged commit 5cdd00f into redpanda-data:v26.1.x Apr 13, 2026
21 checks passed
@tyson-redpanda tyson-redpanda modified the milestones: v26.1.x-next, v26.1.5 Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/redpanda kind/backport PRs targeting a stable branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants