diff options
author | Andy Polyakov <appro@openssl.org> | 2018-07-29 14:37:17 +0200 |
---|---|---|
committer | Andy Polyakov <appro@openssl.org> | 2018-08-07 09:08:31 +0200 |
commit | f21b5b64cbbc279ef31389e6ae312690575187da (patch) | |
tree | 3d25267bcbd694d0b1777119491a762996417cba /crypto/x509v3 | |
parent | x509v3/v3_purp.c: resolve Thread Sanitizer nit. (diff) | |
download | openssl-f21b5b64cbbc279ef31389e6ae312690575187da.tar.xz openssl-f21b5b64cbbc279ef31389e6ae312690575187da.zip |
x509v3/v3_purp.c: re-implement lock-free check for extensions cache validity.
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6786)
Diffstat (limited to 'crypto/x509v3')
-rw-r--r-- | crypto/x509v3/v3_purp.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/crypto/x509v3/v3_purp.c b/crypto/x509v3/v3_purp.c index d804106788..5a535e2ade 100644 --- a/crypto/x509v3/v3_purp.c +++ b/crypto/x509v3/v3_purp.c @@ -13,6 +13,7 @@ #include <openssl/x509v3.h> #include <openssl/x509_vfy.h> #include "internal/x509_int.h" +#include "internal/tsan_assist.h" static void x509v3_cache_extensions(X509 *x); @@ -353,6 +354,10 @@ static void x509v3_cache_extensions(X509 *x) X509_EXTENSION *ex; int i; + /* fast lock-free check, see end of the function for details. */ + if (tsan_load((TSAN_QUALIFIER int *)&x->ex_cached)) + return; + CRYPTO_THREAD_write_lock(x->lock); if (x->ex_flags & EXFLAG_SET) { CRYPTO_THREAD_unlock(x->lock); @@ -494,6 +499,12 @@ static void x509v3_cache_extensions(X509 *x) x509_init_sig_info(x); x->ex_flags |= EXFLAG_SET; CRYPTO_THREAD_unlock(x->lock); + /* + * It has to be placed after memory barrier, which is implied by unlock. + * Worst thing that can happen is that another thread proceeds to lock + * and checks x->ex_flags & EXFLAGS_SET. See beginning of the function. + */ + tsan_store((TSAN_QUALIFIER int *)&x->ex_cached, 1); } /*- |