From patchwork Tue Sep 2 14:10:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 4826081 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 13D43C0338 for ; Tue, 2 Sep 2014 14:11:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DEA7820160 for ; Tue, 2 Sep 2014 14:11:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF07F2009C for ; Tue, 2 Sep 2014 14:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753876AbaIBOLV (ORCPT ); Tue, 2 Sep 2014 10:11:21 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:45255 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753707AbaIBOLV (ORCPT ); Tue, 2 Sep 2014 10:11:21 -0400 Received: by mail-pa0-f49.google.com with SMTP id kq14so14714266pab.22 for ; Tue, 02 Sep 2014 07:11:20 -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 :content-type:content-transfer-encoding; bh=kMr+qha1HFkie7sTBaZ3CqXR7QsKrBl6PNczkQsIS3g=; b=CzNiHwoAVOkNDkbXsw8Rgy7qyhMtXterZ5kIu14UvtFrg/VqHwHkkZBEZ9Y4ChZGKT 6KXrvzX6ZwdxE2bnkD4B2OoN68VlyE4VA6owp+EhnXBEWDuwkVR27RQymUsupH4yDKXW QG/KRtms+bRfpkSFd0mPxYsEtivGNJYeCxVb0HTBNyeqp6SuqywitHsQaaZ3bU13oJi+ Ak2W6mPgLvan1jkjWCT7sO9fjfz+HIZ9V6OW3jYcydoo9vGWScLT6mVD8arA51RPxrE+ nB6Z4dw5JKfTtq9c6piNW3qlXvu9eI8lCn5/UVJX/SkjDJllc5xtn8QrMymxzdBvygU2 RMHA== X-Received: by 10.67.5.68 with SMTP id ck4mr48749179pad.6.1409667080901; Tue, 02 Sep 2014 07:11:20 -0700 (PDT) Received: from [192.168.0.100] ([171.92.20.104]) by mx.google.com with ESMTPSA id g13sm11789411pat.45.2014.09.02.07.11.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Sep 2014 07:11:19 -0700 (PDT) Message-ID: <5405CFE4.9060407@gmail.com> Date: Tue, 02 Sep 2014 22:10:44 +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: "J. Bruce Fields" CC: Linux NFS Mailing List , Kinglong Mee Subject: [PATCH 1/6] NFSD: Put file after ima_file_check fail in nfsd_open() 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 | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index f501a9b..a994c50 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,17 +704,22 @@ 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; + + file = dentry_open(&path, flags, current_cred()); + if (IS_ERR(file)) { + host_err = PTR_ERR(file); } else { - host_err = ima_file_check(*filp, may_flags); + host_err = ima_file_check(file, may_flags); + if (host_err) { + nfsd_close(file); + goto out_nfserr; + } if (may_flags & NFSD_MAY_64BIT_COOKIE) - (*filp)->f_mode |= FMODE_64BITHASH; + (file)->f_mode |= FMODE_64BITHASH; else - (*filp)->f_mode |= FMODE_32BITHASH; + (file)->f_mode |= FMODE_32BITHASH; + *filp = file; } out_nfserr: