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: Wed, 15 May 2024 15:17:25 +0000
From: Jiasheng Jiang <jiashengjiangcool@...look.com>
To: viro@...iv.linux.org.uk,
	brauner@...nel.org,
	jack@...e.cz,
	arnd@...db.de,
	gregkh@...e.de
Cc: linux-fsdevel@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Jiasheng Jiang <jiashengjiangcool@...look.com>
Subject: [PATCH] libfs: fix implicitly cast in simple_attr_write_xsigned()

Return 0 to indicate failure and return "len" to indicate success.
It was hard to distinguish success or failure if "len" equals the error
code after the implicit cast.
Moreover, eliminating implicit cast is a better practice.

Fixes: acaefc25d21f ("[PATCH] libfs: add simple attribute files")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@...look.com>
---
 fs/libfs.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/fs/libfs.c b/fs/libfs.c
index b635ee5adbcc..637451f0d53e 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -1348,24 +1348,27 @@ static ssize_t simple_attr_write_xsigned(struct file *file, const char __user *b
 
 	attr = file->private_data;
 	if (!attr->set)
-		return -EACCES;
+		return 0;
 
 	ret = mutex_lock_interruptible(&attr->mutex);
 	if (ret)
-		return ret;
+		return 0;
 
-	ret = -EFAULT;
 	size = min(sizeof(attr->set_buf) - 1, len);
-	if (copy_from_user(attr->set_buf, buf, size))
+	if (copy_from_user(attr->set_buf, buf, size)) {
+		ret = 0;
 		goto out;
+	}
 
 	attr->set_buf[size] = '\0';
 	if (is_signed)
-		ret = kstrtoll(attr->set_buf, 0, &val);
+		ret = (size_t)kstrtoll(attr->set_buf, 0, &val);
 	else
-		ret = kstrtoull(attr->set_buf, 0, &val);
-	if (ret)
+		ret = (size_t)kstrtoull(attr->set_buf, 0, &val);
+	if (ret) {
+		ret = 0;
 		goto out;
+	}
 	ret = attr->set(attr->data, val);
 	if (ret == 0)
 		ret = len; /* on success, claim we got the whole input */
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ