In dict_entry_unref(), the write lock on d->rwlock was only acquired after
decrementing the refcount. However, between the decrement and the lock,
another thread could increment it by calling dict_insert(). That could lead
to a UAF.
To fix the issue, the call to HA_ATOMIC_SUB_FETCH is moved inside the write
lock.
This patch must be backported to all stable versions.
if (!de)
return;
- if (HA_ATOMIC_SUB_FETCH(&de->refcount, 1) != 0)
- return;
-
HA_RWLOCK_WRLOCK(DICT_LOCK, &d->rwlock);
+ if (HA_ATOMIC_SUB_FETCH(&de->refcount, 1) != 0) {
+ HA_RWLOCK_WRUNLOCK(DICT_LOCK, &d->rwlock);
+ return;
+ }
ebpt_delete(&de->value);
HA_RWLOCK_WRUNLOCK(DICT_LOCK, &d->rwlock);