openssl/util
Benjamin Kaduk 63ab5ea13b Revert the crypto "global lock" implementation
Conceptually, this is a squashed version of:

    Revert "Address feedback"

    This reverts commit 75551e07bd.

and

    Revert "Add CRYPTO_thread_glock_new"

    This reverts commit ed6b2c7938.

But there were some intervening commits that made neither revert apply
cleanly, so instead do it all as one shot.

The crypto global locks were an attempt to cope with the awkward
POSIX semantics for pthread_atfork(); its documentation (the "RATIONALE"
section) indicates that the expected usage is to have the prefork handler
lock all "global" locks, and the parent and child handlers release those
locks, to ensure that forking happens with a consistent (lock) state.
However, the set of functions available in the child process is limited
to async-signal-safe functions, and pthread_mutex_unlock() is not on
the list of async-signal-safe functions!  The only synchronization
primitives that are async-signal-safe are the semaphore primitives,
which are not really appropriate for general-purpose usage.

However, the state consistency problem that the global locks were
attempting to solve is not actually a serious problem, particularly for
OpenSSL.  That is, we can consider four cases of forking application
that might use OpenSSL:

(1) Single-threaded, does not call into OpenSSL in the child (e.g.,
the child calls exec() immediately)

For this class of process, no locking is needed at all, since there is
only ever a single thread of execution and the only reentrancy is due to
signal handlers (which are themselves limited to async-signal-safe
operation and should not be doing much work at all).

(2) Single-threaded, calls into OpenSSL after fork()

The application must ensure that it does not fork() with an unexpected
lock held (that is, one that would get unlocked in the parent but
accidentally remain locked in the child and cause deadlock).  Since
OpenSSL does not expose any of its internal locks to the application
and the application is single-threaded, the OpenSSL internal locks
will be unlocked for the fork(), and the state will be consistent.
(OpenSSL will need to reseed its PRNG in the child, but that is
an orthogonal issue.)  If the application makes use of locks from
libcrypto, proper handling for those locks is the responsibility of
the application, as for any other locking primitive that is available
for application programming.

(3) Multi-threaded, does not call into OpenSSL after fork()

As for (1), the OpenSSL state is only relevant in the parent, so
no particular fork()-related handling is needed.  The internal locks
are relevant, but there is no interaction with the child to consider.

(4) Multi-threaded, calls into OpenSSL after fork()

This is the case where the pthread_atfork() hooks to ensure that all
global locks are in a known state across fork() would come into play,
per the above discussion.  However, these "calls into OpenSSL after
fork()" are still subject to the restriction to async-signal-safe
functions.  Since OpenSSL uses all sorts of locking and libc functions
that are not on the list of safe functions (e.g., malloc()), this
case is not currently usable and is unlikely to ever be usable,
independently of the locking situation.  So, there is no need to
go through contortions to attempt to support this case in the one small
area of locking interaction with fork().

In light of the above analysis (thanks @davidben and @achernya), go
back to the simpler implementation that does not need to distinguish
"library-global" locks or to have complicated atfork handling for locks.

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/5089)
2018-01-31 12:25:28 -06:00
..
perl Add TLSProxy tests for signature_algorithms_cert 2018-01-25 12:57:22 -06:00
build.info VMS: throw away [.util]shareable_image_wrap.c.in and add replacement scripts 2017-03-14 22:27:17 +01:00
ck_errf.pl Perltidy ck_errf 2017-05-03 14:16:58 -04:00
copy.pl util/copy.pl: work around glob quirk in some of earlier 5.1x Perl versions. 2017-11-10 09:39:29 +01:00
dofile.pl Many spelling fixes/typo's corrected. 2017-11-11 19:03:10 -05:00
find-doc-nits Copyright update of more files that have changed this year 2018-01-19 13:34:03 +01:00
find-unused-errs Add -f -r flags to find-unused-errs 2017-04-16 07:57:12 -04:00
indent.pro Fix invalid function type casts. 2017-12-15 19:33:48 +01:00
libcrypto.num Revert the crypto "global lock" implementation 2018-01-31 12:25:28 -06:00
libssl.num Add the SSL_stateless() function 2018-01-24 18:02:36 +00:00
local_shlib.com.in VMS: don't use /DSF, turn off CALL_DEBUG instead 2017-03-15 03:09:57 +01:00
mkbuildinf.pl Fix SOURCE_DATE_EPOCH bug; use UTC 2017-11-27 14:34:14 -05:00
mkdef.pl Update copyright years on all files merged since Jan 1st 2018 2018-01-09 05:49:01 +01:00
mkdir-p.pl utils/mkdir-p: check if dir exists also after mkdir failed 2016-06-23 11:10:29 -04:00
mkerr.pl Update copyright year in mkerr.pl 2018-01-28 12:01:04 +01:00
mkrc.pl Fix curly braces on util/mkrc.pl 2017-05-03 14:16:58 -04:00
openssl-format-source Fix some Typos and indents 2017-08-11 10:16:33 -04:00
openssl-update-copyright Enhance util/openssl-update-copyright shell script 2018-01-10 18:23:28 +01:00
opensslwrap.sh opensslwrap.sh to respect $OPENSSL_ENGINES. 2006-12-29 15:00:36 +00:00
private.num Add accessors for AdmissionSyntax 2018-01-22 11:29:52 -05:00
process_docs.pl Additional name for all commands 2017-10-18 15:33:56 -04:00
shlib_wrap.sh.in Remove automatic RPATH - adapt shlib_wrap.sh 2016-10-13 02:21:51 +02:00
su-filter.pl Remove trailing whitespace from some files. 2016-10-10 23:36:21 +01:00
unlocal_shlib.com.in VMS: don't use /DSF, turn off CALL_DEBUG instead 2017-03-15 03:09:57 +01:00