mirror of
https://github.com/QuasarApp/openssl.git
synced 2025-05-01 20:19:39 +00:00
Remove locking in CRYPTO_secure_allocated()
The check for being in secure memory is against the arena. The arena is only ever modified by sh_init() and sh_done() and in both cases, it is done without locking. Thus, it is safe for the CRYPTO_secure_allocated() to not lock. Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14775)
This commit is contained in:
parent
0bc27f7203
commit
44e82b813f
@ -208,15 +208,14 @@ void CRYPTO_secure_clear_free(void *ptr, size_t num,
|
|||||||
int CRYPTO_secure_allocated(const void *ptr)
|
int CRYPTO_secure_allocated(const void *ptr)
|
||||||
{
|
{
|
||||||
#ifndef OPENSSL_NO_SECURE_MEMORY
|
#ifndef OPENSSL_NO_SECURE_MEMORY
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!secure_mem_initialized)
|
if (!secure_mem_initialized)
|
||||||
return 0;
|
return 0;
|
||||||
if (!CRYPTO_THREAD_read_lock(sec_malloc_lock))
|
/*
|
||||||
return 0;
|
* Only read accesses to the arena take place in sh_allocated() and this
|
||||||
ret = sh_allocated(ptr);
|
* is only changed by the sh_init() and sh_done() calls which are not
|
||||||
CRYPTO_THREAD_unlock(sec_malloc_lock);
|
* locked. Hence, it is safe to make this check without a lock too.
|
||||||
return ret;
|
*/
|
||||||
|
return sh_allocated(ptr);
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif /* OPENSSL_NO_SECURE_MEMORY */
|
#endif /* OPENSSL_NO_SECURE_MEMORY */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user