* [PATCH] pktgen: Remove a dangerous debug print.
@ 2010-10-27 19:13 Nelson Elhage
2010-10-27 19:21 ` David Miller
` (3 more replies)
0 siblings, 4 replies; 20+ messages in thread
From: Nelson Elhage @ 2010-10-27 19:13 UTC (permalink / raw)
To: Robert Olsson; +Cc: linux-kernel, netdev, Eugene Teo, Nelson Elhage
We were allocating an arbitrarily-large buffer on the stack, which would allow a
buggy or malicious userspace program to overflow the kernel stack.
Since the debug printk() was just printing exactly the text passed from
userspace, it's probably just as easy for anyone who might use it to augment (or
just strace(1)) the program writing to the pktgen file, so let's just not bother
trying to print the whole buffer.
Signed-off-by: Nelson Elhage <nelhage@ksplice.com>
---
net/core/pktgen.c | 11 +++--------
1 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 10a1ea7..de8e0da 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -888,14 +888,9 @@ 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))
- return -EFAULT;
- tb[count] = 0;
- printk(KERN_DEBUG "pktgen: %s,%lu buffer -:%s:-\n", name,
- (unsigned long)count, tb);
- }
+ if (debug)
+ printk(KERN_DEBUG "pktgen: %s,%lu\n", name,
+ (unsigned long)count);
if (!strcmp(name, "min_pkt_size")) {
len = num_arg(&user_buffer[i], 10, &value);
--
1.7.1.31.g6297e
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH] pktgen: Remove a dangerous debug print.
2010-10-27 19:13 [PATCH] pktgen: Remove a dangerous debug print Nelson Elhage
@ 2010-10-27 19:21 ` David Miller
2010-10-27 19:28 ` Nelson Elhage
2010-10-27 20:38 ` Ben Greear
` (2 subsequent siblings)
3 siblings, 1 reply; 20+ messages in thread
From: David Miller @ 2010-10-27 19:21 UTC (permalink / raw)
To: nelhage; +Cc: robert.olsson, linux-kernel, netdev, eugene
From: Nelson Elhage <nelhage@ksplice.com>
Date: Wed, 27 Oct 2010 15:13:08 -0400
> We were allocating an arbitrarily-large buffer on the stack, which would allow a
> buggy or malicious userspace program to overflow the kernel stack.
>
> Since the debug printk() was just printing exactly the text passed from
> userspace, it's probably just as easy for anyone who might use it to augment (or
> just strace(1)) the program writing to the pktgen file, so let's just not bother
> trying to print the whole buffer.
>
> Signed-off-by: Nelson Elhage <nelhage@ksplice.com>
Only root can write to the pktgen control file.
Also, the debug feature really is used by people's pktgen scripts, you
can't just turn it off.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] pktgen: Remove a dangerous debug print.
2010-10-27 19:21 ` David Miller
@ 2010-10-27 19:28 ` Nelson Elhage
2010-10-27 19:30 ` David Miller
2010-10-27 19:41 ` Eric Dumazet
0 siblings, 2 replies; 20+ messages in thread
From: Nelson Elhage @ 2010-10-27 19:28 UTC (permalink / raw)
To: David Miller; +Cc: robert.olsson, linux-kernel, netdev, eugene
How would you feel about limiting the debug print to at most, say, 512 or 1024
bytes? Even if it's only accessible to root by default, I don't a userspace
program should be able to accidentally corrupt the kernel stack by writing too
many bytes to a file in /proc.
- Nelson
On Wed, Oct 27, 2010 at 12:21:43PM -0700, David Miller wrote:
> From: Nelson Elhage <nelhage@ksplice.com>
> Date: Wed, 27 Oct 2010 15:13:08 -0400
>
> > We were allocating an arbitrarily-large buffer on the stack, which would allow a
> > buggy or malicious userspace program to overflow the kernel stack.
> >
> > Since the debug printk() was just printing exactly the text passed from
> > userspace, it's probably just as easy for anyone who might use it to augment (or
> > just strace(1)) the program writing to the pktgen file, so let's just not bother
> > trying to print the whole buffer.
> >
> > Signed-off-by: Nelson Elhage <nelhage@ksplice.com>
>
> Only root can write to the pktgen control file.
>
> Also, the debug feature really is used by people's pktgen scripts, you
> can't just turn it off.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] pktgen: Remove a dangerous debug print.
2010-10-27 19:28 ` Nelson Elhage
@ 2010-10-27 19:30 ` David Miller
2010-10-27 19:41 ` Eric Dumazet
1 sibling, 0 replies; 20+ messages in thread
From: David Miller @ 2010-10-27 19:30 UTC (permalink / raw)
To: nelhage; +Cc: robert.olsson, linux-kernel, netdev, eugene
From: Nelson Elhage <nelhage@ksplice.com>
Date: Wed, 27 Oct 2010 15:28:08 -0400
> How would you feel about limiting the debug print to at most, say, 512 or 1024
> bytes? Even if it's only accessible to root by default, I don't a userspace
> program should be able to accidentally corrupt the kernel stack by writing too
> many bytes to a file in /proc.
Why not? He can just as easily "cat whatever >/dev/kmem" or similar?
And I'm sure there are other proc files that can cause similar damage
such as the PCI device control files.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] pktgen: Remove a dangerous debug print.
2010-10-27 19:28 ` Nelson Elhage
2010-10-27 19:30 ` David Miller
@ 2010-10-27 19:41 ` Eric Dumazet
2010-10-27 19:49 ` Nelson Elhage
1 sibling, 1 reply; 20+ messages in thread
From: Eric Dumazet @ 2010-10-27 19:41 UTC (permalink / raw)
To: Nelson Elhage; +Cc: David Miller, robert.olsson, linux-kernel, netdev, eugene
Le mercredi 27 octobre 2010 à 15:28 -0400, Nelson Elhage a écrit :
> How would you feel about limiting the debug print to at most, say, 512 or 1024
> bytes? Even if it's only accessible to root by default, I don't a userspace
> program should be able to accidentally corrupt the kernel stack by writing too
> many bytes to a file in /proc.
Arent /proc writes limited to PAGE_SIZE anyway ?
On x86 at least, you cannot corrupt kernel stack, since its bigger than
PAGE_SIZE.
I agree pktgen code is a bit ugly and needs a cleanup, but who
cares ? :)
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] pktgen: Remove a dangerous debug print.
2010-10-27 19:41 ` Eric Dumazet
@ 2010-10-27 19:49 ` Nelson Elhage
0 siblings, 0 replies; 20+ messages in thread
From: Nelson Elhage @ 2010-10-27 19:49 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David Miller, robert.olsson, linux-kernel, netdev, eugene
I tested this and was able to oops both amd64 and i386 test machines with 8k
writes to the pktgen file. I haven't investigated whether that's because there's
no PAGE_SIZE limit, or because one page ends up being enough to cause a problem
on all my test machines.
- Nelson
On Wed, Oct 27, 2010 at 09:41:39PM +0200, Eric Dumazet wrote:
> Le mercredi 27 octobre 2010 à 15:28 -0400, Nelson Elhage a écrit :
> > How would you feel about limiting the debug print to at most, say, 512 or 1024
> > bytes? Even if it's only accessible to root by default, I don't a userspace
> > program should be able to accidentally corrupt the kernel stack by writing too
> > many bytes to a file in /proc.
>
> Arent /proc writes limited to PAGE_SIZE anyway ?
>
> On x86 at least, you cannot corrupt kernel stack, since its bigger than
> PAGE_SIZE.
>
> I agree pktgen code is a bit ugly and needs a cleanup, but who
> cares ? :)
>
>
>
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] pktgen: Remove a dangerous debug print.
2010-10-27 19:13 [PATCH] pktgen: Remove a dangerous debug print Nelson Elhage
2010-10-27 19:21 ` David Miller
@ 2010-10-27 20:38 ` Ben Greear
2010-10-27 22:12 ` [patch] fix stack overflow in pktgen_if_write() Dan Carpenter
2010-10-28 15:20 ` [PATCH] pktgen: Limit how much data we copy onto the stack Nelson Elhage
3 siblings, 0 replies; 20+ messages in thread
From: Ben Greear @ 2010-10-27 20:38 UTC (permalink / raw)
To: Nelson Elhage; +Cc: Robert Olsson, linux-kernel, netdev, Eugene Teo
On 10/27/2010 12:13 PM, Nelson Elhage wrote:
> We were allocating an arbitrarily-large buffer on the stack, which would allow a
> buggy or malicious userspace program to overflow the kernel stack.
>
> Since the debug printk() was just printing exactly the text passed from
> userspace, it's probably just as easy for anyone who might use it to augment (or
> just strace(1)) the program writing to the pktgen file, so let's just not bother
> trying to print the whole buffer.
Maybe just allocate that buffer on the heap instead of stack?
Thanks,
Ben
--
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc http://www.candelatech.com
^ permalink raw reply [flat|nested] 20+ messages in thread
* [patch] fix stack overflow in pktgen_if_write()
2010-10-27 19:13 [PATCH] pktgen: Remove a dangerous debug print Nelson Elhage
2010-10-27 19:21 ` David Miller
2010-10-27 20:38 ` Ben Greear
@ 2010-10-27 22:12 ` Dan Carpenter
2010-10-27 22:40 ` Dan Carpenter
2010-10-27 22:43 ` [patch v2] " Dan Carpenter
2010-10-28 15:20 ` [PATCH] pktgen: Limit how much data we copy onto the stack Nelson Elhage
3 siblings, 2 replies; 20+ messages in thread
From: Dan Carpenter @ 2010-10-27 22:12 UTC (permalink / raw)
To: nelhage
Cc: Eric Dumazet, David S. Miller, Robert Olsson, Andy Shevchenko,
netdev
Nelson Elhage says he was able to oops both amd64 and i386 test
machines with 8k writes to the pktgen file. Let's just allocate the
buffer on the heap instead of on the stack.
This can only be triggered by root so there are no security issues here.
Reported-by: Nelson Elhage <nelhage@ksplice.com>
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
I saw this on twitter. Hi Nelson, could you test this?
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 2c0df0f..b5d3c70 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -887,12 +887,14 @@ 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))
- return -EFAULT;
- tb[count] = 0;
+ char *tb;
+
+ tb = strndup_user(user_buffer, count + 1);
+ if (IS_ERR(tb))
+ return PTR_ERR(tb);
printk(KERN_DEBUG "pktgen: %s,%lu buffer -:%s:-\n", name,
(unsigned long)count, tb);
+ kfree(tb);
}
if (!strcmp(name, "min_pkt_size")) {
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [patch] fix stack overflow in pktgen_if_write()
2010-10-27 22:12 ` [patch] fix stack overflow in pktgen_if_write() Dan Carpenter
@ 2010-10-27 22:40 ` Dan Carpenter
2010-10-27 22:43 ` [patch v2] " Dan Carpenter
1 sibling, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2010-10-27 22:40 UTC (permalink / raw)
To: nelhage
Cc: Eric Dumazet, David S. Miller, Robert Olsson, Andy Shevchenko,
netdev
On Thu, Oct 28, 2010 at 12:12:35AM +0200, Dan Carpenter wrote:
> - char tb[count + 1];
> - if (copy_from_user(tb, user_buffer, count))
> - return -EFAULT;
> - tb[count] = 0;
> + char *tb;
> +
> + tb = strndup_user(user_buffer, count + 1);
Crap... This should be memdup_user().
Sorry about that. I'll send v2.
regards,
dan carpenter
> + if (IS_ERR(tb))
> + return PTR_ERR(tb);
> printk(KERN_DEBUG "pktgen: %s,%lu buffer -:%s:-\n", name,
> (unsigned long)count, tb);
> + kfree(tb);
> }
>
> if (!strcmp(name, "min_pkt_size")) {
^ permalink raw reply [flat|nested] 20+ messages in thread
* [patch v2] fix stack overflow in pktgen_if_write()
2010-10-27 22:12 ` [patch] fix stack overflow in pktgen_if_write() Dan Carpenter
2010-10-27 22:40 ` Dan Carpenter
@ 2010-10-27 22:43 ` Dan Carpenter
2010-10-27 23:06 ` Nelson Elhage
1 sibling, 1 reply; 20+ messages in thread
From: Dan Carpenter @ 2010-10-27 22:43 UTC (permalink / raw)
To: nelhage
Cc: Eric Dumazet, David S. Miller, Robert Olsson, Andy Shevchenko,
netdev
Nelson Elhage says he was able to oops both amd64 and i386 test
machines with 8k writes to the pktgen file. Let's just allocate the
buffer on the heap instead of on the stack.
This can only be triggered by root so there are no security issues here.
Reported-by: Nelson Elhage <nelhage@ksplice.com>
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
I saw this on twitter. Hi Nelson, could you test this?
V2: strndup_user() => memdup_user()
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 2c0df0f..b5d3c70 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -887,12 +887,14 @@ 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))
- return -EFAULT;
- tb[count] = 0;
+ char *tb;
+
+ tb = memdup_user(user_buffer, count + 1);
+ if (IS_ERR(tb))
+ return PTR_ERR(tb);
printk(KERN_DEBUG "pktgen: %s,%lu buffer -:%s:-\n", name,
(unsigned long)count, tb);
+ kfree(tb);
}
if (!strcmp(name, "min_pkt_size")) {
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [patch v2] fix stack overflow in pktgen_if_write()
2010-10-27 22:43 ` [patch v2] " Dan Carpenter
@ 2010-10-27 23:06 ` Nelson Elhage
2010-10-28 6:05 ` Dan Carpenter
2010-10-28 6:05 ` [patch v3] " Dan Carpenter
0 siblings, 2 replies; 20+ messages in thread
From: Nelson Elhage @ 2010-10-27 23:06 UTC (permalink / raw)
To: Dan Carpenter
Cc: Eric Dumazet, David S. Miller, Robert Olsson, Andy Shevchenko,
netdev
You want to add a trailing NUL, or else printk will read off the end of the
buffer.
Also, by memdup()ing count + 1 bytes, you're technically reading one more byte
than userspace asked for, which could in principle lead to a spurious EFAULT.
- Nelson
On Thu, Oct 28, 2010 at 12:43:02AM +0200, Dan Carpenter wrote:
> Nelson Elhage says he was able to oops both amd64 and i386 test
> machines with 8k writes to the pktgen file. Let's just allocate the
> buffer on the heap instead of on the stack.
>
> This can only be triggered by root so there are no security issues here.
>
> Reported-by: Nelson Elhage <nelhage@ksplice.com>
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
> I saw this on twitter. Hi Nelson, could you test this?
>
> V2: strndup_user() => memdup_user()
>
> diff --git a/net/core/pktgen.c b/net/core/pktgen.c
> index 2c0df0f..b5d3c70 100644
> --- a/net/core/pktgen.c
> +++ b/net/core/pktgen.c
> @@ -887,12 +887,14 @@ 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))
> - return -EFAULT;
> - tb[count] = 0;
> + char *tb;
> +
> + tb = memdup_user(user_buffer, count + 1);
> + if (IS_ERR(tb))
> + return PTR_ERR(tb);
> printk(KERN_DEBUG "pktgen: %s,%lu buffer -:%s:-\n", name,
> (unsigned long)count, tb);
> + kfree(tb);
> }
>
> if (!strcmp(name, "min_pkt_size")) {
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [patch v2] fix stack overflow in pktgen_if_write()
2010-10-27 23:06 ` Nelson Elhage
@ 2010-10-28 6:05 ` Dan Carpenter
2010-10-28 6:05 ` [patch v3] " Dan Carpenter
1 sibling, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2010-10-28 6:05 UTC (permalink / raw)
To: Nelson Elhage
Cc: Eric Dumazet, David S. Miller, Robert Olsson, Andy Shevchenko,
netdev
On Wed, Oct 27, 2010 at 07:06:57PM -0400, Nelson Elhage wrote:
> You want to add a trailing NUL, or else printk will read off the end of the
> buffer.
>
> Also, by memdup()ing count + 1 bytes, you're technically reading one more byte
> than userspace asked for, which could in principle lead to a spurious EFAULT.
>
That's a lot of bugs per line. :( I'm eating humble pie today...
regards,
dan carpenter
^ permalink raw reply [flat|nested] 20+ messages in thread
* [patch v3] fix stack overflow in pktgen_if_write()
2010-10-27 23:06 ` Nelson Elhage
2010-10-28 6:05 ` Dan Carpenter
@ 2010-10-28 6:05 ` Dan Carpenter
2010-10-28 15:22 ` Nelson Elhage
2010-10-28 23:11 ` Andi Kleen
1 sibling, 2 replies; 20+ messages in thread
From: Dan Carpenter @ 2010-10-28 6:05 UTC (permalink / raw)
To: Nelson Elhage
Cc: Eric Dumazet, David S. Miller, Robert Olsson, Andy Shevchenko,
netdev
Nelson Elhage says he was able to oops both amd64 and i386 test
machines with 8k writes to the pktgen file. Let's just allocate the
buffer on the heap instead of on the stack.
This can only be triggered by root so there are no security issues here.
Reported-by: Nelson Elhage <nelhage@ksplice.com>
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
v3: just use kmalloc()
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 2c0df0f..c8d3620 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -887,12 +887,17 @@ static ssize_t pktgen_if_write(struct file *file,
i += len;
if (debug) {
- char tb[count + 1];
+ char *tb;
+
+ tb = kmalloc(count + 1, GFP_KERNEL);
+ if (!tb)
+ return -ENOMEM;
if (copy_from_user(tb, user_buffer, count))
return -EFAULT;
tb[count] = 0;
printk(KERN_DEBUG "pktgen: %s,%lu buffer -:%s:-\n", name,
(unsigned long)count, tb);
+ kfree(tb);
}
if (!strcmp(name, "min_pkt_size")) {
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH] pktgen: Limit how much data we copy onto the stack.
2010-10-27 19:13 [PATCH] pktgen: Remove a dangerous debug print Nelson Elhage
` (2 preceding siblings ...)
2010-10-27 22:12 ` [patch] fix stack overflow in pktgen_if_write() Dan Carpenter
@ 2010-10-28 15:20 ` Nelson Elhage
2010-10-28 18:32 ` David Miller
3 siblings, 1 reply; 20+ messages in thread
From: Nelson Elhage @ 2010-10-28 15:20 UTC (permalink / raw)
To: David S. Miller
Cc: Eric Dumazet, Robert Olsson, Andy Shevchenko, netdev, Eugene Teo,
Nelson Elhage
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>
---
While testing Dan's patch, I realized the printk() limitation, so I don't think
there's any reason to need a kmalloc() at all. I've tested this on a
CONFIG_4KSTACKS kernel, and copying 1k works fine.
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 10a1ea7..d6667cf 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -889,10 +889,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);
}
--
1.7.1.31.g6297e
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [patch v3] fix stack overflow in pktgen_if_write()
2010-10-28 6:05 ` [patch v3] " Dan Carpenter
@ 2010-10-28 15:22 ` Nelson Elhage
2010-10-28 16:28 ` Dan Carpenter
2010-10-28 23:11 ` Andi Kleen
1 sibling, 1 reply; 20+ messages in thread
From: Nelson Elhage @ 2010-10-28 15:22 UTC (permalink / raw)
To: Dan Carpenter
Cc: Eric Dumazet, David S. Miller, Robert Olsson, Andy Shevchenko,
netdev
You've got a leak if copy_user fails.
While testing this, I realized that printk() won't print more than 1k in a
single call, anyways, so I've sent along a patch that just copies up to 1k onto
the stack, which should prevent the overflow without changing behavior or
needing a heap allocation.
- Nelson
On Thu, Oct 28, 2010 at 08:05:29AM +0200, Dan Carpenter wrote:
> Nelson Elhage says he was able to oops both amd64 and i386 test
> machines with 8k writes to the pktgen file. Let's just allocate the
> buffer on the heap instead of on the stack.
>
> This can only be triggered by root so there are no security issues here.
>
> Reported-by: Nelson Elhage <nelhage@ksplice.com>
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
> v3: just use kmalloc()
>
> diff --git a/net/core/pktgen.c b/net/core/pktgen.c
> index 2c0df0f..c8d3620 100644
> --- a/net/core/pktgen.c
> +++ b/net/core/pktgen.c
> @@ -887,12 +887,17 @@ static ssize_t pktgen_if_write(struct file *file,
> i += len;
>
> if (debug) {
> - char tb[count + 1];
> + char *tb;
> +
> + tb = kmalloc(count + 1, GFP_KERNEL);
> + if (!tb)
> + return -ENOMEM;
> if (copy_from_user(tb, user_buffer, count))
> return -EFAULT;
> tb[count] = 0;
> printk(KERN_DEBUG "pktgen: %s,%lu buffer -:%s:-\n", name,
> (unsigned long)count, tb);
> + kfree(tb);
> }
>
> if (!strcmp(name, "min_pkt_size")) {
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [patch v3] fix stack overflow in pktgen_if_write()
2010-10-28 15:22 ` Nelson Elhage
@ 2010-10-28 16:28 ` Dan Carpenter
2010-10-28 16:30 ` Nelson Elhage
0 siblings, 1 reply; 20+ messages in thread
From: Dan Carpenter @ 2010-10-28 16:28 UTC (permalink / raw)
To: Nelson Elhage
Cc: Eric Dumazet, David S. Miller, Robert Olsson, Andy Shevchenko,
netdev
On Thu, Oct 28, 2010 at 11:22:22AM -0400, Nelson Elhage wrote:
> You've got a leak if copy_user fails.
>
My QC scripts should have caught that, but they didn't... I'll figure
it out. It shouldn't happen again.
> While testing this, I realized that printk() won't print more than 1k in a
> single call, anyways, so I've sent along a patch that just copies up to 1k onto
> the stack, which should prevent the overflow without changing behavior or
> needing a heap allocation.
>
Ok. Good to hear. Sorry I wasted people's time.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [patch v3] fix stack overflow in pktgen_if_write()
2010-10-28 16:28 ` Dan Carpenter
@ 2010-10-28 16:30 ` Nelson Elhage
0 siblings, 0 replies; 20+ messages in thread
From: Nelson Elhage @ 2010-10-28 16:30 UTC (permalink / raw)
To: Dan Carpenter
Cc: Eric Dumazet, David S. Miller, Robert Olsson, Andy Shevchenko,
netdev
On Thu, Oct 28, 2010 at 06:28:25PM +0200, Dan Carpenter wrote:
> On Thu, Oct 28, 2010 at 11:22:22AM -0400, Nelson Elhage wrote:
> > You've got a leak if copy_user fails.
> >
>
> My QC scripts should have caught that, but they didn't... I'll figure
> it out. It shouldn't happen again.
>
> > While testing this, I realized that printk() won't print more than 1k in a
> > single call, anyways, so I've sent along a patch that just copies up to 1k onto
> > the stack, which should prevent the overflow without changing behavior or
> > needing a heap allocation.
> >
>
> Ok. Good to hear. Sorry I wasted people's time.
No worries. I appreciate you jumping in to help, even if it looks like the
approach wasn't needed in the end.
- Nelson
>
> regards,
> dan carpenter
>
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] pktgen: Limit how much data we copy onto the stack.
2010-10-28 15:20 ` [PATCH] pktgen: Limit how much data we copy onto the stack Nelson Elhage
@ 2010-10-28 18:32 ` David Miller
0 siblings, 0 replies; 20+ messages in thread
From: David Miller @ 2010-10-28 18:32 UTC (permalink / raw)
To: nelhage; +Cc: eric.dumazet, robert.olsson, andy.shevchenko, netdev, eugene
From: Nelson Elhage <nelhage@ksplice.com>
Date: Thu, 28 Oct 2010 11:20:42 -0400
> 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>
Applied, thanks a lot.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [patch v3] fix stack overflow in pktgen_if_write()
2010-10-28 6:05 ` [patch v3] " Dan Carpenter
2010-10-28 15:22 ` Nelson Elhage
@ 2010-10-28 23:11 ` Andi Kleen
2010-11-01 3:47 ` Dan Carpenter
1 sibling, 1 reply; 20+ messages in thread
From: Andi Kleen @ 2010-10-28 23:11 UTC (permalink / raw)
To: Dan Carpenter
Cc: Nelson Elhage, Eric Dumazet, David S. Miller, Robert Olsson,
Andy Shevchenko, netdev
Dan Carpenter <error27@gmail.com> writes:
> Reported-by: Nelson Elhage <nelhage@ksplice.com>
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
> v3: just use kmalloc()
>
> diff --git a/net/core/pktgen.c b/net/core/pktgen.c
> index 2c0df0f..c8d3620 100644
> --- a/net/core/pktgen.c
> +++ b/net/core/pktgen.c
> @@ -887,12 +887,17 @@ static ssize_t pktgen_if_write(struct file *file,
> i += len;
>
> if (debug) {
> - char tb[count + 1];
> + char *tb;
> +
> + tb = kmalloc(count + 1, GFP_KERNEL);
This is still trivially exploitable (for root) -- think what happens
when count is near ULONG_MAX
-Andi
--
ak@linux.intel.com -- Speaking for myself only.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [patch v3] fix stack overflow in pktgen_if_write()
2010-10-28 23:11 ` Andi Kleen
@ 2010-11-01 3:47 ` Dan Carpenter
0 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2010-11-01 3:47 UTC (permalink / raw)
To: Andi Kleen
Cc: Nelson Elhage, Eric Dumazet, David S. Miller, Robert Olsson,
Andy Shevchenko, netdev
> > @@ -887,12 +887,17 @@ static ssize_t pktgen_if_write(struct file *file,
> > i += len;
> >
> > if (debug) {
> > - char tb[count + 1];
> > + char *tb;
> > +
> > + tb = kmalloc(count + 1, GFP_KERNEL);
>
>
> This is still trivially exploitable (for root) -- think what happens
> when count is near ULONG_MAX
>
In vfs_write() we call rw_verify_area() which caps count at INT_MAX or
LONG_MAX.
if (unlikely((ssize_t) count < 0))
return retval;
So I get lucky this time... ;)
regards,
dan carpenter
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2010-11-01 3:47 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-27 19:13 [PATCH] pktgen: Remove a dangerous debug print Nelson Elhage
2010-10-27 19:21 ` David Miller
2010-10-27 19:28 ` Nelson Elhage
2010-10-27 19:30 ` David Miller
2010-10-27 19:41 ` Eric Dumazet
2010-10-27 19:49 ` Nelson Elhage
2010-10-27 20:38 ` Ben Greear
2010-10-27 22:12 ` [patch] fix stack overflow in pktgen_if_write() Dan Carpenter
2010-10-27 22:40 ` Dan Carpenter
2010-10-27 22:43 ` [patch v2] " Dan Carpenter
2010-10-27 23:06 ` Nelson Elhage
2010-10-28 6:05 ` Dan Carpenter
2010-10-28 6:05 ` [patch v3] " Dan Carpenter
2010-10-28 15:22 ` Nelson Elhage
2010-10-28 16:28 ` Dan Carpenter
2010-10-28 16:30 ` Nelson Elhage
2010-10-28 23:11 ` Andi Kleen
2010-11-01 3:47 ` Dan Carpenter
2010-10-28 15:20 ` [PATCH] pktgen: Limit how much data we copy onto the stack Nelson Elhage
2010-10-28 18:32 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).