All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] NFSD: Put file after ima_file_check fail in nfsd_open()
@ 2014-09-02 14:10 Kinglong Mee
  2014-09-02 15:57 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Kinglong Mee @ 2014-09-02 14:10 UTC (permalink / raw)
  To: J. Bruce Fields; +Cc: Linux NFS Mailing List, Kinglong Mee

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
---
 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:
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/6] NFSD: Put file after ima_file_check fail in nfsd_open()
  2014-09-02 14:10 [PATCH 1/6] NFSD: Put file after ima_file_check fail in nfsd_open() Kinglong Mee
@ 2014-09-02 15:57 ` Christoph Hellwig
  2014-09-03  0:14   ` [PATCH v2] " Kinglong Mee
  2014-09-03  0:16   ` [PATCH 1/6] " Kinglong Mee
  0 siblings, 2 replies; 4+ messages in thread
From: Christoph Hellwig @ 2014-09-02 15:57 UTC (permalink / raw)
  To: Kinglong Mee; +Cc: J. Bruce Fields, Linux NFS Mailing List

> +	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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] NFSD: Put file after ima_file_check fail in nfsd_open()
  2014-09-02 15:57 ` Christoph Hellwig
@ 2014-09-03  0:14   ` Kinglong Mee
  2014-09-03  0:16   ` [PATCH 1/6] " Kinglong Mee
  1 sibling, 0 replies; 4+ messages in thread
From: Kinglong Mee @ 2014-09-03  0:14 UTC (permalink / raw)
  To: Christoph Hellwig, J. Bruce Fields; +Cc: Linux NFS Mailing List, Kinglong Mee

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
---
 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:
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/6] NFSD: Put file after ima_file_check fail in nfsd_open()
  2014-09-02 15:57 ` Christoph Hellwig
  2014-09-03  0:14   ` [PATCH v2] " Kinglong Mee
@ 2014-09-03  0:16   ` Kinglong Mee
  1 sibling, 0 replies; 4+ messages in thread
From: Kinglong Mee @ 2014-09-03  0:16 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: J. Bruce Fields, Linux NFS Mailing List

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-09-03  0:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-02 14:10 [PATCH 1/6] NFSD: Put file after ima_file_check fail in nfsd_open() Kinglong Mee
2014-09-02 15:57 ` Christoph Hellwig
2014-09-03  0:14   ` [PATCH v2] " Kinglong Mee
2014-09-03  0:16   ` [PATCH 1/6] " Kinglong Mee

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.