From: Bernd Edlinger Date: Mon, 3 Mar 2025 22:46:12 +0000 (+0100) Subject: Fix a memory order issue with weakly ordered systems X-Git-Tag: openssl-3.4.2~149 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9cb6508f29157a5e33179a963e81c7b2fa803f42;p=thirdparty%2Fopenssl.git Fix a memory order issue with weakly ordered systems this adds a dummy atomic release operation to update_qp, which should make sure that the new value of reader_idx is visible in get_hold_current_qp, directly after incrementing the users count. Fixes: #26875 Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/26964) (cherry picked from commit 4a1a7fe5ce088964010779e1f5a90560903ecc76) --- diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c index c0598c5a616..f69b3d6f456 100644 --- a/crypto/threads_pthread.c +++ b/crypto/threads_pthread.c @@ -407,6 +407,13 @@ static struct rcu_qp *update_qp(CRYPTO_RCU_LOCK *lock, uint32_t *curr_id) ATOMIC_STORE_N(uint32_t, &lock->reader_idx, lock->current_alloc_idx, __ATOMIC_RELAXED); + /* + * this should make sure that the new value of reader_idx is visible in + * get_hold_current_qp, directly after incrementing the users count + */ + ATOMIC_ADD_FETCH(&lock->qp_group[current_idx].users, (uint64_t)0, + __ATOMIC_RELEASE); + /* wake up any waiters */ pthread_cond_signal(&lock->alloc_signal); pthread_mutex_unlock(&lock->alloc_lock);