Subject: Re: kernel stack overflow detection
To: None <eeh@netbsd.org, yamt@mwd.biglobe.ne.jp>
From: None <eeh@netbsd.org>
List: tech-kern
Date: 06/26/2002 18:56:30
| From: eeh@netbsd.org
| Subject: Re: kernel stack overflow detection
| Date: 26 Jun 2002 17:14:16 -0000
|
| > | there're 2 things. (sorry for confusing)
| > |
| > | KSTACK_CHECK_MAGIC is (intended to be) MI.
| > | KSTACK_CHECK_DR0 is i386-specific.
| > 
| > So, does KSTACK_CHECK_MAGIC work without any MD changes?
| > If not, what MD changes are needed?
|
| if kernel stack range on the arch can be calculated by
| macros on sys/proc.h (KSTACK_{END,SIZE} in my patch),
| no MD changes are needed.
| if it can't, you need to override these macros.

Looking at the actual code...  you have:

#define	KSTACK_END(p)	((caddr_t)ALIGN((p)->p_addr + 1))

which will give this pointer alignment and:

#define	KSTACK_SIZE	(USPACE - sizeof(struct user))

then do:

+	ip = (u_int32_t *)KSTACK_END(p);
+	end = (u_int32_t *)((caddr_t)KSTACK_END(p) + KSTACK_SIZE); 
+	for (; ip < end; ip++) {
+		*ip = KSTACK_MAGIC;
+	}

Now, isn't there some danger that due to rounding
(KSTACK_END(p) + KSTACK_SIZE) may fall off the end of a page?

Will this also work with machines which have stacks that grow
up instead of stacks that grow down?

Eduardo