From bc7bfdeceda27a1abfc32162ec1d25287f0cbe58 Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Mon, 3 Mar 2025 23:46:12 +0100 Subject: [PATCH] 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) --- crypto/threads_pthread.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c index 9e3b83e17d3..90c4955d01f 100644 --- a/crypto/threads_pthread.c +++ b/crypto/threads_pthread.c @@ -385,6 +385,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); -- 2.47.2