re
as exposed by xntpd (that does smth similar to what is done
in watchdogd(8)) setting stack limit lower than current usage
produces SIGSEGV on return from syscall which is not possible
to handle anyhow as per posix this SIGSEGV cannot be caught
or ignored (:
thus the diff (from netbsd ;)
there is a regress i added earlier that demonstrates the problem.
any comments?
cu
-- 
    paranoic mickey       (my employers have changed but, the name has remained)

Index: kern_resource.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_resource.c,v
retrieving revision 1.2
diff -u -p -r1.2 kern_resource.c
--- kern_resource.c     26 Dec 2008 18:51:49 -0000      1.2
+++ kern_resource.c     15 Jun 2009 20:30:17 -0000
@@ -259,6 +259,16 @@ dosetrlimit(struct proc *p, u_int which,
 
        if (which == RLIMIT_STACK) {
                /*
+                * Return EINVAL if the new stack size limit is lower than
+                * current usage. Otherwise, the process would get SIGSEGV the
+                * moment it would try to access anything on it's current stack.
+                * This conforms to SUSv2.
+                */   
+               if (limp->rlim_cur < p->p_vmspace->vm_ssize * PAGE_SIZE ||
+                   limp->rlim_max < p->p_vmspace->vm_ssize * PAGE_SIZE)
+                       return (EINVAL);
+
+               /*
                 * Stack is allocated to the max at exec time with only
                 * "rlim_cur" bytes accessible.  If stack limit is going
                 * up make more accessible, if going down make inaccessible.

Reply via email to