From patchwork Mon Mar 10 09:41:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yan, Zheng" X-Patchwork-Id: 3801891 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C74C0BF540 for ; Mon, 10 Mar 2014 09:42:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D646C20266 for ; Mon, 10 Mar 2014 09:42:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EA71C20265 for ; Mon, 10 Mar 2014 09:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752261AbaCJJmF (ORCPT ); Mon, 10 Mar 2014 05:42:05 -0400 Received: from mga02.intel.com ([134.134.136.20]:29435 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752158AbaCJJmF (ORCPT ); Mon, 10 Mar 2014 05:42:05 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 10 Mar 2014 02:42:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,622,1389772800"; d="scan'208";a="496942278" Received: from zyan5-mobl.sh.intel.com ([10.239.13.4]) by orsmga002.jf.intel.com with ESMTP; 10 Mar 2014 02:41:44 -0700 From: "Yan, Zheng" To: linux-nfs@vger.kernel.org Cc: bfields@fieldses.org, hch@infradead.org, "Yan, Zheng" Subject: [PATCH v3] nfsd4: fix memory leak in nfsd4_encode_fattr() Date: Mon, 10 Mar 2014 17:41:41 +0800 Message-Id: <1394444501-20826-1-git-send-email-zheng.z.yan@intel.com> X-Mailer: git-send-email 1.8.5.3 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The temporary file handle should be freed when nfsd4_encode_fattr() finishes its job. Christoph Hellwig suggests to move the code that generates the temporary file handle into nfsd4_encode_dirent_fattr() Signed-off-by: Yan, Zheng --- fs/nfsd/nfs4xdr.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 63f2395..73698f7 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -2058,7 +2058,6 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, u32 bmval1 = bmval[1]; u32 bmval2 = bmval[2]; struct kstat stat; - struct svc_fh *tempfh = NULL; struct kstatfs statfs; int buflen = count << 2; __be32 *attrlenp; @@ -2104,17 +2103,6 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, if (err) goto out_nfserr; } - if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) { - tempfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); - status = nfserr_jukebox; - if (!tempfh) - goto out; - fh_init(tempfh, NFS4_FHSIZE); - status = fh_compose(tempfh, exp, dentry, NULL); - if (status) - goto out; - fhp = tempfh; - } if (bmval0 & (FATTR4_WORD0_ACL | FATTR4_WORD0_ACLSUPPORT | FATTR4_WORD0_SUPPORTED_ATTRS)) { err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl); @@ -2499,8 +2487,6 @@ out: security_release_secctx(context, contextlen); #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ kfree(acl); - if (tempfh) - fh_put(tempfh); return status; out_nfserr: status = nfserrno(err); @@ -2524,6 +2510,7 @@ nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd, const char *name, int namlen, __be32 **p, int buflen) { struct svc_export *exp = cd->rd_fhp->fh_export; + struct svc_fh *tempfh = NULL; struct dentry *dentry; __be32 nfserr; int ignore_crossmnt = 0; @@ -2573,9 +2560,24 @@ nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd, } out_encode: - nfserr = nfsd4_encode_fattr(NULL, exp, dentry, p, buflen, cd->rd_bmval, - cd->rd_rqstp, ignore_crossmnt); + if ((cd->rd_bmval[0] & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID))) { + tempfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); + if (!tempfh) { + nfserr = nfserr_jukebox; + goto out_put; + } + fh_init(tempfh, NFS4_FHSIZE); + nfserr = fh_compose(tempfh, exp, dentry, NULL); + if (nfserr) + goto out_put; + } + nfserr = nfsd4_encode_fattr(tempfh, exp, dentry, p, buflen, + cd->rd_bmval, cd->rd_rqstp, ignore_crossmnt); out_put: + if (tempfh) { + fh_put(tempfh); + kfree(tempfh); + } dput(dentry); exp_put(exp); return nfserr;