]> git.openfabrics.org - ~shefty/rdma-dev.git/commitdiff
pktgen: Limit how much data we copy onto the stack.
authorNelson Elhage <nelhage@ksplice.com>
Thu, 28 Oct 2010 18:31:07 +0000 (11:31 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 28 Oct 2010 18:47:53 +0000 (11:47 -0700)
A program that accidentally writes too much data to the pktgen file can overflow
the kernel stack and oops the machine. This is only triggerable by root, so
there's no security issue, but it's still an unfortunate bug.

printk() won't print more than 1024 bytes in a single call, anyways, so let's
just never copy more than that much data. We're on a fairly shallow stack, so
that should be safe even with CONFIG_4KSTACKS.

Signed-off-by: Nelson Elhage <nelhage@ksplice.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/pktgen.c

index 679b797d06b1028888bdc9590a1f741918eece6c..fbce4b05a53e79b502e37e7d768228dc6155b5d9 100644 (file)
@@ -887,10 +887,11 @@ static ssize_t pktgen_if_write(struct file *file,
        i += len;
 
        if (debug) {
-               char tb[count + 1];
-               if (copy_from_user(tb, user_buffer, count))
+               size_t copy = min(count, 1023);
+               char tb[copy + 1];
+               if (copy_from_user(tb, user_buffer, copy))
                        return -EFAULT;
-               tb[count] = 0;
+               tb[copy] = 0;
                printk(KERN_DEBUG "pktgen: %s,%lu  buffer -:%s:-\n", name,
                       (unsigned long)count, tb);
        }