aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2013-06-12 22:53:42 -0400
committerJ. Bruce Fields <bfields@redhat.com>2013-07-01 17:53:28 -0400
commit013920eb5db97e99a4c30c8400f1c616e2a8b0a2 (patch)
treef4d1e80073ac61199d898a793815ee6dd493351b /net
parent2a1c7f53fd31e46f51780b61eb99fffef4c3c5a6 (diff)
sunrpc/cache: ensure items removed from cache do not have pending upcalls.
It is possible for a race to set CACHE_PENDING after cache_clean() has removed a cache entry from the cache. If CACHE_PENDING is still set when the entry is finally 'put', the cache_dequeue() will never happen and we can leak memory. So set a new flag 'CACHE_CLEANED' when we remove something from the cache, and don't queue any upcall if it is set. If CACHE_PENDING is set before CACHE_CLEANED, the call that cache_clean() makes to cache_fresh_unlocked() will free memory as needed. If CACHE_PENDING is set after CACHE_CLEANED, the test in sunrpc_cache_pipe_upcall will ensure that the memory is not allocated. Reported-by: <bstroesser@ts.fujitsu.com> Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'net')
-rw-r--r--net/sunrpc/cache.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 29c463396a2d..b12144c5edd0 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -306,7 +306,7 @@ EXPORT_SYMBOL_GPL(cache_check);
306 * a current pointer into that list and into the table 306 * a current pointer into that list and into the table
307 * for that entry. 307 * for that entry.
308 * 308 *
309 * Each time clean_cache is called it finds the next non-empty entry 309 * Each time cache_clean is called it finds the next non-empty entry
310 * in the current table and walks the list in that entry 310 * in the current table and walks the list in that entry
311 * looking for entries that can be removed. 311 * looking for entries that can be removed.
312 * 312 *
@@ -453,6 +453,7 @@ static int cache_clean(void)
453 current_index ++; 453 current_index ++;
454 spin_unlock(&cache_list_lock); 454 spin_unlock(&cache_list_lock);
455 if (ch) { 455 if (ch) {
456 set_bit(CACHE_CLEANED, &ch->flags);
456 cache_fresh_unlocked(ch, d); 457 cache_fresh_unlocked(ch, d);
457 cache_put(ch, d); 458 cache_put(ch, d);
458 } 459 }
@@ -1178,6 +1179,9 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
1178 warn_no_listener(detail); 1179 warn_no_listener(detail);
1179 return -EINVAL; 1180 return -EINVAL;
1180 } 1181 }
1182 if (test_bit(CACHE_CLEANED, &h->flags))
1183 /* Too late to make an upcall */
1184 return -EAGAIN;
1181 1185
1182 buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 1186 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1183 if (!buf) 1187 if (!buf)