* [PATCH] pktgen: Remove a dangerous debug print.
@ 2010-10-27 19:13 Nelson Elhage
2010-10-27 19:21 ` David Miller
2010-10-27 20:38 ` Ben Greear
0 siblings, 2 replies; 7+ 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] 7+ 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
1 sibling, 1 reply; 7+ 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] 7+ 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; 7+ 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] 7+ 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; 7+ 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] 7+ 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; 7+ 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] 7+ 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; 7+ 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] 7+ 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
1 sibling, 0 replies; 7+ 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] 7+ messages in thread
end of thread, other threads:[~2010-10-27 20:39 UTC | newest]
Thread overview: 7+ 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox