Skip to content

Commit 4ecd55e

Browse files
vaverinJ. Bruce Fields
authored andcommitted
sunrpc: fix cache_head leak due to queued request
After commit d202cce, 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 d202cce ("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>
1 parent f50c9d7 commit 4ecd55e

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎net/sunrpc/cache.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ static void cache_init(struct cache_head *h, struct cache_detail *detail)
5454
h->last_refresh = now;
5555
}
5656

57+
static void cache_fresh_locked(struct cache_head *head, time_t expiry,
58+
struct cache_detail *detail);
59+
static void cache_fresh_unlocked(struct cache_head *head,
60+
struct cache_detail *detail);
61+
5762
static struct cache_head *sunrpc_cache_find_rcu(struct cache_detail *detail,
5863
struct cache_head *key,
5964
int hash)
@@ -100,6 +105,7 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
100105
if (cache_is_expired(detail, tmp)) {
101106
hlist_del_init_rcu(&tmp->cache_list);
102107
detail->entries --;
108+
cache_fresh_locked(tmp, 0, detail);
103109
freeme = tmp;
104110
break;
105111
}
@@ -115,8 +121,10 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
115121
cache_get(new);
116122
spin_unlock(&detail->hash_lock);
117123

118-
if (freeme)
124+
if (freeme) {
125+
cache_fresh_unlocked(freeme, detail);
119126
cache_put(freeme, detail);
127+
}
120128
return new;
121129
}
122130

0 commit comments

Comments
 (0)