diff mbox

[1/6] NFSD: Put file after ima_file_check fail in nfsd_open()

Message ID 5405CFE4.9060407@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kinglong Mee Sept. 2, 2014, 2:10 p.m. UTC
Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
---
 fs/nfsd/vfs.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

Comments

Christoph Hellwig Sept. 2, 2014, 3:57 p.m. UTC | #1
> +	file = dentry_open(&path, flags, current_cred());
> +	if (IS_ERR(file)) {
> +		host_err = PTR_ERR(file);
>  	} else {

The is_err case should have a

	goto out_nfserr;

which would allow you to drop the following indentation if you
change the whole function anyway.

>  		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;

no need for the braces around file here.

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Kinglong Mee Sept. 3, 2014, 12:16 a.m. UTC | #2
On 9/2/2014 23:57, Christoph Hellwig wrote:
>> +	file = dentry_open(&path, flags, current_cred());
>> +	if (IS_ERR(file)) {
>> +		host_err = PTR_ERR(file);
>>  	} else {
> 
> The is_err case should have a
> 
> 	goto out_nfserr;
> 
> which would allow you to drop the following indentation if you
> change the whole function anyway.
> 
>>  		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;
> 
> no need for the braces around file here.
> 

Thanks for your review.
A new version of this patch has be sent.

thanks,
Kinglong Mee
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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: