Subject: kern/3379: Exec fails if stack limit is not on page boundary.
To: None <gnats-bugs@gnats.netbsd.org>
From: None <enami@ba2.so-net.or.jp>
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
>Last-Modified:
>Originator:     enami tsugutomo
>Organization:
	an individual
>Release:        NetBSD-current 1997 Mar. 20
>Environment:
System: NetBSD plants-doll.enami.ba2.so-net.or.jp 1.2D NetBSD 1.2D (PLANTS_DOLL) #265: Sat Mar 22 14:20:51 JST 1997 enami@plants-doll.enami.ba2.so-net.or.jp:/usr/src/sys/arch/i386/compile/PLANTS_DOLL i386


>Description:
	Exec fails if stack limit is not on page boundary.
>How-To-Repeat:
	Following shell script (or any equivalent C/csh/... program) fails.

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

>Fix:
	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
	boundary).

	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.
>Audit-Trail:
>Unformatted: