Skip to contentSkip to conversation

ipv4: netfilter: ipt_CLUSTERIP: fix buffer overflow

PATCH Superseded Vasiliy Kulikov 3 participants 6 messages Mar 10, 2011 – Mar 20, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv4: netfilter: ipt_CLUSTERIP: fix buffer overflow

buffer string is copied from userspace. It is not checked whether it is zero terminated. This may lead to overflow inside of simple_strtoul().

It was introduced before the git epoch. Files "ipt_CLUSTERIP/*" are root writable only by default, however, on some setups permissions might be relaxed to e.g. network admin user.

---
Compile tested.

 net/ipv4/netfilter/ipt_CLUSTERIP.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
net/ipv4/netfilter/ipt_CLUSTERIP.c +1 -0
index 403ca57..7aabf9a 100644
@@ -666,6 +666,7 @@ static ssize_t clusterip_proc_write(struct file *file, const char __user *input,
 
 	if (copy_from_user(buffer, input, PROC_WRITELEN))
 		return -EFAULT;
+	buffer[sizeof(buffer)-1] = 0;
 
 	if (*buffer == '+') {
 		nodenum = simple_strtoul(buffer+1, NULL, 10);
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 19 lines · Vasiliy Kulikov

buffer string is copied from userspace.  It is not checked whether it is zero terminated.  This may lead to overflow inside of simple_strtoul().

It was introduced before the git epoch.  Files "ipt_CLUSTERIP/*" are root writable only by default, however, on some setups permissions might be relaxed to e.g. network admin user.

---
 Compile tested.

 net/ipv4/netfilter/ipt_CLUSTERIP.c |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)
net/ipv4/netfilter/ipt_CLUSTERIP.c +0 -0
index 403ca57..7aabf9a 100644

net/ipv4/netfilter/ipt_CLUSTERIP.c static ssize_t clusterip_proc_write(struct file *file, const char __user *input, · line 667

Quoted 2 lines
net/ipv4/netfilter/ipt_CLUSTERIP.c +0 -0
@@ -666,6 +666,7 @@ static ssize_t clusterip_proc_write(struct file *file, const char __user *input,
 
        if (copy_from_user(buffer, input, PROC_WRITELEN))

I think size should be used instead of PROC_WRITELEN.

if (size > PROC_WRITELEN)

     return -EIO;
if (copy_from_user(buffer, input, size))
    return -EFAULT;

buffer[size] = '\0';

Quoted 5 lines
net/ipv4/netfilter/ipt_CLUSTERIP.c +1 -0
                return -EFAULT;
+       buffer[sizeof(buffer)-1] = 0;
 
        if (*buffer == '+') {
                nodenum = simple_strtoul(buffer+1, NULL, 10);
Signature · 6 lines
Regards,
Changli Gao([email protected])
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 25 lines · Changli Gao
Quoted 19 lines · Vasiliy Kulikov

buffer string is copied from userspace. It is not checked whether it is zero terminated. This may lead to overflow inside of simple_strtoul().

It was introduced before the git epoch. Files "ipt_CLUSTERIP/*" are root writable only by default, however, on some setups permissions might be relaxed to e.g. network admin user.

---
Compile tested.

 net/ipv4/netfilter/ipt_CLUSTERIP.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
net/ipv4/netfilter/ipt_CLUSTERIP.c +0 -0
index 403ca57..7aabf9a 100644

net/ipv4/netfilter/ipt_CLUSTERIP.c static ssize_t clusterip_proc_write(struct file *file, const char __user *input, · line 667

Quoted 2 lines
net/ipv4/netfilter/ipt_CLUSTERIP.c +0 -0
@@ -666,6 +666,7 @@ static ssize_t clusterip_proc_write(struct file *file, const char __user *input,
 
       if (copy_from_user(buffer, input, PROC_WRITELEN))

I think size should be used instead of PROC_WRITELEN.

Quoted 5 lines

if (size > PROC_WRITELEN)

     return -EIO;
if (copy_from_user(buffer, input, size))
    return -EFAULT;

buffer[size] = '\0';

I agree, otherwise we might have the situation that the userspace copy is crossing page boundaries into unmapped memory.

#3 lore raw

PATCH v2 1/1 ipv4: netfilter: ipt_CLUSTERIP: fix buffer overflow

'buffer' string is copied from userspace. It is not checked whether it is zero terminated. This may lead to overflow inside of simple_strtoul(). Changli Gao suggested to copy not more than user supplied 'size' bytes.

It was introduced before the git epoch. Files "ipt_CLUSTERIP/*" are root writable only by default, however, on some setups permissions might be relaxed to e.g. network admin user.

---
 net/ipv4/netfilter/ipt_CLUSTERIP.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
net/ipv4/netfilter/ipt_CLUSTERIP.c +4 -1
index 1e26a48..af7dec6 100644
@@ -669,8 +669,11 @@ static ssize_t clusterip_proc_write(struct file *file, const char __user *input,
 	char buffer[PROC_WRITELEN+1];
 	unsigned long nodenum;
 
-	if (copy_from_user(buffer, input, PROC_WRITELEN))
+	if (size > PROC_WRITELEN)
+		return -EIO;
+	if (copy_from_user(buffer, input, size))
 		return -EFAULT;
+	buffer[size] = 0;
 
 	if (*buffer == '+') {
 		nodenum = simple_strtoul(buffer+1, NULL, 10);
Signature · 1 line
1.7.0.4
Acked-by on v2 1/1
#4 lore raw
Quoted 9 lines · Vasiliy Kulikov

'buffer' string is copied from userspace.  It is not checked whether it is zero terminated.  This may lead to overflow inside of simple_strtoul(). Changli Gao suggested to copy not more than user supplied 'size' bytes.

It was introduced before the git epoch.  Files "ipt_CLUSTERIP/*" are root writable only by default, however, on some setups permissions might be relaxed to e.g. network admin user.

Signature · 6 lines
Regards,
Changli Gao([email protected])
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw

Am 17.03.2011 13:15, schrieb Changli Gao:

Quoted 5 lines · Vasiliy Kulikov
Quoted 4 lines

'buffer' string is copied from userspace. It is not checked whether it is zero terminated. This may lead to overflow inside of simple_strtoul(). Changli Gao suggested to copy not more than user supplied 'size' bytes.

Quoted 8 lines
Quoted 5 lines

It was introduced before the git epoch. Files "ipt_CLUSTERIP/*" are root writable only by default, however, on some setups permissions might be relaxed to e.g. network admin user.

Applied, thanks everyone.