stack overflow

Breno
2003-09-12T21:55:22Z

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