The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] fs/nilfs2: Integer overflow in nilfs_ioctl_wrap_copy()
@ 2013-12-20  7:46 Wenliang Fan
  2013-12-20  8:23 ` Vyacheslav Dubeyko
  0 siblings, 1 reply; 4+ messages in thread
From: Wenliang Fan @ 2013-12-20  7:46 UTC (permalink / raw)
  To: konishi.ryusuke; +Cc: linux-nilfs, linux-kernel, Wenliang Fan

The local variable 'pos' comes from userspace. If a large number was
passed, there would be an integer overflow in the following line:
	pos += n;

Signed-off-by: Wenliang Fan <fanwlexca@gmail.com>
---
 fs/nilfs2/ioctl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
index b44bdb2..b2bac9a 100644
--- a/fs/nilfs2/ioctl.c
+++ b/fs/nilfs2/ioctl.c
@@ -90,8 +90,13 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
 		total += nr;
 		if ((size_t)nr < n)
 			break;
-		if (pos == ppos)
+		if (pos == ppos) {
+			if (pos > ULONG_MAX - n) {
+				ret = -EINVAL;
+				break;
+			}
 			pos += n;
+		}
 	}
 	argv->v_nmembs = total;
 
-- 
1.8.5.rc1.28.g7061504


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

* Re: [PATCH] fs/nilfs2: Integer overflow in nilfs_ioctl_wrap_copy()
  2013-12-20  7:46 [PATCH] fs/nilfs2: Integer overflow in nilfs_ioctl_wrap_copy() Wenliang Fan
@ 2013-12-20  8:23 ` Vyacheslav Dubeyko
  0 siblings, 0 replies; 4+ messages in thread
From: Vyacheslav Dubeyko @ 2013-12-20  8:23 UTC (permalink / raw)
  To: Wenliang Fan; +Cc: konishi.ryusuke, linux-nilfs, linux-kernel

On Fri, 2013-12-20 at 15:46 +0800, Wenliang Fan wrote:
> The local variable 'pos' comes from userspace. If a large number was
> passed, there would be an integer overflow in the following line:
> 	pos += n;
> 

What about check before enter into the cycle? If you are talking about
possible huge number then you can receive huge number from userspace
before entering in the cycle.

Thanks,
Vyacheslav Dubeyko.

> Signed-off-by: Wenliang Fan <fanwlexca@gmail.com>
> ---
>  fs/nilfs2/ioctl.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
> index b44bdb2..b2bac9a 100644
> --- a/fs/nilfs2/ioctl.c
> +++ b/fs/nilfs2/ioctl.c
> @@ -90,8 +90,13 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
>  		total += nr;
>  		if ((size_t)nr < n)
>  			break;
> -		if (pos == ppos)
> +		if (pos == ppos) {
> +			if (pos > ULONG_MAX - n) {
> +				ret = -EINVAL;
> +				break;
> +			}
>  			pos += n;
> +		}
>  	}
>  	argv->v_nmembs = total;
>  



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

* [PATCH] fs/nilfs2: Integer overflow in nilfs_ioctl_wrap_copy()
@ 2013-12-28  2:28 Wenliang Fan
  2013-12-30  6:40 ` Vyacheslav Dubeyko
  0 siblings, 1 reply; 4+ messages in thread
From: Wenliang Fan @ 2013-12-28  2:28 UTC (permalink / raw)
  To: slava, konishi.ryusuke; +Cc: linux-nilfs, linux-kernel, Wenliang Fan

The local variable 'pos' comes from userspace. If a large number was
passed, there would be an integer overflow in the following line:
        pos += n;

Signed-off-by: Wenliang Fan <fanwlexca@gmail.com>
---
 fs/nilfs2/ioctl.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
index b44bdb2..a260a98 100644
--- a/fs/nilfs2/ioctl.c
+++ b/fs/nilfs2/ioctl.c
@@ -65,6 +65,8 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
 	ret = 0;
 	total = 0;
 	pos = argv->v_index;
+	if (pos > ULONG_MAX - argv->v_nmembs)
+		return -EINVAL;
 	for (i = 0; i < argv->v_nmembs; i += n) {
 		n = (argv->v_nmembs - i < maxmembs) ?
 			argv->v_nmembs - i : maxmembs;
-- 
1.8.5.rc1.28.g7061504


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

* Re: [PATCH] fs/nilfs2: Integer overflow in nilfs_ioctl_wrap_copy()
  2013-12-28  2:28 Wenliang Fan
@ 2013-12-30  6:40 ` Vyacheslav Dubeyko
  0 siblings, 0 replies; 4+ messages in thread
From: Vyacheslav Dubeyko @ 2013-12-30  6:40 UTC (permalink / raw)
  To: Wenliang Fan; +Cc: konishi.ryusuke, linux-nilfs, linux-kernel

Hi,

On Sat, 2013-12-28 at 10:28 +0800, Wenliang Fan wrote:
> The local variable 'pos' comes from userspace. If a large number was
> passed, there would be an integer overflow in the following line:
>         pos += n;
> 
> Signed-off-by: Wenliang Fan <fanwlexca@gmail.com>
> ---
>  fs/nilfs2/ioctl.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
> index b44bdb2..a260a98 100644
> --- a/fs/nilfs2/ioctl.c
> +++ b/fs/nilfs2/ioctl.c
> @@ -65,6 +65,8 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
>  	ret = 0;
>  	total = 0;
>  	pos = argv->v_index;
> +	if (pos > ULONG_MAX - argv->v_nmembs)
> +		return -EINVAL;

I am slightly confused. Does this patch means that you refused previous
one? Or this patch is addition to the previous one?

You need to prepare next version of the patch or to prepare patch set
from two patches. And it makes sense to provide changelog of your work,
I think.

Thanks,
Vyacheslav Dubeyko.

>  	for (i = 0; i < argv->v_nmembs; i += n) {
>  		n = (argv->v_nmembs - i < maxmembs) ?
>  			argv->v_nmembs - i : maxmembs;



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

end of thread, other threads:[~2013-12-30  6:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-20  7:46 [PATCH] fs/nilfs2: Integer overflow in nilfs_ioctl_wrap_copy() Wenliang Fan
2013-12-20  8:23 ` Vyacheslav Dubeyko
  -- strict thread matches above, loose matches on Subject: below --
2013-12-28  2:28 Wenliang Fan
2013-12-30  6:40 ` Vyacheslav Dubeyko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox