Skip to content

Commit 28134a5

Browse files
herbertxdavem330
authored andcommitted
rhashtable: Fix potential crash on destroy in rhashtable_shrink
The current being_destroyed check in rhashtable_expand is not enough since if we start a shrinking process after freeing all elements in the table that's also going to crash. This patch adds a being_destroyed check to the deferred worker thread so that we bail out as soon as we take the lock. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9b55669 commit 28134a5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/rhashtable.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,13 +487,17 @@ static void rht_deferred_worker(struct work_struct *work)
487487

488488
ht = container_of(work, struct rhashtable, run_work);
489489
mutex_lock(&ht->mutex);
490+
if (ht->being_destroyed)
491+
goto unlock;
492+
490493
tbl = rht_dereference(ht->tbl, ht);
491494

492495
if (ht->p.grow_decision && ht->p.grow_decision(ht, tbl->size))
493496
rhashtable_expand(ht);
494497
else if (ht->p.shrink_decision && ht->p.shrink_decision(ht, tbl->size))
495498
rhashtable_shrink(ht);
496499

500+
unlock:
497501
mutex_unlock(&ht->mutex);
498502
}
499503

0 commit comments

Comments
 (0)