Skip to content

Commit

Permalink
rhashtable: Fix potential crash on destroy in rhashtable_shrink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Herbert Xu authored and David S. Miller committed Feb 5, 2015
1 parent 9b55669 commit 28134a5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rhashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,17 @@ static void rht_deferred_worker(struct work_struct *work)

ht = container_of(work, struct rhashtable, run_work);
mutex_lock(&ht->mutex);
if (ht->being_destroyed)
goto unlock;

tbl = rht_dereference(ht->tbl, ht);

if (ht->p.grow_decision && ht->p.grow_decision(ht, tbl->size))
rhashtable_expand(ht);
else if (ht->p.shrink_decision && ht->p.shrink_decision(ht, tbl->size))
rhashtable_shrink(ht);

unlock:
mutex_unlock(&ht->mutex);
}

Expand Down

0 comments on commit 28134a5

Please sign in to comment.