Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp593602img; Fri, 22 Mar 2019 04:46:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwF0p6TEc+mc/2YrvRfj3oWJzgEno6M9BkIrJWSmoQT6ZZA49UaW5nQ4P+t0OsVBbhOfEdV X-Received: by 2002:a17:902:5a5:: with SMTP id f34mr9121509plf.35.1553255190202; Fri, 22 Mar 2019 04:46:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553255190; cv=none; d=google.com; s=arc-20160816; b=TFgy2OZXw1SlarA/XPenIjSDrjr/Ho1Oeplr+/FyYrtbAz1KBALC7C2cIU58bIq2lB YFR7gQ6y5zdZCZo6HuX1eqoFV91QnjSQFku7dJrCy5KtHandaFsoCG+9U669Hu9itCZC /87srG3O85BCDkdCl/Atoi3fBKueV9b9sW/83FvnHhmHOfUS7PvOWBqFjZ1WnIIVSIyD iyms/43aQGRKdGKXaONLPr1gK0ZaNbSxwHyTu3uSMpI4pmMvP13UDDnjQg6WzzNWtYcB wW/Z1HW2MH1vnvJrm4GM33+G2lOsUD8COVF6vU0T3OX4V/XIHR2dL9UJ/WfXV9zpiLNr l20A== 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=ztjrvnaa0cUpJf8nhKtLU+T7NeP9eUI80WwC5SSNJXE=; b=ibb4UmA43BZ2qEuOpjCgqt26EMI/WGLPvwtqOUVEFye0eoDdlEC4W0jqqEmAHUW3hk UMPEpCXpSI7DdLF1RpzMjLPHqVjxI7TshPzrLb1pn+H0b1XhNa3R2AyNKcRXkQrxr1hf cAKuTQlzXsF062oW7WcKM4tiq0iLAoJ4NTgVGKKF7zcivGYgz7tjhaKcMTkJpb6MGGhV AThjEye9mvghk29+NzG+vtqfkNpDKr9BIrNOQtzA4TVf164/Is37CHDaxk/T8hWEp7ym d7NK6oPpT/We6VpTLEoEj7pdxwNS/HKcqAngynM8n5nfFv7K/omNCFGPWbWfIhsHqGO0 aopw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lyD45Lq0; 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 m133si6531978pga.314.2019.03.22.04.46.14; Fri, 22 Mar 2019 04:46:30 -0700 (PDT) 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=lyD45Lq0; 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 S1731928AbfCVLpN (ORCPT + 99 others); Fri, 22 Mar 2019 07:45:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:48268 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731010AbfCVLpK (ORCPT ); Fri, 22 Mar 2019 07:45:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 63E3721934; Fri, 22 Mar 2019 11:45:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553255109; bh=sM0NgIw2v9EHs41AbeK96Viv0Vv5pi6P6bVSzy6Z4yE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lyD45Lq0mePpnIU12biAGAKONJaeJkIBCYbtDwTYmCGNWMlNLJo7LdJ5TLbuzplDA B+qQRj2jX6QSidbP5ozMWgkVuhfaxGaJFCOJKnMwpIo1I76SfgxOKBMMZn1rvWCPTD rllm+K8jQdXUuslzyT+BVw274u3GSuTPIF+bCmxQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust Subject: [PATCH 4.9 101/118] NFS: Fix I/O request leakages Date: Fri, 22 Mar 2019 12:16:13 +0100 Message-Id: <20190322111223.506026668@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111215.873964544@linuxfoundation.org> References: <20190322111215.873964544@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Trond Myklebust commit f57dcf4c72113c745d83f1c65f7291299f65c14f upstream. When we fail to add the request to the I/O queue, we currently leave it to the caller to free the failed request. However since some of the requests that fail are actually created by nfs_pageio_add_request() itself, and are not passed back the caller, this leads to a leakage issue, which can again cause page locks to leak. This commit addresses the leakage by freeing the created requests on error, using desc->pg_completion_ops->error_cleanup() Signed-off-by: Trond Myklebust Fixes: a7d42ddb30997 ("nfs: add mirroring support to pgio layer") Cc: stable@vger.kernel.org # v4.0: c18b96a1b862: nfs: clean up rest of reqs Cc: stable@vger.kernel.org # v4.0: d600ad1f2bdb: NFS41: pop some layoutget Cc: stable@vger.kernel.org # v4.0+ Signed-off-by: Greg Kroah-Hartman --- fs/nfs/pagelist.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c @@ -975,6 +975,17 @@ static void nfs_pageio_doio(struct nfs_p } } +static void +nfs_pageio_cleanup_request(struct nfs_pageio_descriptor *desc, + struct nfs_page *req) +{ + LIST_HEAD(head); + + nfs_list_remove_request(req); + nfs_list_add_request(req, &head); + desc->pg_completion_ops->error_cleanup(&head); +} + /** * nfs_pageio_add_request - Attempt to coalesce a request into a page list. * @desc: destination io descriptor @@ -1012,10 +1023,8 @@ static int __nfs_pageio_add_request(stru nfs_page_group_unlock(req); desc->pg_moreio = 1; nfs_pageio_doio(desc); - if (desc->pg_error < 0) - return 0; - if (mirror->pg_recoalesce) - return 0; + if (desc->pg_error < 0 || mirror->pg_recoalesce) + goto out_cleanup_subreq; /* retry add_request for this subreq */ nfs_page_group_lock(req, false); continue; @@ -1048,6 +1057,10 @@ err_ptr: desc->pg_error = PTR_ERR(subreq); nfs_page_group_unlock(req); return 0; +out_cleanup_subreq: + if (req != subreq) + nfs_pageio_cleanup_request(desc, subreq); + return 0; } static int nfs_do_recoalesce(struct nfs_pageio_descriptor *desc) @@ -1141,11 +1154,14 @@ int nfs_pageio_add_request(struct nfs_pa if (nfs_pgio_has_mirroring(desc)) desc->pg_mirror_idx = midx; if (!nfs_pageio_add_request_mirror(desc, dupreq)) - goto out_failed; + goto out_cleanup_subreq; } return 1; +out_cleanup_subreq: + if (req != dupreq) + nfs_pageio_cleanup_request(desc, dupreq); out_failed: /* * We might have failed before sending any reqs over wire.