Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp623568img; Fri, 22 Mar 2019 05:22:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIIpBSMLMEXNdGDqH72sftlDzL3wNazTD2H7QiMdWhGxlf4Q1x2E4MoQA4hAH2nBE20scB X-Received: by 2002:a63:ee04:: with SMTP id e4mr8660873pgi.310.1553257339309; Fri, 22 Mar 2019 05:22:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553257339; cv=none; d=google.com; s=arc-20160816; b=uymJbyDunPbJp22hsTI8djX5tiQJmU5LnMoPambyc3Zt7f92HAVdc1Gxvp5uacNjh4 eb4WBdV4zwhiEX7KRYx4FYvS2dbH3Ar+fEcGu1ep2PQXdT/7JdP/kd0GMyfe2+9vGAA/ 1FSKl2xJNInav5n9Nvz6uwwNZev2SwxnU+Av75Bx1Gw550JNUgUzAMhbaCvYbo3s54+/ tFQb8h6vI7zH6nQpJuSnGKVuI9u1gewTK0iHjD2FhQMyBeG6Nt4/RaGHPrLZCzz2bnXk JfENxYnqpPESmxXd1XpPMpkpsdfVLwnadoS5gbaKwC5351MBol+ELDYTIuUC3CxKA+3Q PYaQ== 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=B5zrWn06bPD3+M41F/i3b47eSIF3F14rurbPp348cPY=; b=tJJq1CNY+b0lQAU9HOZpIAMLqbHIKbhQkJAZKLPxoKpSwfw9V84niTRCPa9C1HrU82 ptCSr+s6Wq0MceMZPIB4o3a+zsXdy8IAVSMMGWP4sKIdozQUNmNFNySj+R9XWG+AWJdl AULbBOeW07vNjJpIec4GZ8yHy/vWPutAS/R99JFIqJ0LJFv9w/DH9GuZVjBKP6FSIjAa 42cxFw2ZmkIPvWeVu9XH3typ+3F0sgYK1iXk+CjwlgeywwkH9vynMcid8BnFTb0Zmf4P xUyDEXTJynclWuv6bW8poOe7H+B1RTS0KOmD2h+9AE71T4hnC30y2QK+fmWyrGxDTn+d vgaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Zi+oKoRx; 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 124si6720172pfw.148.2019.03.22.05.22.04; Fri, 22 Mar 2019 05:22:19 -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=Zi+oKoRx; 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 S2390858AbfCVMVY (ORCPT + 99 others); Fri, 22 Mar 2019 08:21:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:60418 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390856AbfCVMVU (ORCPT ); Fri, 22 Mar 2019 08:21:20 -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 D72DE2054F; Fri, 22 Mar 2019 12:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553257279; bh=p2AF7x5bld3p+ubfWlS1+5aKEcVNr/aNnhvdvY+Ctew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zi+oKoRx1yQDblk4ntYDLcKCXu+83dnLAa6TaiEhj4UPWn14KLqxSnmJikeARlYyB sIHuudnkxzujD/TXnL7svC23oNTZZS4czYjzsM8C6qKz887kq/cJTDG0qLKVdGijke siZT7PTHJSLDiGJoPLvrW8siq4YK/xFaEOapaT/k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust Subject: [PATCH 5.0 184/238] NFS: Fix I/O request leakages Date: Fri, 22 Mar 2019 12:16:43 +0100 Message-Id: <20190322111309.124688277@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@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 5.0-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 @@ -988,6 +988,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 @@ -1025,10 +1036,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); continue; @@ -1061,6 +1070,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) @@ -1168,11 +1181,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: nfs_pageio_error_cleanup(desc); return 0;