From patchwork Wed Sep 3 00:14:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 4829461 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 83418C0338 for ; Wed, 3 Sep 2014 00:14:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 71CD9201ED for ; Wed, 3 Sep 2014 00:14:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9BB1A201E4 for ; Wed, 3 Sep 2014 00:14:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753853AbaICAOZ (ORCPT ); Tue, 2 Sep 2014 20:14:25 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:45402 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753728AbaICAOZ (ORCPT ); Tue, 2 Sep 2014 20:14:25 -0400 Received: by mail-pa0-f43.google.com with SMTP id et14so15990895pad.16 for ; Tue, 02 Sep 2014 17:14:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=usdmK5a0n6tO/p+VOK86Ai39W1QDGz0Trbuf5M7IULg=; b=IC9rDS93z7J0Ateg1TEygCmQsGAV7WdBmqJb9ARezhDopSJzYWR21SoximGArQU4T7 qU69stV1nrefoEzNyUrnIfvnzNeRm6PIaXAYbSw/W1SDBFL14vXbBJ1pXsLgDTRhTsnv 8GS+1Bg5Q4/XahVX86mXzE7IlL+rsWwDQkCS+Gj9jJqjVouPv77YkkyRgtKv/sfLpUmm GbfXBapcqIxbeQP+L+pVs0iKPTF22guRqXsAENFPgtX8tr2MluZrA413A01h7QEtXF9p MYS4mV7srZGJNkRqBsRKEhBAdwqOpS4l0TYNNAexO7mOmLM4S3/NYIaosErzGLCyw3zW Fk1A== X-Received: by 10.68.69.71 with SMTP id c7mr51878634pbu.43.1409703264620; Tue, 02 Sep 2014 17:14:24 -0700 (PDT) Received: from [192.168.0.100] ([110.190.110.179]) by mx.google.com with ESMTPSA id l4sm7064282pdp.66.2014.09.02.17.14.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Sep 2014 17:14:23 -0700 (PDT) Message-ID: <54065D4E.7040808@gmail.com> Date: Wed, 03 Sep 2014 08:14:06 +0800 From: Kinglong Mee User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: Christoph Hellwig , "J. Bruce Fields" CC: Linux NFS Mailing List , Kinglong Mee Subject: [PATCH v2] NFSD: Put file after ima_file_check fail in nfsd_open() References: <5405CFE4.9060407@gmail.com> <20140902155755.GA14472@infradead.org> In-Reply-To: <20140902155755.GA14472@infradead.org> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 Signed-off-by: Kinglong Mee --- fs/nfsd/vfs.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index f501a9b..89d1ae3 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -649,6 +649,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, { struct path path; struct inode *inode; + struct file *file; int flags = O_RDONLY|O_LARGEFILE; __be32 err; int host_err = 0; @@ -703,19 +704,25 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, else flags = O_WRONLY|O_LARGEFILE; } - *filp = dentry_open(&path, flags, current_cred()); - if (IS_ERR(*filp)) { - host_err = PTR_ERR(*filp); - *filp = NULL; - } else { - host_err = ima_file_check(*filp, may_flags); - if (may_flags & NFSD_MAY_64BIT_COOKIE) - (*filp)->f_mode |= FMODE_64BITHASH; - else - (*filp)->f_mode |= FMODE_32BITHASH; + file = dentry_open(&path, flags, current_cred()); + if (IS_ERR(file)) { + host_err = PTR_ERR(file); + goto out_nfserr; } + host_err = ima_file_check(file, may_flags); + if (host_err) { + nfsd_close(file); + goto out_nfserr; + } + + if (may_flags & NFSD_MAY_64BIT_COOKIE) + file->f_mode |= FMODE_64BITHASH; + else + file->f_mode |= FMODE_32BITHASH; + + *filp = file; out_nfserr: err = nfserrno(host_err); out: