]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix another memory order issue
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 15 Sep 2025 19:12:37 +0000 (21:12 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Fri, 19 Sep 2025 05:04:47 +0000 (07:04 +0200)
this adds another release/acquire link between update_qp and
get_hold_current_qp via the reader_idx because the current
one which is based on the qp users count is only preventing
a race condition, but does not help when the reader acquires
the next qp.

Fixes #27267

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28585)

(cherry picked from commit d296f9653345d79ee316c053f63a489f001565a5)

crypto/threads_pthread.c

index 750ef201210b7dd539564dd83ca4836013cc211b..f357c9f71f05e19eda55a4d939bdb1eb8a623142 100644 (file)
@@ -279,7 +279,7 @@ static struct rcu_qp *get_hold_current_qp(struct rcu_lock_st *lock)
 
         /* if the idx hasn't changed, we're good, else try again */
         if (qp_idx == ATOMIC_LOAD_N(uint32_t, &lock->reader_idx,
-                                    __ATOMIC_RELAXED))
+                                    __ATOMIC_ACQUIRE))
             break;
 
         ATOMIC_SUB_FETCH(&lock->qp_group[qp_idx].users, (uint64_t)1,
@@ -403,8 +403,12 @@ static struct rcu_qp *update_qp(CRYPTO_RCU_LOCK *lock, uint32_t *curr_id)
     *curr_id = lock->id_ctr;
     lock->id_ctr++;
 
+    /*
+     * make the current state of everything visible by this release
+     * when get_hold_current_qp acquires the next qp
+     */
     ATOMIC_STORE_N(uint32_t, &lock->reader_idx, lock->current_alloc_idx,
-                   __ATOMIC_RELAXED);
+                   __ATOMIC_RELEASE);
 
     /*
      * this should make sure that the new value of reader_idx is visible in