Enable locking on the primary DRBG when we create it
authorMatt Caswell <matt@openssl.org>
Fri, 8 Jan 2021 13:48:13 +0000 (13:48 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 14 Jan 2021 17:30:46 +0000 (17:30 +0000)
commitf5a50c2a07e288187c14b784be253b3a2a23483b
tree71ab229bb6194a7dde63dcf5fa904f5bef005158
parent2c40421440d260ddb97a807b064033f61ae3b2b3
Enable locking on the primary DRBG when we create it

The primary DRBG may be shared across multiple threads and therefore
we must use locking to access it. Previously we were enabling that locking
lazily when we attempted to obtain one of the child DRBGs. Part of the
process of enabling the lock, is to create the lock. But if we create the
lock lazily then it is too late - we may race with other threads where each
thread is independently attempting to enable the locking. This results
in multiple locks being created - only one of which "sticks" and the rest
are leaked.

Instead we enable locking on the primary when we first create it. This is
already locked and therefore we cannot race.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13660)
crypto/err/openssl.txt
crypto/evp/evp_err.c
crypto/evp/evp_rand.c
crypto/rand/rand_lib.c
doc/man3/EVP_RAND.pod
include/openssl/evperr.h