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  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:   Sun, 22 Nov 2020 15:10:18 +0300
From:   Alexey Dobriyan <adobriyan@...il.com>
To:     gregkh@...uxfoundation.org, rafael@...nel.org
Cc:     linux-kernel@...r.kernel.org
Subject: [PATCH] driver core: cleanup kstrto*() usage

kstrto*() functions can write result directly to target memory
if no additional checks needs to be done.

Signed-off-by: Alexey Dobriyan <adobriyan@...il.com>
---

 drivers/base/core.c |   12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1701,12 +1701,10 @@ ssize_t device_store_ulong(struct device *dev,
 {
 	struct dev_ext_attribute *ea = to_ext_attr(attr);
 	int ret;
-	unsigned long new;
 
-	ret = kstrtoul(buf, 0, &new);
+	ret = kstrtoul(buf, 0, (unsigned long *)ea->var);
 	if (ret)
 		return ret;
-	*(unsigned long *)(ea->var) = new;
 	/* Always return full write size even if we didn't consume all */
 	return size;
 }
@@ -1726,16 +1724,12 @@ ssize_t device_store_int(struct device *dev,
 			 const char *buf, size_t size)
 {
 	struct dev_ext_attribute *ea = to_ext_attr(attr);
+	int val;
 	int ret;
-	long new;
 
-	ret = kstrtol(buf, 0, &new);
+	ret = kstrtoint(buf, 0, (int *)ea->var);
 	if (ret)
 		return ret;
-
-	if (new > INT_MAX || new < INT_MIN)
-		return -EINVAL;
-	*(int *)(ea->var) = new;
 	/* Always return full write size even if we didn't consume all */
 	return size;
 }

Powered by blists - more mailing lists