Subject: kern/3379: Exec fails if stack limit is not on page boundary.
To: None <>
From: None <>
List: netbsd-bugs
Date: 03/22/1997 15:06:55
>Number:         3379
>Category:       kern
>Synopsis:       Exec fails if stack limit is not on page boundary.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 21 22:20:02 1997
>Originator:     enami tsugutomo
	an individual
>Release:        NetBSD-current 1997 Mar. 20
System: NetBSD 1.2D NetBSD 1.2D (PLANTS_DOLL) #265: Sat Mar 22 14:20:51 JST 1997 i386

	Exec fails if stack limit is not on page boundary.
	Following shell script (or any equivalent C/csh/... program) fails.

enami@plants-doll% cat hoge
ulimit -s
ulimit -s 513
ulimit -s
exec /bin/pwd
enami@plants-doll% ./hoge
Abort trap

	This is because vm_allocate() for stack area fails.

	In the function exec_aout_setup_stack(), it tries to setup two
	contiguous regions for stack space without considering page
	boundary.  But in vm_allocate(), which is called via
	vmcmd_map_zero(), start address of region is automatically
	truncated to page boundary (but length are left unchanged).
	Thus, if boundary of the regions are not on page boundary,
	they overlaps and later request of allocate fails.

	So, to fix this, adjust boundary of the regions to page
	boundary in exec_aout_setup_stack() or make
	p->p_rlimit[RLIMIT_STACK].rlim_cur always to fit page boundary
	when setting (if maxsaddr and minsaddr are already on page

	Note that function exec_ecoff_setup_stack() is very similar to
	exec_aout_setup_stack(), so if the latter is needed to be
	modified, former also may needed.