lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1381772222-21323-1-git-send-email-geyslan@gmail.com>
Date:	Mon, 14 Oct 2013 14:37:02 -0300
From:	"Geyslan G. Bem" <geyslan@...il.com>
To:	linux-kernel@...r.kernel.org
Cc:	"Geyslan G. Bem" <geyslan@...il.com>
Subject: [PATCH] fs/fhandle.c: 'handle_to_path' function reorganization

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@...il.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ