Commit 72d9ea3c authored by Vasily Averin's avatar Vasily Averin Committed by Juerg Haefliger

sunrpc: fix cache_head leak due to queued request

BugLink: https://bugs.launchpad.net/bugs/1811647

commit 4ecd55ea upstream.

After commit d202cce8, 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 d202cce8 ("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: default avatarVasily Averin <vvs@virtuozzo.com>
Reviewed-by: default avatarNeilBrown <neilb@suse.com>
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
parent c6aee8fc
...@@ -54,6 +54,11 @@ static void cache_init(struct cache_head *h, struct cache_detail *detail) ...@@ -54,6 +54,11 @@ static void cache_init(struct cache_head *h, struct cache_detail *detail)
h->last_refresh = now; h->last_refresh = now;
} }
static void cache_fresh_locked(struct cache_head *head, time_t expiry,
struct cache_detail *detail);
static void cache_fresh_unlocked(struct cache_head *head,
struct cache_detail *detail);
struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
struct cache_head *key, int hash) struct cache_head *key, int hash)
{ {
...@@ -95,6 +100,7 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, ...@@ -95,6 +100,7 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
if (cache_is_expired(detail, tmp)) { if (cache_is_expired(detail, tmp)) {
hlist_del_init(&tmp->cache_list); hlist_del_init(&tmp->cache_list);
detail->entries --; detail->entries --;
cache_fresh_locked(tmp, 0, detail);
freeme = tmp; freeme = tmp;
break; break;
} }
...@@ -110,8 +116,10 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, ...@@ -110,8 +116,10 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
cache_get(new); cache_get(new);
write_unlock(&detail->hash_lock); write_unlock(&detail->hash_lock);
if (freeme) if (freeme) {
cache_fresh_unlocked(freeme, detail);
cache_put(freeme, detail); cache_put(freeme, detail);
}
return new; return new;
} }
EXPORT_SYMBOL_GPL(sunrpc_cache_lookup); EXPORT_SYMBOL_GPL(sunrpc_cache_lookup);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment