Skip to content
This repository was archived by the owner on Aug 24, 2025. It is now read-only.

Commit 9553d96

Browse files
author
Andy Polyakov
committed
x509v3/v3_purp.c: re-implement lock-free check for extensions cache validity.
Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from openssl#6891) (back-ported from commit f21b5b6)
1 parent 80158ae commit 9553d96

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

crypto/include/internal/x509_int.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ struct x509_st {
166166
unsigned char sha1_hash[SHA_DIGEST_LENGTH];
167167
X509_CERT_AUX *aux;
168168
CRYPTO_RWLOCK *lock;
169+
volatile int ex_cached;
169170
} /* X509 */ ;
170171

171172
/*

crypto/x509v3/v3_purp.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ static void x509v3_cache_extensions(X509 *x)
352352
X509_EXTENSION *ex;
353353
int i;
354354

355+
/* fast lock-free check, see end of the function for details. */
356+
if (x->ex_cached)
357+
return;
358+
355359
CRYPTO_THREAD_write_lock(x->lock);
356360
if (x->ex_flags & EXFLAG_SET) {
357361
CRYPTO_THREAD_unlock(x->lock);
@@ -492,6 +496,12 @@ static void x509v3_cache_extensions(X509 *x)
492496
}
493497
x->ex_flags |= EXFLAG_SET;
494498
CRYPTO_THREAD_unlock(x->lock);
499+
/*
500+
* It has to be placed after memory barrier, which is implied by unlock.
501+
* Worst thing that can happen is that another thread proceeds to lock
502+
* and checks x->ex_flags & EXFLAGS_SET. See beginning of the function.
503+
*/
504+
x->ex_cached = 1;
495505
}
496506

497507
/*-

0 commit comments

Comments
 (0)