#include <openssl/crypto.h>
#include <openssl/rand.h>
+#include <openssl/async.h>
#include "rand_lcl.h"
#include <openssl/err.h>
*/
CRYPTO_w_lock(CRYPTO_LOCK_RAND);
+ /*
+ * We could end up in an async engine while holding this lock so ensure
+ * we don't pause and cause a deadlock
+ */
+ ASYNC_block_pause();
/* prevent rand_bytes() from trying to obtain the lock again */
CRYPTO_w_lock(CRYPTO_LOCK_RAND2);
/* before unlocking, we must clear 'crypto_lock_rand' */
crypto_lock_rand = 0;
+ ASYNC_unblock_pause();
CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
while (num > 0) {
|| !MD_Update(&m, local_md, MD_DIGEST_LENGTH))
goto err;
CRYPTO_w_lock(CRYPTO_LOCK_RAND);
+ /*
+ * Prevent deadlocks if we end up in an async engine
+ */
+ ASYNC_block_pause();
if (!MD_Update(&m, md, MD_DIGEST_LENGTH) || !MD_Final(&m, md)) {
CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
goto err;
}
+ ASYNC_unblock_pause();
CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
EVP_MD_CTX_cleanup(&m);
if (!do_not_lock) {
CRYPTO_w_lock(CRYPTO_LOCK_RAND);
+ /*
+ * Prevent deadlocks in case we end up in an async engine
+ */
+ ASYNC_block_pause();
/*
* prevent rand_bytes() from trying to obtain the lock again
/* before unlocking, we must clear 'crypto_lock_rand' */
crypto_lock_rand = 0;
+ ASYNC_unblock_pause();
CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
}