Skip to contentSkip to conversation

fs/nilfs2: Integer overflow in nilfs_ioctl_wrap_copy()

PATCH In review Wenliang Fan 2 participants 2 messages Dec 20, 2013 NILFS2 filesystem

lore
Share & tools
lore
#0 lore raw

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

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 b44bdb2..b2bac9a 100644
@@ -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;
 
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
#1 lore raw
Quoted 4 lines · 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;

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.

Quoted 14 lines
---
 fs/nilfs2/ioctl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/nilfs2/ioctl.c +0 -1
index b44bdb2..b2bac9a 100644
@@ -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)

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

Quoted 10 lines
fs/nilfs2/ioctl.c +6 -0
+		if (pos == ppos) {
+			if (pos > ULONG_MAX - n) {
+				ret = -EINVAL;
+				break;
+			}
 			pos += n;
+		}
 	}
 	argv->v_nmembs = total;
 

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