linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Geyslan G. Bem" <geyslan@gmail.com>
To: viro@zeniv.linux.org.uk
Cc: viro@ftp.linux.org.uk, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.or, kernel-br@googlegroups.com,
	"Geyslan G. Bem" <geyslan@gmail.com>
Subject: [PATCH] fs/fhandle.c: 'handle_to_path' function reorganization
Date: Mon, 14 Oct 2013 14:28:15 -0300	[thread overview]
Message-ID: <1381771695-20659-1-git-send-email-geyslan@gmail.com> (raw)

This reorganization:

Removes the exiting labels and adds direct return, once that
there is only one cleanup necessity.

Removes 'retval' and 'file_handle' prior assignments due this new
approach.

Adds 'size' and 'byte' variables to make the code cleaner and more
understandable.

Uses 'memdup_user' instead 'kmalloc' + 'copy_from_user'.

Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
---
 fs/fhandle.c | 48 ++++++++++++++++++------------------------------
 1 file changed, 18 insertions(+), 30 deletions(-)

diff --git a/fs/fhandle.c b/fs/fhandle.c
index 999ff5c..56b120d 100644
--- a/fs/fhandle.c
+++ b/fs/fhandle.c
@@ -166,47 +166,35 @@ out_err:
 static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
 		   struct path *path)
 {
-	int retval = 0;
+	int retval;
 	struct file_handle f_handle;
-	struct file_handle *handle = NULL;
+	struct file_handle *handle;
+	unsigned int size, bytes;
 
 	/*
 	 * With handle we don't look at the execute bit on the
 	 * the directory. Ideally we would like CAP_DAC_SEARCH.
 	 * But we don't have that
 	 */
-	if (!capable(CAP_DAC_READ_SEARCH)) {
-		retval = -EPERM;
-		goto out_err;
-	}
-	if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle))) {
-		retval = -EFAULT;
-		goto out_err;
-	}
-	if ((f_handle.handle_bytes > MAX_HANDLE_SZ) ||
-	    (f_handle.handle_bytes == 0)) {
-		retval = -EINVAL;
-		goto out_err;
-	}
-	handle = kmalloc(sizeof(struct file_handle) + f_handle.handle_bytes,
-			 GFP_KERNEL);
-	if (!handle) {
-		retval = -ENOMEM;
-		goto out_err;
-	}
-	/* copy the full handle */
-	if (copy_from_user(handle, ufh,
-			   sizeof(struct file_handle) +
-			   f_handle.handle_bytes)) {
-		retval = -EFAULT;
-		goto out_handle;
-	}
+	if (!capable(CAP_DAC_READ_SEARCH))
+		return -EPERM;
+
+	size = sizeof(struct file_handle);
+	if (copy_from_user(&f_handle, ufh, size))
+		return -EFAULT;
+
+	bytes = f_handle.handle_bytes;
+	if ((bytes > MAX_HANDLE_SZ) || (bytes == 0))
+		return -EINVAL;
+
+	size += bytes;
+	handle = memdup_user(ufh, size);
+	if (IS_ERR(handle))
+		return PTR_ERR(handle);
 
 	retval = do_handle_to_path(mountdirfd, handle, path);
 
-out_handle:
 	kfree(handle);
-out_err:
 	return retval;
 }
 
-- 
1.8.4


                 reply	other threads:[~2013-10-14 17:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1381771695-20659-1-git-send-email-geyslan@gmail.com \
    --to=geyslan@gmail.com \
    --cc=kernel-br@googlegroups.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.or \
    --cc=viro@ftp.linux.org.uk \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).