netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* rhashtable: Fix potential crash on destroy in rhashtable_shrink
@ 2015-01-31  9:36 Herbert Xu
  2015-01-31 11:16 ` Thomas Graf
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Herbert Xu @ 2015-01-31  9:36 UTC (permalink / raw)
  To: Thomas Graf, netdev

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>

diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 69a4eb0..4c3da1f 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -489,6 +489,9 @@ 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);
 
 	list_for_each_entry(walker, &ht->walkers, list)
@@ -499,6 +502,7 @@ static void rht_deferred_worker(struct work_struct *work)
 	else if (ht->p.shrink_decision && ht->p.shrink_decision(ht, tbl->size))
 		rhashtable_shrink(ht);
 
+unlock:
 	mutex_unlock(&ht->mutex);
 }
 
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-02-03  3:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-31  9:36 rhashtable: Fix potential crash on destroy in rhashtable_shrink Herbert Xu
2015-01-31 11:16 ` Thomas Graf
2015-01-31 11:22   ` Herbert Xu
2015-01-31 12:15     ` Thomas Graf
2015-02-02  9:34 ` Ying Xue
2015-02-02  9:48   ` Thomas Graf
2015-02-03  3:19 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).