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>] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 14 Oct 2013 15:37:17 -0300
From:	"Geyslan G. Bem" <geyslan@...il.com>
To:	matthew.garrett@...ula.com, jk@...abs.org, matt.fleming@...el.com
Cc:	linux-efi@...r.kernel.org, linux-kernel@...r.kernel.org,
	kernel-br@...glegroups.com, "Geyslan G. Bem" <geyslan@...il.com>
Subject: [PATCH] efivarfs: 'efivarfs_file_write' function reorganization

This reorganization:

Adds 'attrsize' variable to make the code cleaner and more
understandable, replacing all 'sizeof(attributes)'.

Removes 'bytes' prior assignment due this new approach.

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

Signed-off-by: Geyslan G. Bem <geyslan@...il.com>
---
 fs/efivarfs/file.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/fs/efivarfs/file.c b/fs/efivarfs/file.c
index 8dd524f..e190aa0 100644
--- a/fs/efivarfs/file.c
+++ b/fs/efivarfs/file.c
@@ -18,29 +18,24 @@ static ssize_t efivarfs_file_write(struct file *file,
 {
 	struct efivar_entry *var = file->private_data;
 	void *data;
-	u32 attributes;
+	u32 attributes, attrsize = sizeof(attributes);
 	struct inode *inode = file->f_mapping->host;
-	unsigned long datasize = count - sizeof(attributes);
-	ssize_t bytes = 0;
+	unsigned long datasize = count - attrsize;
+	ssize_t bytes;
 	bool set = false;
 
-	if (count < sizeof(attributes))
+	if (count < attrsize)
 		return -EINVAL;
 
-	if (copy_from_user(&attributes, userbuf, sizeof(attributes)))
+	if (copy_from_user(&attributes, userbuf, attrsize))
 		return -EFAULT;
 
 	if (attributes & ~(EFI_VARIABLE_MASK))
 		return -EINVAL;
 
-	data = kmalloc(datasize, GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
-
-	if (copy_from_user(data, userbuf + sizeof(attributes), datasize)) {
-		bytes = -EFAULT;
-		goto out;
-	}
+	data = memdup_user(userbuf + attrsize, datasize);
+	if (IS_ERR(data))
+		return PTR_ERR(data);
 
 	bytes = efivar_entry_set_get_size(var, attributes, &datasize,
 					  data, &set);
@@ -56,7 +51,7 @@ static ssize_t efivarfs_file_write(struct file *file,
 		dput(file->f_dentry);
 	} else {
 		mutex_lock(&inode->i_mutex);
-		i_size_write(inode, datasize + sizeof(attributes));
+		i_size_write(inode, datasize + attrsize);
 		mutex_unlock(&inode->i_mutex);
 	}
 
-- 
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