Module Name: src Committed By: christos Date: Mon Aug 23 20:53:08 UTC 2010
Modified Files: src/sys/kern: exec_subr.c kern_pax.c Log Message: Fix issues with stack allocation and pax aslr: - since the size is unsigned, don't check just that it is > 0, but limit it to the MAXSSIZ - if the stack size is reduced because of aslr, make sure we reduce the actual allocation by the same size so that the size does not wrap around. NB: Must be pulled up to 5.x! To generate a diff of this commit: cvs rdiff -u -r1.64 -r1.65 src/sys/kern/exec_subr.c cvs rdiff -u -r1.23 -r1.24 src/sys/kern/kern_pax.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/exec_subr.c diff -u src/sys/kern/exec_subr.c:1.64 src/sys/kern/exec_subr.c:1.65 --- src/sys/kern/exec_subr.c:1.64 Thu Jun 24 09:03:11 2010 +++ src/sys/kern/exec_subr.c Mon Aug 23 16:53:08 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: exec_subr.c,v 1.64 2010/06/24 13:03:11 hannken Exp $ */ +/* $NetBSD: exec_subr.c,v 1.65 2010/08/23 20:53:08 christos Exp $ */ /* * Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.64 2010/06/24 13:03:11 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.65 2010/08/23 20:53:08 christos Exp $"); #include "opt_pax.h" @@ -388,6 +388,7 @@ epp->ep_minsaddr = USRSTACK; max_stack_size = MAXSSIZ; } + epp->ep_ssize = l->l_proc->p_rlimit[RLIMIT_STACK].rlim_cur; #ifdef PAX_ASLR pax_aslr_stack(l, epp, &max_stack_size); @@ -397,7 +398,6 @@ epp->ep_maxsaddr = (vaddr_t)STACK_GROW(epp->ep_minsaddr, max_stack_size); - epp->ep_ssize = l->l_proc->p_rlimit[RLIMIT_STACK].rlim_cur; /* * set up commands for stack. note that this takes *two*, one to @@ -412,11 +412,11 @@ noaccess_size = max_stack_size - access_size; noaccess_linear_min = (vaddr_t)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr, access_size), noaccess_size); - if (noaccess_size > 0) { + if (noaccess_size > 0 && noaccess_size <= MAXSSIZ) { NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size, noaccess_linear_min, NULL, 0, VM_PROT_NONE, VMCMD_STACK); } - KASSERT(access_size > 0); + KASSERT(access_size > 0 && access_size <= MAXSSIZ); NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, access_size, access_linear_min, NULL, 0, VM_PROT_READ | VM_PROT_WRITE, VMCMD_STACK); Index: src/sys/kern/kern_pax.c diff -u src/sys/kern/kern_pax.c:1.23 src/sys/kern/kern_pax.c:1.24 --- src/sys/kern/kern_pax.c:1.23 Mon Mar 15 16:35:20 2010 +++ src/sys/kern/kern_pax.c Mon Aug 23 16:53:08 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_pax.c,v 1.23 2010/03/15 20:35:20 christos Exp $ */ +/* $NetBSD: kern_pax.c,v 1.24 2010/08/23 20:53:08 christos Exp $ */ /*- * Copyright (c) 2006 Elad Efrat <e...@netbsd.org> @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_pax.c,v 1.23 2010/03/15 20:35:20 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_pax.c,v 1.24 2010/08/23 20:53:08 christos Exp $"); #include "opt_pax.h" @@ -353,6 +353,8 @@ #endif epp->ep_minsaddr -= d; *max_stack_size -= d; + if (epp->ep_ssize > *max_stack_size) + epp->ep_ssize = *max_stack_size; } } #endif /* PAX_ASLR */