* stack overflow
@ 2003-09-12 17:53 Breno
2003-09-12 22:50 ` Andreas Dilger
0 siblings, 1 reply; 8+ messages in thread
From: Breno @ 2003-09-12 17:53 UTC (permalink / raw)
To: Kernel List
Hi ... this is my idea to check a stack overflow. What do you think ?
#define STACK_LIMIT (1024*8192)/PAGE_SIZE
int check_stack_overflow(struct task_struct *tsk)
{
unsigned long stack_size,stack_addr,stack_ptr;
int i;
if(tsk->mm != NULL)
{
stack_addr = tsk->mm->start_stack;
stack_ptr = tsk->thread.esp;
for(i=0; i < stack_ptr; i++)
stack_addr++;
stack_size = (stack_addr - stack_ptr)/PAGE_SIZE;
if(stack_size > ( STACK_LIMIT - 1))
{
printk(KERN_CRIT"Process %s : pid %d -
Can cause stack
overflow\n",tsk->comm,tsk->pid);
return 0;
}
}
return 0;
}
att,
Breno
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: stack overflow
2003-09-12 22:50 ` Andreas Dilger
@ 2003-09-12 19:14 ` Breno
2003-09-12 23:06 ` William Lee Irwin III
1 sibling, 0 replies; 8+ messages in thread
From: Breno @ 2003-09-12 19:14 UTC (permalink / raw)
To: Andreas Dilger; +Cc: Kernel List
I think that size limit of user stack is 8mb
Breno
----- Original Message -----
From: "Andreas Dilger" <adilger@clusterfs.com>
To: "Breno" <brenosp@brasilsec.com.br>
Cc: "Kernel List" <linux-kernel@vger.kernel.org>
Sent: Friday, September 12, 2003 11:50 PM
Subject: Re: stack overflow
> On Sep 12, 2003 18:53 +0100, Breno wrote:
> > Hi ... this is my idea to check a stack overflow. What do you think ?
> >
> > #define STACK_LIMIT (1024*8192)/PAGE_SIZE
> >
> > int check_stack_overflow(struct task_struct *tsk)
> > {
> >
> > unsigned long stack_size,stack_addr,stack_ptr;
> > int i;
> >
> > if(tsk->mm != NULL)
> > {
> > stack_addr = tsk->mm->start_stack;
> >
> > stack_ptr = tsk->thread.esp;
> >
> > for(i=0; i < stack_ptr; i++)
> > stack_addr++;
> >
> > stack_size = (stack_addr - stack_ptr)/PAGE_SIZE;
> >
> > if(stack_size > ( STACK_LIMIT - 1))
>
> Well, with the exception of the fact that STACK_LIMIT is 8MB, and kernel
> stacks are only 8kB (on i386)...
>
> Also, see "do_IRQ()" (i386) for CONFIG_DEBUG_STACKOVERFLOW to see this
already.
>
> Cheers, Andreas
> --
> Andreas Dilger
> http://sourceforge.net/projects/ext2resize/
> http://www-mddsp.enel.ucalgary.ca/People/adilger/
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: stack overflow
2003-09-12 23:06 ` William Lee Irwin III
@ 2003-09-12 19:23 ` Breno
2003-09-12 23:18 ` Alan Cox
1 sibling, 0 replies; 8+ messages in thread
From: Breno @ 2003-09-12 19:23 UTC (permalink / raw)
To: William Lee Irwin III, Kernel List
Wli,
Exactly that stack users are demand paged , you can calculate the size of
stack. This is will impossible or more difficult to do if you have more that
one mm->start_stack :)
att
Breno
----- Original Message -----
From: "William Lee Irwin III" <wli@holomorphy.com>
To: "Breno" <brenosp@brasilsec.com.br>; "Kernel List"
<linux-kernel@vger.kernel.org>
Sent: Saturday, September 13, 2003 12:06 AM
Subject: Re: stack overflow
> On Fri, Sep 12, 2003 at 04:50:47PM -0600, Andreas Dilger wrote:
> > Well, with the exception of the fact that STACK_LIMIT is 8MB, and kernel
> > stacks are only 8kB (on i386)...
> > Also, see "do_IRQ()" (i386) for CONFIG_DEBUG_STACKOVERFLOW to see this
already.
>
> What he actually wants is in-kernel user stack overflow checking, which
> is basically impossible since user stacks are demand paged. He's been
> told this before and failed to absorb it.
>
> There have been attempts to use i386 segmentation for stack limit
> checks written but they should probably not be confused with this.
>
>
> -- wli
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: stack overflow
2003-09-12 17:53 stack overflow Breno
@ 2003-09-12 22:50 ` Andreas Dilger
2003-09-12 19:14 ` Breno
2003-09-12 23:06 ` William Lee Irwin III
0 siblings, 2 replies; 8+ messages in thread
From: Andreas Dilger @ 2003-09-12 22:50 UTC (permalink / raw)
To: Breno; +Cc: Kernel List
On Sep 12, 2003 18:53 +0100, Breno wrote:
> Hi ... this is my idea to check a stack overflow. What do you think ?
>
> #define STACK_LIMIT (1024*8192)/PAGE_SIZE
>
> int check_stack_overflow(struct task_struct *tsk)
> {
>
> unsigned long stack_size,stack_addr,stack_ptr;
> int i;
>
> if(tsk->mm != NULL)
> {
> stack_addr = tsk->mm->start_stack;
>
> stack_ptr = tsk->thread.esp;
>
> for(i=0; i < stack_ptr; i++)
> stack_addr++;
>
> stack_size = (stack_addr - stack_ptr)/PAGE_SIZE;
>
> if(stack_size > ( STACK_LIMIT - 1))
Well, with the exception of the fact that STACK_LIMIT is 8MB, and kernel
stacks are only 8kB (on i386)...
Also, see "do_IRQ()" (i386) for CONFIG_DEBUG_STACKOVERFLOW to see this already.
Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: stack overflow
2003-09-12 22:50 ` Andreas Dilger
2003-09-12 19:14 ` Breno
@ 2003-09-12 23:06 ` William Lee Irwin III
2003-09-12 19:23 ` Breno
2003-09-12 23:18 ` Alan Cox
1 sibling, 2 replies; 8+ messages in thread
From: William Lee Irwin III @ 2003-09-12 23:06 UTC (permalink / raw)
To: Breno, Kernel List
On Fri, Sep 12, 2003 at 04:50:47PM -0600, Andreas Dilger wrote:
> Well, with the exception of the fact that STACK_LIMIT is 8MB, and kernel
> stacks are only 8kB (on i386)...
> Also, see "do_IRQ()" (i386) for CONFIG_DEBUG_STACKOVERFLOW to see this already.
What he actually wants is in-kernel user stack overflow checking, which
is basically impossible since user stacks are demand paged. He's been
told this before and failed to absorb it.
There have been attempts to use i386 segmentation for stack limit
checks written but they should probably not be confused with this.
-- wli
^ permalink raw reply [flat|nested] 8+ messages in thread
* stack overflow - kernel thread
2003-09-12 23:25 ` William Lee Irwin III
@ 2003-09-12 23:18 ` Breno
0 siblings, 0 replies; 8+ messages in thread
From: Breno @ 2003-09-12 23:18 UTC (permalink / raw)
To: William Lee Irwin III, Alan Cox; +Cc: Linux Kernel Mailing List
Hi .... this worked
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/unistd.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/highmem.h>
#include <linux/string.h>
#include <asm/uaccess.h>
#include <asm/errno.h>
#include <asm/mman.h>
#include <asm/page.h>
#include <asm/pgalloc.h>
#include <asm/processor.h>
#include <asm-i386/vm86.h>
#define THREAD 1
#define STACK_LIMIT 8192
int check_stack()
{
struct task_struct *p = NULL;
struct vm_area_struct *vma;
unsigned long stack_size, stack_addr, stack_ptr;
daemonize();
sprintf(current->comm,"CHECK_STACK");
for(;;schedule())
{
for_each_task(p)
{
if((p->mm != NULL) && (p->pid != 1))
{
stack_addr = p->mm->start_stack;
stack_ptr = p->thread.esp;
vma = find_vma(p->mm,stack_addr);
if(!vma)
return 0;
stack_size = (vma->vm_end - vma->vm_start)/PAGE_SIZE;
if(stack_size >= (STACK_LIMIT - 1024))
{
printk(KERN_CRIT"Process %s pid: %d\n",p->comm,p->pid);
printk(KERN_CRIT"Stack size %lu k\n",stack_size);
vma->vm_flags &= ~(VM_WRITE | VM_GROWSDOWN);
return 0;
}
}
}
}
return 0;
}
int init_module()
{
int th_pid[THREAD];
int i;
for(i = 0;i < THREAD;i++)
th_pid[i] = kernel_thread(check_stack,NULL,CLONE_SIGHAND);
if(th_pid[i] < 0)
printk(KERN_CRIT"Cannot create thread\n");
return 0;
}
void cleanup_module()
{
}
att,
Breno
----- Original Message -----
From: "William Lee Irwin III" <wli@holomorphy.com>
To: "Alan Cox" <alan@lxorguk.ukuu.org.uk>
Cc:
"Breno" <brenosp@brasilsec.com.br>; "Linux Kernel Mailing List"
<linux-kernel@vger.kernel.org>
Sent: Saturday, September 13, 2003 12:25 AM
Subject: Re: stack overflow
> On Sad, 2003-09-13 at 00:06, William Lee Irwin III wrote:
> >> What he actually wants is in-kernel user stack overflow checking, which
> >> is basically impossible since user stacks are demand paged. He's been
> >> told this before and failed to absorb it.
>
> On Sat, Sep 13, 2003 at 12:18:32AM +0100, Alan Cox wrote:
> > We will fault and error on a user stack exceed. You need to use
> > sigaltstack to catch it for obvious reasons. You can also use mmap and
> > drop in red zones on user space stacks
>
> Stack rlimits are fine and we already do those; the rest sounds like
> something userspace has to do.
>
>
> -- wli
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: stack overflow
2003-09-12 23:06 ` William Lee Irwin III
2003-09-12 19:23 ` Breno
@ 2003-09-12 23:18 ` Alan Cox
2003-09-12 23:25 ` William Lee Irwin III
1 sibling, 1 reply; 8+ messages in thread
From: Alan Cox @ 2003-09-12 23:18 UTC (permalink / raw)
To: William Lee Irwin III; +Cc: Breno, Linux Kernel Mailing List
On Sad, 2003-09-13 at 00:06, William Lee Irwin III wrote:
> What he actually wants is in-kernel user stack overflow checking, which
> is basically impossible since user stacks are demand paged. He's been
> told this before and failed to absorb it.
We will fault and error on a user stack exceed. You need to use
sigaltstack to catch it for obvious reasons. You can also use mmap and
drop in red zones on user space stacks
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: stack overflow
2003-09-12 23:18 ` Alan Cox
@ 2003-09-12 23:25 ` William Lee Irwin III
2003-09-12 23:18 ` stack overflow - kernel thread Breno
0 siblings, 1 reply; 8+ messages in thread
From: William Lee Irwin III @ 2003-09-12 23:25 UTC (permalink / raw)
To: Alan Cox; +Cc: Breno, Linux Kernel Mailing List
On Sad, 2003-09-13 at 00:06, William Lee Irwin III wrote:
>> What he actually wants is in-kernel user stack overflow checking, which
>> is basically impossible since user stacks are demand paged. He's been
>> told this before and failed to absorb it.
On Sat, Sep 13, 2003 at 12:18:32AM +0100, Alan Cox wrote:
> We will fault and error on a user stack exceed. You need to use
> sigaltstack to catch it for obvious reasons. You can also use mmap and
> drop in red zones on user space stacks
Stack rlimits are fine and we already do those; the rest sounds like
something userspace has to do.
-- wli
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2003-09-13 3:19 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-12 17:53 stack overflow Breno
2003-09-12 22:50 ` Andreas Dilger
2003-09-12 19:14 ` Breno
2003-09-12 23:06 ` William Lee Irwin III
2003-09-12 19:23 ` Breno
2003-09-12 23:18 ` Alan Cox
2003-09-12 23:25 ` William Lee Irwin III
2003-09-12 23:18 ` stack overflow - kernel thread Breno
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®