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
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/
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
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" <[email protected]>
To: "Breno" <[email protected]>; "Kernel List"
<[email protected]>
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 [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
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
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
I think that size limit of user stack is 8mb
Breno
----- Original Message -----
From: "Andreas Dilger" <[email protected]>
To: "Breno" <[email protected]>
Cc: "Kernel List" <[email protected]>
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 [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/