Skip to content

Commit

Permalink
pktgen: Limit how much data we copy onto the stack.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
nelhage authored and davem330 committed Oct 28, 2010
1 parent 8acfe46 commit 448d7b5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions net/core/pktgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 448d7b5

Please sign in to comment.