From owner-svn-src-all@FreeBSD.ORG Wed Mar 26 16:59:28 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D7448465; Wed, 26 Mar 2014 16:59:28 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C2F0ACD2; Wed, 26 Mar 2014 16:59:28 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s2QGxSiN084269; Wed, 26 Mar 2014 16:59:28 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s2QGxSnJ084267; Wed, 26 Mar 2014 16:59:28 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201403261659.s2QGxSnJ084267@svn.freebsd.org> From: Konstantin Belousov Date: Wed, 26 Mar 2014 16:59:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r263770 - in stable/10/sys: compat/freebsd32 kern X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Mar 2014 16:59:28 -0000 Author: kib Date: Wed Mar 26 16:59:28 2014 New Revision: 263770 URL: http://svnweb.freebsd.org/changeset/base/263770 Log: MFC r263349: Make the array pointed to by AT_PAGESIZES auxv properly aligned. Modified: stable/10/sys/compat/freebsd32/freebsd32_misc.c stable/10/sys/kern/kern_exec.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/compat/freebsd32/freebsd32_misc.c ============================================================================== --- stable/10/sys/compat/freebsd32/freebsd32_misc.c Wed Mar 26 14:01:41 2014 (r263769) +++ stable/10/sys/compat/freebsd32/freebsd32_misc.c Wed Mar 26 16:59:28 2014 (r263770) @@ -2790,7 +2790,8 @@ freebsd32_copyout_strings(struct image_p { int argc, envc, i; u_int32_t *vectp; - char *stringp, *destp; + char *stringp; + uintptr_t destp; u_int32_t *stack_base; struct freebsd32_ps_strings *arginfo; char canary[sizeof(long) * 8]; @@ -2812,35 +2813,34 @@ freebsd32_copyout_strings(struct image_p szsigcode = *(imgp->proc->p_sysent->sv_szsigcode); else szsigcode = 0; - destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE - - roundup(execpath_len, sizeof(char *)) - - roundup(sizeof(canary), sizeof(char *)) - - roundup(sizeof(pagesizes32), sizeof(char *)) - - roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *)); + destp = (uintptr_t)arginfo; /* * install sigcode */ - if (szsigcode != 0) - copyout(imgp->proc->p_sysent->sv_sigcode, - ((caddr_t)arginfo - szsigcode), szsigcode); + if (szsigcode != 0) { + destp -= szsigcode; + destp = rounddown2(destp, sizeof(uint32_t)); + copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp, + szsigcode); + } /* * Copy the image path for the rtld. */ if (execpath_len != 0) { - imgp->execpathp = (uintptr_t)arginfo - szsigcode - execpath_len; - copyout(imgp->execpath, (void *)imgp->execpathp, - execpath_len); + destp -= execpath_len; + imgp->execpathp = destp; + copyout(imgp->execpath, (void *)destp, execpath_len); } /* * Prepare the canary for SSP. */ arc4rand(canary, sizeof(canary), 0); - imgp->canary = (uintptr_t)arginfo - szsigcode - execpath_len - - sizeof(canary); - copyout(canary, (void *)imgp->canary, sizeof(canary)); + destp -= sizeof(canary); + imgp->canary = destp; + copyout(canary, (void *)destp, sizeof(canary)); imgp->canarylen = sizeof(canary); /* @@ -2848,11 +2848,15 @@ freebsd32_copyout_strings(struct image_p */ for (i = 0; i < MAXPAGESIZES; i++) pagesizes32[i] = (uint32_t)pagesizes[i]; - imgp->pagesizes = (uintptr_t)arginfo - szsigcode - execpath_len - - roundup(sizeof(canary), sizeof(char *)) - sizeof(pagesizes32); - copyout(pagesizes32, (void *)imgp->pagesizes, sizeof(pagesizes32)); + destp -= sizeof(pagesizes32); + destp = rounddown2(destp, sizeof(uint32_t)); + imgp->pagesizes = destp; + copyout(pagesizes32, (void *)destp, sizeof(pagesizes32)); imgp->pagesizeslen = sizeof(pagesizes32); + destp -= ARG_MAX - imgp->args->stringspace; + destp = rounddown2(destp, sizeof(uint32_t)); + /* * If we have a valid auxargs ptr, prepare some room * on the stack. @@ -2872,13 +2876,14 @@ freebsd32_copyout_strings(struct image_p vectp = (u_int32_t *) (destp - (imgp->args->argc + imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) * sizeof(u_int32_t)); - } else + } else { /* * The '+ 2' is for the null pointers at the end of each of * the arg and env vector sets */ - vectp = (u_int32_t *) - (destp - (imgp->args->argc + imgp->args->envc + 2) * sizeof(u_int32_t)); + vectp = (u_int32_t *)(destp - (imgp->args->argc + + imgp->args->envc + 2) * sizeof(u_int32_t)); + } /* * vectp also becomes our initial stack base @@ -2891,7 +2896,7 @@ freebsd32_copyout_strings(struct image_p /* * Copy out strings - arguments and environment. */ - copyout(stringp, destp, ARG_MAX - imgp->args->stringspace); + copyout(stringp, (void *)destp, ARG_MAX - imgp->args->stringspace); /* * Fill in "ps_strings" struct for ps, w, etc. Modified: stable/10/sys/kern/kern_exec.c ============================================================================== --- stable/10/sys/kern/kern_exec.c Wed Mar 26 14:01:41 2014 (r263769) +++ stable/10/sys/kern/kern_exec.c Wed Mar 26 16:59:28 2014 (r263770) @@ -1232,7 +1232,8 @@ exec_copyout_strings(imgp) { int argc, envc; char **vectp; - char *stringp, *destp; + char *stringp; + uintptr_t destp; register_t *stack_base; struct ps_strings *arginfo; struct proc *p; @@ -1256,45 +1257,47 @@ exec_copyout_strings(imgp) if (p->p_sysent->sv_szsigcode != NULL) szsigcode = *(p->p_sysent->sv_szsigcode); } - destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE - - roundup(execpath_len, sizeof(char *)) - - roundup(sizeof(canary), sizeof(char *)) - - roundup(szps, sizeof(char *)) - - roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *)); + destp = (uintptr_t)arginfo; /* * install sigcode */ - if (szsigcode != 0) - copyout(p->p_sysent->sv_sigcode, ((caddr_t)arginfo - - szsigcode), szsigcode); + if (szsigcode != 0) { + destp -= szsigcode; + destp = rounddown2(destp, sizeof(void *)); + copyout(p->p_sysent->sv_sigcode, (void *)destp, szsigcode); + } /* * Copy the image path for the rtld. */ if (execpath_len != 0) { - imgp->execpathp = (uintptr_t)arginfo - szsigcode - execpath_len; - copyout(imgp->execpath, (void *)imgp->execpathp, - execpath_len); + destp -= execpath_len; + imgp->execpathp = destp; + copyout(imgp->execpath, (void *)destp, execpath_len); } /* * Prepare the canary for SSP. */ arc4rand(canary, sizeof(canary), 0); - imgp->canary = (uintptr_t)arginfo - szsigcode - execpath_len - - sizeof(canary); - copyout(canary, (void *)imgp->canary, sizeof(canary)); + destp -= sizeof(canary); + imgp->canary = destp; + copyout(canary, (void *)destp, sizeof(canary)); imgp->canarylen = sizeof(canary); /* * Prepare the pagesizes array. */ - imgp->pagesizes = (uintptr_t)arginfo - szsigcode - execpath_len - - roundup(sizeof(canary), sizeof(char *)) - szps; - copyout(pagesizes, (void *)imgp->pagesizes, szps); + destp -= szps; + destp = rounddown2(destp, sizeof(void *)); + imgp->pagesizes = destp; + copyout(pagesizes, (void *)destp, szps); imgp->pagesizeslen = szps; + destp -= ARG_MAX - imgp->args->stringspace; + destp = rounddown2(destp, sizeof(void *)); + /* * If we have a valid auxargs ptr, prepare some room * on the stack. @@ -1319,8 +1322,8 @@ exec_copyout_strings(imgp) * The '+ 2' is for the null pointers at the end of each of * the arg and env vector sets */ - vectp = (char **)(destp - (imgp->args->argc + imgp->args->envc + 2) * - sizeof(char *)); + vectp = (char **)(destp - (imgp->args->argc + imgp->args->envc + + 2) * sizeof(char *)); } /* @@ -1335,7 +1338,7 @@ exec_copyout_strings(imgp) /* * Copy out strings - arguments and environment. */ - copyout(stringp, destp, ARG_MAX - imgp->args->stringspace); + copyout(stringp, (void *)destp, ARG_MAX - imgp->args->stringspace); /* * Fill in "ps_strings" struct for ps, w, etc.