Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3342745imm; Tue, 17 Jul 2018 03:14:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcwvbr2M7HiJQWI1JPqOBslkJBZGdKAuquvrhYWS9ugsuFKHC04vFP6ec/fxFuXfmGMubJX X-Received: by 2002:a62:8a4f:: with SMTP id y76-v6mr9880pfd.233.1531822475815; Tue, 17 Jul 2018 03:14:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531822475; cv=none; d=google.com; s=arc-20160816; b=hDRNmjhp4fzBSGu/82IUL1yGHRDjFzUC7gewi9y/X8EQTHUIjbbre6+6mMgQ0c9Qi4 4CiNyxt6idlFE99jVpaHOrpAUvvn6ZnHVxiuwfc20OuUEmgFegJEDcQYqd22QFR/9L5k RC6Y93v7+s8Y+c9OVBi/pbXRT2r5kSICXH64CqMm6j7qKHSDQjOuinG17op6kUHrWtUS r2Yc3PfGPMH2O9WXmeLvQvkxvGBhqEsXRjtv+3Ny4uGQponIIoTky1VOJrfNBPyxdi9t CejmqSV6tRg3KfySjZZcFdcn5oEGP469BQyz1l10O+S2scAvH8tBR7EDrr7pzd/XUMNR 7Q7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=0hUTEo010ZAtD1DncwKQqAE2mIPRgA1Qb90olPwjrfw=; b=UE8eLGAlGyRA/duOxtdTjKAgZIOVHu0lKUfdvoh8ZQB8wQjTiy8j4m5SGhyqbImiO7 2nbSSTlVnRtir0j091h474KsB/amqMtL7aM45eE+w1yl3pJRw4U2/TCVT3ylBV9JYR47 1NU1XP/l25l088Y4gM7bm5GQXidOOHRvOe4Ld+VgYD5xX6KzXoRxWgrAnl7e7TY+PlYq 4HaPnNQu2bapDt4r8XaKouuOdGElU4mOTdp+M9IlLRKsyvp63JSZypMROtpOffy+PXQJ P06ll+46Bwv4wmQTrsYPo0ruodsVoxND3AOXMwMdw8ljd/A7HI5Y8YkcSKMLnCIk2ctP 4eFQ== ARC-Authentication-Results: i=1; mx.google.com; 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 d16-v6si539807pfe.267.2018.07.17.03.14.20; Tue, 17 Jul 2018 03:14:35 -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; 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 S1731123AbeGQKpN (ORCPT + 99 others); Tue, 17 Jul 2018 06:45:13 -0400 Received: from fieldses.org ([173.255.197.46]:36446 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729907AbeGQKpN (ORCPT ); Tue, 17 Jul 2018 06:45:13 -0400 Received: by fieldses.org (Postfix, from userid 2815) id 9599623ED; Tue, 17 Jul 2018 06:13:20 -0400 (EDT) Date: Tue, 17 Jul 2018 06:13:20 -0400 From: "J . Bruce Fields" To: Colin Ian King Cc: Dan Carpenter , Jeff Layton , linux-nfs@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, Olga Kornievskaia Subject: Re: [PATCH] nfsd: fix memory leak of async_copy Message-ID: <20180717101320.GB30192@fieldses.org> References: <20180716120954.6720-1-colin.king@canonical.com> <20180717093005.3ggy24fskb3bxtni@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cc'ing Olga.--b. On Tue, Jul 17, 2018 at 10:33:59AM +0100, Colin Ian King wrote: > On 17/07/18 10:30, Dan Carpenter wrote: > > On Mon, Jul 16, 2018 at 01:09:54PM +0100, Colin King wrote: > >> From: Colin Ian King > >> > >> In the case where async_copy is successfully allocated but > >> the call to nfs4_init_cp_state fails, async_copy is not > >> currently freed and the memory is leaked. Fix this by kfree'ing > >> it before returning. > >> > >> Detected by CoverityScan, CID#1471823 ("Resource leak") > >> > >> Fixes: beb1814d5a8a ("NFSD create new stateid for async copy") > >> Signed-off-by: Colin Ian King > >> --- > >> fs/nfsd/nfs4proc.c | 4 +++- > >> 1 file changed, 3 insertions(+), 1 deletion(-) > >> > >> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c > >> index 8f3368353aaf..3fb96a2708b9 100644 > >> --- a/fs/nfsd/nfs4proc.c > >> +++ b/fs/nfsd/nfs4proc.c > >> @@ -1295,8 +1295,10 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, > >> async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); > >> if (!async_copy) > >> goto out; > >> - if (!nfs4_init_cp_state(nn, copy)) > >> + if (!nfs4_init_cp_state(nn, copy)) { > >> + kfree(async_copy); > >> goto out; > > > > It really feels like both this and the kzalloc() failure should be doing > > an of fput() of copy->file_src and copy->file_dst. The goto out_err > > does an list_del(©->copies); but it happens before the > > "list_add(&async_copy->copies ..." so that's likely wrong as well. > > Good observation, thanks for spotting that. I suspect I'm a bit out of > my depth figuring out the exact error handling reaping steps here. > Perhaps this is one for the maintainers to figure out a safe cleanup on > these error paths. > > > > > regards, > > dan carpenter > > > > -- > > To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in > > the body of a message to majordomo@vger.kernel.org > > More majordomo info at http://vger.kernel.org/majordomo-info.html > >