Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp645361imu; Fri, 11 Jan 2019 06:43:47 -0800 (PST) X-Google-Smtp-Source: ALg8bN4WCqEREEQXlxvkQXr0VB287qXyQ03itl4HyBC9GOKZoFktGYWG6v5+IxCAih30ha7oMrBg X-Received: by 2002:a62:5444:: with SMTP id i65mr15267036pfb.193.1547217827571; Fri, 11 Jan 2019 06:43:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547217827; cv=none; d=google.com; s=arc-20160816; b=J5dG6C+6rGGvs1RQPRwbaAOlL6ZrBWCcHrLvBGoPalSjhbNaaeGNDPoWnZPXfEe8nO 3Fsto0W2wn0KjniNonjefbazY4moG6WbppMQkBWG+DAgsGptzEJp0N/RrHjcHp9y3SlI cpLsRa2d4FbtmVtnZvx8V/YsAsLoHMKmo+mp2MkD5WPWS/+0IRF6yLbxL32QQspLustw ttlOESJsyk52eBR+wuBsZDuPTZMfDKV2dpBr2A5fWJ6O7a7VY4ZIcY31hV+KqS5xymQT 3c+IAOzIkyCWQl8B+egDH3uLPTSCtIAAqOVerdXD7qRRrxPGX+p882JRiDSuPIXkfJoy 4WbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gfDKVd5mDMtNC2JNEWZDgrIOfi637RlR8SBPa5vCBkY=; b=GlDSszwu8q41SXbWide5bM3OgEqhgacsPovEMKchPfwWcWAbMOY9/Xa8u8Q62CkL6s 7TLSjyiFYvyd/g6z8578iG+QR7Nfcq+u6jGHodBv2RiZrwME5zTLGhYSYntMqllK4Yh5 ScvWIXJmdIiLyzqUm8N38IguzPJwxL2suZdpEvJLUtIDYDNTJUMdV8lMZub57QfK4gze 8P5bpB8cRxTJD2LcVfIlPC2hiYjyeFIP0kbOp0Mz2i+ibmHNL13nnbsl3e9EAvUqaIkv Q+/KiT/XZE4D2X7sM6gK0P3TF0MNB3j1r80Woc5YYCOj8QU1vzpptvqAkfGO/9iWAZuH SeDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YPPfodnB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y73si36381250pgd.478.2019.01.11.06.43.32; Fri, 11 Jan 2019 06:43:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YPPfodnB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391336AbfAKOlo (ORCPT + 99 others); Fri, 11 Jan 2019 09:41:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:34428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391322AbfAKOlm (ORCPT ); Fri, 11 Jan 2019 09:41:42 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C50232133F; Fri, 11 Jan 2019 14:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547217701; bh=s8NNfvVisdaq1k5+MpCpnzUaBtA3p161ro/j6t51LOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YPPfodnBxacT89mqjrDOufrdw10uva/vZixoE7klhcf7HKdY+l+IuCCatzYXNyM3j cDILNaH+dmZBolCSq7xG+9i9ZByKUCTQb8h+kyXTYu0sMffAcSuZ+hNgrPcGciIa+a gfs+fdp8N67h7LEeGvJERL45658Vpo2xPRLXs84M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Tikhomirov , Vasily Averin , NeilBrown , "J. Bruce Fields" , stable@kernel.org Subject: [PATCH 4.20 10/65] sunrpc: fix cache_head leak due to queued request Date: Fri, 11 Jan 2019 15:14:56 +0100 Message-Id: <20190111131057.748549749@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111131055.331350141@linuxfoundation.org> References: <20190111131055.331350141@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vasily Averin commit 4ecd55ea074217473f94cfee21bb72864d39f8d7 upstream. 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 Cc: stable@kernel.org # 2.6.35 Signed-off-by: Vasily Averin Reviewed-by: NeilBrown Signed-off-by: J. Bruce Fields Signed-off-by: Greg Kroah-Hartman --- net/sunrpc/cache.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -54,6 +54,11 @@ static void cache_init(struct cache_head 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); + static struct cache_head *sunrpc_cache_find_rcu(struct cache_detail *detail, struct cache_head *key, int hash) @@ -100,6 +105,7 @@ static struct cache_head *sunrpc_cache_a if (cache_is_expired(detail, tmp)) { hlist_del_init_rcu(&tmp->cache_list); detail->entries --; + cache_fresh_locked(tmp, 0, detail); freeme = tmp; break; } @@ -115,8 +121,10 @@ static struct cache_head *sunrpc_cache_a cache_get(new); spin_unlock(&detail->hash_lock); - if (freeme) + if (freeme) { + cache_fresh_unlocked(freeme, detail); cache_put(freeme, detail); + } return new; }