[RHEL7,COMMIT] sunrpc: cache_head leak due queued request

Submitted by Konstantin Khorenko on Nov. 28, 2018, 4:02 p.m.

Details

Message ID 201811281602.wASG2VrV007028@finist-ce7.sw.ru
State New
Series "sunrpc: cache_head leak due queued request"
Headers show

Commit Message

Konstantin Khorenko Nov. 28, 2018, 4:02 p.m.
The commit is pushed to "branch-rh7-3.10.0-862.20.2.vz7.73.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-862.20.2.vz7.73.15
------>
commit ec2421405f25766ba00079359ee8de2da7908adf
Author: Vasily Averin <vvs@virtuozzo.com>
Date:   Wed Nov 28 19:02:30 2018 +0300

    sunrpc: cache_head leak due queued request
    
    Submitted to mainline
    https://patchwork.kernel.org/patch/10702077/
    
    After commit d202cce8963d  expired cache_head can be removed from
    hash on cache_detail.
    
    However expired cache_head can wait for a reply from previously submitted
    request. Such cache_head have increased refcounter and therefore it
    cannot be freed after cache_put(freeme).
    
    Because cache_head was removed from hash it cannot be found during
    cache_clean() and can be leaked forever together with stalled cache_request
    and other taken resources.
    
    Fixes d202cce8963d ("sunrpc: never return expired entries in sunrpc_cache_lookup")
    Cc: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
    Cc: stable@kernel.org # 2.6.35
    
    https://jira.sw.ru/browse/PSBM-80869
    
    Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
    Reviewed-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 net/sunrpc/cache.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 1e9ae8053b9c..7e2e289e4287 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -53,6 +53,11 @@  static void cache_init(struct cache_head *h, struct cache_detail *detail)
 	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 *key, int hash)
 {
@@ -97,6 +102,7 @@  struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
 				*hp = tmp->next;
 				tmp->next = NULL;
 				detail->entries --;
+				cache_fresh_locked(tmp, 0, detail);
 				freeme = tmp;
 				break;
 			}
@@ -112,8 +118,10 @@  struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
 	cache_get(new);
 	write_unlock(&detail->hash_lock);
 
-	if (freeme)
+	if (freeme) {
+		cache_fresh_unlocked(freeme, detail);
 		cache_put(freeme, detail);
+	}
 	return new;
 }
 EXPORT_SYMBOL_GPL(sunrpc_cache_lookup);