Skip to content

lib-ssl-iostream: Don't call OPENSSL_cleanup() for openssl 4.0#295

Open
hector-cao wants to merge 1 commit into
dovecot:mainfrom
hector-cao:fix-openssl-4-cleanup
Open

lib-ssl-iostream: Don't call OPENSSL_cleanup() for openssl 4.0#295
hector-cao wants to merge 1 commit into
dovecot:mainfrom
hector-cao:fix-openssl-4-cleanup

Conversation

@hector-cao

Copy link
Copy Markdown

With OpenSSL 4.0 the lib-dcrypt unit tests (test-crypto, test-stream) segfault at process exit.

dovecot_openssl_common_global_ref() installs custom OpenSSL memory functions via CRYPTO_set_mem_functions(); their code lives inside the dynamically loaded OpenSSL/dcrypt module. It also passes OPENSSL_INIT_NO_ATEXIT so that libcrypto does not register its own atexit(OPENSSL_cleanup) handler.

dovecot_openssl_common_global_unref() then called OPENSSL_cleanup() explicitly. On OpenSSL 4.0 this explicit cleanup re-arms an internal exit-time cleanup that runs after main() returns [1], i.e. after the module (and therefore the custom memory functions) has been dlclose()d, so libcrypto calls the now-unmapped free() function and the process crashes with SIGSEGV.

[1] https://openssl-library.org/post/2026-03-10-remove-atexit/index.html

With OpenSSL 4.0 the lib-dcrypt unit tests (test-crypto, test-stream)
segfault at process exit.

dovecot_openssl_common_global_ref() installs custom OpenSSL memory
functions via CRYPTO_set_mem_functions(); their code lives inside the
dynamically loaded OpenSSL/dcrypt module. It also passes
OPENSSL_INIT_NO_ATEXIT so that libcrypto does not register its own
atexit(OPENSSL_cleanup) handler.

dovecot_openssl_common_global_unref() then called OPENSSL_cleanup()
explicitly. On OpenSSL 4.0 this explicit cleanup re-arms an internal
exit-time cleanup that runs after main() returns [1], i.e. after the module
(and therefore the custom memory functions) has been dlclose()d, so
libcrypto calls the now-unmapped free() function and the process crashes
with SIGSEGV.

[1] https://openssl-library.org/post/2026-03-10-remove-atexit/index.html

Signed-off-by: Hector Cao <hector.cao@canonical.com>
@cmouse

cmouse commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Thanks, we'll take a look.

@cmouse

cmouse commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Hi, your explanation sounds bit counter to the blog post you pointed out, which says that atexit handler is not registered ever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants