aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVasily Averin <vvs@virtuozzo.com>2018-11-28 03:45:57 -0500
committerJ. Bruce Fields <bfields@redhat.com>2018-12-04 15:42:08 -0500
commit4ecd55ea074217473f94cfee21bb72864d39f8d7 (patch)
tree273aa85947dace0ad1f2a7d6dd2350e07a658719
parentf50c9d797d3df41e13265491c722d3d15b038d57 (diff)
sunrpc: fix cache_head leak due to queued request
After commit d202cce8963d, an expired cache_head can be removed from the cache_detail's hash. However, the expired cache_head may be waiting for a reply from a previously submitted request. Such a cache_head has an increased refcounter and therefore it won't be freed after cache_put(freeme). Because the cache_head was removed from the hash it cannot be found during cache_clean() and can be leaked forever, together with stalled cache_request and other taken resources. In our case we noticed it because an entry in the export cache was holding a reference on a filesystem. Fixes d202cce8963d ("sunrpc: never return expired entries in sunrpc_cache_lookup") Cc: Pavel Tikhomirov <ptikhomirov@virtuozzo.com> Cc: stable@kernel.org # 2.6.35 Signed-off-by: Vasily Averin <vvs@virtuozzo.com> Reviewed-by: NeilBrown <neilb@suse.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r--net/sunrpc/cache.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index f96345b1180e..12bb23b8e0c5 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -54,6 +54,11 @@ static void cache_init(struct cache_head *h, struct cache_detail *detail)
54 h->last_refresh = now; 54 h->last_refresh = now;
55} 55}
56 56
57static void cache_fresh_locked(struct cache_head *head, time_t expiry,
58 struct cache_detail *detail);
59static void cache_fresh_unlocked(struct cache_head *head,
60 struct cache_detail *detail);
61
57static struct cache_head *sunrpc_cache_find_rcu(struct cache_detail *detail, 62static struct cache_head *sunrpc_cache_find_rcu(struct cache_detail *detail,
58 struct cache_head *key, 63 struct cache_head *key,
59 int hash) 64 int hash)
@@ -100,6 +105,7 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
100 if (cache_is_expired(detail, tmp)) { 105 if (cache_is_expired(detail, tmp)) {
101 hlist_del_init_rcu(&tmp->cache_list); 106 hlist_del_init_rcu(&tmp->cache_list);
102 detail->entries --; 107 detail->entries --;
108 cache_fresh_locked(tmp, 0, detail);
103 freeme = tmp; 109 freeme = tmp;
104 break; 110 break;
105 } 111 }
@@ -115,8 +121,10 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
115 cache_get(new); 121 cache_get(new);
116 spin_unlock(&detail->hash_lock); 122 spin_unlock(&detail->hash_lock);
117 123
118 if (freeme) 124 if (freeme) {
125 cache_fresh_unlocked(freeme, detail);
119 cache_put(freeme, detail); 126 cache_put(freeme, detail);
127 }
120 return new; 128 return new;
121} 129}
122 130