Fix another memory order issue

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 d296f96533)
This commit is contained in:
Bernd Edlinger 2025-09-15 21:12:37 +02:00
parent e800c459ee
commit eec456fc7b
1 changed files with 6 additions and 2 deletions

View File

@ -257,7 +257,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,
@ -381,8 +381,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