xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next 1/3] powerpc/rtas: Replaced simple_strtoull() with kstrtoull()
@ 2021-05-26  9:20 Chen Huang
  2021-05-26  9:20 ` [PATCH -next 2/3] xen: balloon: " Chen Huang
  2021-05-26  9:20 ` [PATCH -next 3/3] ocfs2: " Chen Huang
  0 siblings, 2 replies; 5+ messages in thread
From: Chen Huang @ 2021-05-26  9:20 UTC (permalink / raw)
  To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, Mark Fasheh,
	Joel Becker, Joseph Qi, Nathan Lynch, Andrew Donnellan,
	Alexey Kardashevskiy, Andrew Morton, Stephen Rothwell,
	Jens Axboe, Yang Yingliang, Masahiro Yamada, Dan Carpenter
  Cc: linuxppc-dev, linux-kernel, xen-devel, ocfs2-devel, Chen Huang

The simple_strtoull() function is deprecated in some situation, since
it does not check for the range overflow, use kstrtoull() instead.

Signed-off-by: Chen Huang <chenhuang5@huawei.com>
---
 arch/powerpc/kernel/rtas-proc.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/rtas-proc.c b/arch/powerpc/kernel/rtas-proc.c
index 6857a5b0a1c3..117886782ebd 100644
--- a/arch/powerpc/kernel/rtas-proc.c
+++ b/arch/powerpc/kernel/rtas-proc.c
@@ -259,7 +259,6 @@ __initcall(proc_rtas_init);
 static int parse_number(const char __user *p, size_t count, u64 *val)
 {
 	char buf[40];
-	char *end;
 
 	if (count > 39)
 		return -EINVAL;
@@ -269,11 +268,7 @@ static int parse_number(const char __user *p, size_t count, u64 *val)
 
 	buf[count] = 0;
 
-	*val = simple_strtoull(buf, &end, 10);
-	if (*end && *end != '\n')
-		return -EINVAL;
-
-	return 0;
+	return kstrtoull(buf, 10, val);
 }
 
 /* ****************************************************************** */
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH -next 2/3] xen: balloon: Replaced simple_strtoull() with kstrtoull()
  2021-05-26  9:20 [PATCH -next 1/3] powerpc/rtas: Replaced simple_strtoull() with kstrtoull() Chen Huang
@ 2021-05-26  9:20 ` Chen Huang
  2021-05-27 14:10   ` David Laight
  2021-05-26  9:20 ` [PATCH -next 3/3] ocfs2: " Chen Huang
  1 sibling, 1 reply; 5+ messages in thread
From: Chen Huang @ 2021-05-26  9:20 UTC (permalink / raw)
  To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, Mark Fasheh,
	Joel Becker, Joseph Qi, Nathan Lynch, Andrew Donnellan,
	Alexey Kardashevskiy, Andrew Morton, Stephen Rothwell,
	Jens Axboe, Yang Yingliang, Masahiro Yamada, Dan Carpenter
  Cc: linuxppc-dev, linux-kernel, xen-devel, ocfs2-devel, Chen Huang

The simple_strtoull() function is deprecated in some situation, since
it does not check for the range overflow, use kstrtoull() instead.

Signed-off-by: Chen Huang <chenhuang5@huawei.com>
---
 drivers/xen/xen-balloon.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/xen/xen-balloon.c b/drivers/xen/xen-balloon.c
index a8d24433c8e9..1fba838963d2 100644
--- a/drivers/xen/xen-balloon.c
+++ b/drivers/xen/xen-balloon.c
@@ -163,13 +163,16 @@ static ssize_t store_target_kb(struct device *dev,
 			       const char *buf,
 			       size_t count)
 {
-	char *endchar;
+	ssize_t ret;
 	unsigned long long target_bytes;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
 
-	target_bytes = simple_strtoull(buf, &endchar, 0) * 1024;
+	ret = kstrtoull(buf, 0, &target_bytes);
+	if (ret)
+		return ret;
+	target_bytes *= 1024;
 
 	balloon_set_new_target(target_bytes >> PAGE_SHIFT);
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH -next 3/3] ocfs2: Replaced simple_strtoull() with kstrtoull()
  2021-05-26  9:20 [PATCH -next 1/3] powerpc/rtas: Replaced simple_strtoull() with kstrtoull() Chen Huang
  2021-05-26  9:20 ` [PATCH -next 2/3] xen: balloon: " Chen Huang
@ 2021-05-26  9:20 ` Chen Huang
  1 sibling, 0 replies; 5+ messages in thread
From: Chen Huang @ 2021-05-26  9:20 UTC (permalink / raw)
  To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, Mark Fasheh,
	Joel Becker, Joseph Qi, Nathan Lynch, Andrew Donnellan,
	Alexey Kardashevskiy, Andrew Morton, Stephen Rothwell,
	Jens Axboe, Yang Yingliang, Masahiro Yamada, Dan Carpenter
  Cc: linuxppc-dev, linux-kernel, xen-devel, ocfs2-devel, Chen Huang

The simple_strtoull() function is deprecated in some situation since
it does not check for the range overflow, use kstrtoull() instead.

Signed-off-by: Chen Huang <chenhuang5@huawei.com>
---
 fs/ocfs2/cluster/heartbeat.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 1169c8dc9106..f89ffcbd585f 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -1596,12 +1596,13 @@ static ssize_t o2hb_region_start_block_store(struct config_item *item,
 	struct o2hb_region *reg = to_o2hb_region(item);
 	unsigned long long tmp;
 	char *p = (char *)page;
+	ssize_t ret;
 
 	if (reg->hr_bdev)
 		return -EINVAL;
 
-	tmp = simple_strtoull(p, &p, 0);
-	if (!p || (*p && (*p != '\n')))
+	ret = kstrtoull(p, 0, &tmp);
+	if (ret)
 		return -EINVAL;
 
 	reg->hr_start_block = tmp;
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [PATCH -next 2/3] xen: balloon: Replaced simple_strtoull() with kstrtoull()
  2021-05-26  9:20 ` [PATCH -next 2/3] xen: balloon: " Chen Huang
@ 2021-05-27 14:10   ` David Laight
  2021-05-27 14:37     ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: David Laight @ 2021-05-27 14:10 UTC (permalink / raw)
  To: 'Chen Huang',
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, Mark Fasheh,
	Joel Becker, Joseph Qi, Nathan Lynch, Andrew Donnellan,
	Alexey Kardashevskiy, Andrew Morton, Stephen Rothwell,
	Jens Axboe, Yang Yingliang, Masahiro Yamada, Dan Carpenter
  Cc: linuxppc-dev, linux-kernel, xen-devel, ocfs2-devel

From: Chen Huang
> Sent: 26 May 2021 10:20
> 
> The simple_strtoull() function is deprecated in some situation, since
> it does not check for the range overflow, use kstrtoull() instead.
> 
...
> -	target_bytes = simple_strtoull(buf, &endchar, 0) * 1024;
> +	ret = kstrtoull(buf, 0, &target_bytes);
> +	if (ret)
> +		return ret;
> +	target_bytes *= 1024;

I'd have thought it was more important to check *endchar
than overflow.
If you are worried about overflow you need a range check
before the multiply.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -next 2/3] xen: balloon: Replaced simple_strtoull() with kstrtoull()
  2021-05-27 14:10   ` David Laight
@ 2021-05-27 14:37     ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2021-05-27 14:37 UTC (permalink / raw)
  To: David Laight
  Cc: 'Chen Huang',
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, Mark Fasheh,
	Joel Becker, Joseph Qi, Nathan Lynch, Andrew Donnellan,
	Alexey Kardashevskiy, Andrew Morton, Stephen Rothwell,
	Jens Axboe, Yang Yingliang, Masahiro Yamada, linuxppc-dev,
	linux-kernel, xen-devel, ocfs2-devel

On Thu, May 27, 2021 at 02:10:21PM +0000, David Laight wrote:
> From: Chen Huang
> > Sent: 26 May 2021 10:20
> > 
> > The simple_strtoull() function is deprecated in some situation, since
> > it does not check for the range overflow, use kstrtoull() instead.
> > 
> ...
> > -	target_bytes = simple_strtoull(buf, &endchar, 0) * 1024;
> > +	ret = kstrtoull(buf, 0, &target_bytes);
> > +	if (ret)
> > +		return ret;
> > +	target_bytes *= 1024;
> 
> I'd have thought it was more important to check *endchar
> than overflow.

That's one of the differences between simple_strtoull() and kstrtoull().
The simple_strtoull() will accept a string like "123ABC", but kstrtoull()
will only accept NUL terminated numbers or a newline followed by a NUL
terminator.  Which is fine in this context because users will be doing
"echo 1234 > /sys/foo".

> If you are worried about overflow you need a range check
> before the multiply.

This is probably a case where if the users cause an integer overflow
then they get what they deserve.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-27 14:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-26  9:20 [PATCH -next 1/3] powerpc/rtas: Replaced simple_strtoull() with kstrtoull() Chen Huang
2021-05-26  9:20 ` [PATCH -next 2/3] xen: balloon: " Chen Huang
2021-05-27 14:10   ` David Laight
2021-05-27 14:37     ` Dan Carpenter
2021-05-26  9:20 ` [PATCH -next 3/3] ocfs2: " Chen Huang

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).