diff options
author | NeilBrown <neilb@suse.de> | 2013-06-12 22:53:42 -0400 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2013-07-01 17:53:28 -0400 |
commit | 013920eb5db97e99a4c30c8400f1c616e2a8b0a2 (patch) | |
tree | f4d1e80073ac61199d898a793815ee6dd493351b | |
parent | 2a1c7f53fd31e46f51780b61eb99fffef4c3c5a6 (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>
-rw-r--r-- | include/linux/sunrpc/cache.h | 1 | ||||
-rw-r--r-- | net/sunrpc/cache.c | 6 |
2 files changed, 6 insertions, 1 deletions
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h index 303399b1ba59..8419f7dbdab2 100644 --- a/include/linux/sunrpc/cache.h +++ b/include/linux/sunrpc/cache.h | |||
@@ -57,6 +57,7 @@ struct cache_head { | |||
57 | #define CACHE_VALID 0 /* Entry contains valid data */ | 57 | #define CACHE_VALID 0 /* Entry contains valid data */ |
58 | #define CACHE_NEGATIVE 1 /* Negative entry - there is no match for the key */ | 58 | #define CACHE_NEGATIVE 1 /* Negative entry - there is no match for the key */ |
59 | #define CACHE_PENDING 2 /* An upcall has been sent but no reply received yet*/ | 59 | #define CACHE_PENDING 2 /* An upcall has been sent but no reply received yet*/ |
60 | #define CACHE_CLEANED 3 /* Entry has been cleaned from cache */ | ||
60 | 61 | ||
61 | #define CACHE_NEW_EXPIRY 120 /* keep new things pending confirmation for 120 seconds */ | 62 | #define CACHE_NEW_EXPIRY 120 /* keep new things pending confirmation for 120 seconds */ |
62 | 63 | ||
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) |