Commit 76ef06e526 for openssl.org
commit 76ef06e5266f79d46b273ad8146cafeee22bd86b
Author: Mounir IDRASSI <mounir.idrassi@idrix.fr>
Date: Sun Aug 2 14:41:30 2026 +0900
doc: document thread cancellation and non-local exits
Document that OpenSSL provides no general guarantee that an
in-progress call can be abandoned safely through thread cancellation,
forced termination, or another non-local exit.
Explain indirect cancellation points, the limits of thread-local
cleanup, POSIX cancellation masking, and cooperative cancellation.
Clarify in OPENSSL_init_crypto(3) that automatic thread cleanup does
not unwind an interrupted call.
Assisted-by: Codex:gpt-5.6-sol
Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
Reviewed-by: Andrew Dinh <andrewd@openssl.org>
Merge-date: Wed Aug 19 10:28:49 2026
Merged-from: https://github.com/openssl/openssl/pull/32139
diff --git a/doc/man3/OPENSSL_init_crypto.pod b/doc/man3/OPENSSL_init_crypto.pod
index ae7e89ec25..93acb5cd1e 100644
--- a/doc/man3/OPENSSL_init_crypto.pod
+++ b/doc/man3/OPENSSL_init_crypto.pod
@@ -224,6 +224,9 @@ with those threads. The application should either call OPENSSL_thread_stop() on
each thread prior to the dlclose() call, or alternatively the original dlopen()
call should use the RTLD_NODELETE flag (where available on the platform).
+Thread cleanup does not unwind an OpenSSL function interrupted by cancellation
+or thread exit; see L<openssl-threads(7)>.
+
=head1 RETURN VALUES
The functions OPENSSL_init_crypto, and
@@ -231,7 +234,7 @@ OPENSSL_INIT_set_config_appname() return 1 on success or 0 on error.
=head1 SEE ALSO
-L<OPENSSL_init_ssl(3)>
+L<OPENSSL_init_ssl(3)>, L<openssl-threads(7)>
=head1 HISTORY
diff --git a/doc/man7/openssl-threads.pod b/doc/man7/openssl-threads.pod
index bf2b2fb553..9f7e6e9da6 100644
--- a/doc/man7/openssl-threads.pod
+++ b/doc/man7/openssl-threads.pod
@@ -92,9 +92,35 @@ are using the same B<SSL> object concurrently.
Each thread handling TLS connections in parallel should create its own
B<SSL> object from the shared B<SSL_CTX>.
+=head1 THREAD CANCELLATION
+
+Thread safety does not imply cancellation safety.
+Unless a specific function documents otherwise, OpenSSL does not guarantee
+that an in-progress call can be abandoned safely by thread cancellation or
+forced termination. An interruption can leave locks held, resources unreleased,
+or shared state inconsistent, making later use or cleanup unsafe.
+
+Deferred cancellation can take effect at a cancellation point reached directly
+or through a callback, BIO, provider, or other pluggable implementation.
+Automatic thread-local cleanup and L<OPENSSL_thread_stop(3)>, when they run, do
+not unwind the interrupted call.
+
+Applications should act on cancellation only between OpenSSL calls. On POSIX
+systems, applications using pthread cancellation should disable cancellation
+with B<pthread_setcancelstate>() before entering OpenSSL and restore it only
+after OpenSSL returns at a point safe for cancellation. Callbacks invoked by
+OpenSSL must not re-enable it. Disabling cancellation does not make a blocking
+call return on a cancellation request; applications requiring prompt
+cancellation should use nonblocking operation where available.
+
+The same restriction applies to other non-local exits which abandon an OpenSSL
+call in progress, including direct thread exit, long jumps, and language
+exceptions.
+
=head1 SEE ALSO
-CRYPTO_THREAD_run_once(3),
+L<CRYPTO_THREAD_run_once(3)>, L<OPENSSL_thread_stop(3)>,
+L<openssl-quic-concurrency(7)>,
local system threads documentation.
=head1 BUGS
@@ -103,7 +129,7 @@ This page is admittedly very incomplete.
=head1 COPYRIGHT
-Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
+Copyright 2021-2026 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use
this file except in compliance with the License. You can obtain a copy