Skip to contentSkip to conversation

fs/nilfs2: Integer overflow in nilfs_ioctl_wrap_copy()

PATCH In review Wenliang Fan 2 participants 3 messages Dec 30, 2013 1 message not in the archive NILFS2 filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 fs/nilfs2: Integer overflow in nilfs_ioctl_wrap_copy()

Check before entering into cycle.

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;
---
 fs/nilfs2/ioctl.c | 2 ++
 1 file changed, 2 insertions(+)
fs/nilfs2/ioctl.c +2 -0
index b44bdb2..a260a98 100644
@@ -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;
Signature · 6 lines
1.8.5.rc1.28.g7061504

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1388388554-9513-1-git-send-email-fanwlexca-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 2/2 fs/nilfs2: Integer overflow in nilfs_ioctl_wrap_copy()

Check on every iteration.

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;
---
 fs/nilfs2/ioctl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/nilfs2/ioctl.c +6 -1
index a260a98..1db4319 100644
@@ -92,8 +92,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;
 
Signature · 6 lines
1.8.5.rc1.28.g7061504

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
In reply to a message not in the archive
Quoted 16 lines · Wenliang Fan

Check before entering into cycle.

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;
---
 fs/nilfs2/ioctl.c | 2 ++
 1 file changed, 2 insertions(+)
fs/nilfs2/ioctl.c +0 -0
index b44bdb2..a260a98 100644

fs/nilfs2/ioctl.c static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs, · line 68

Quoted 4 lines
fs/nilfs2/ioctl.c +1 -0
@@ -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)

I'd prefer to use brackets during condition checking. But it is only my preferences.

fs/nilfs2/ioctl.c static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs, · line 69

Quoted 1 line
fs/nilfs2/ioctl.c +1 -0
+		return -EINVAL;

I think that you have an issue in this code. It is called __get_free_pages before your code (please, see
http://lxr.free-electrons.com/source/fs/nilfs2/ioctl.c#L60). But you simply returns -EINVAL without free_pages() call. So, I think that it is memory leak.

Thanks,
Vyacheslav Dubeyko.

fs/nilfs2/ioctl.c static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs, · line 72

Quoted 3 lines
fs/nilfs2/ioctl.c +0 -0
 	for (i = 0; i < argv->v_nmembs; i += n) {
 		n = (argv->v_nmembs - i < maxmembs) ?
 			argv->v_nmembs - i : maxmembs;

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html