svn commit: r263771 - in stable/9/sys: compat/freebsd32 kern
Konstantin Belousov
kib at FreeBSD.org
Wed Mar 26 17:00:38 UTC 2014
Author: kib
Date: Wed Mar 26 17:00:37 2014
New Revision: 263771
URL: http://svnweb.freebsd.org/changeset/base/263771
Log:
MFC r263349:
Make the array pointed to by AT_PAGESIZES auxv properly aligned.
Modified:
stable/9/sys/compat/freebsd32/freebsd32_misc.c
stable/9/sys/kern/kern_exec.c
Directory Properties:
stable/9/sys/ (props changed)
Modified: stable/9/sys/compat/freebsd32/freebsd32_misc.c
==============================================================================
--- stable/9/sys/compat/freebsd32/freebsd32_misc.c Wed Mar 26 16:59:28 2014 (r263770)
+++ stable/9/sys/compat/freebsd32/freebsd32_misc.c Wed Mar 26 17:00:37 2014 (r263771)
@@ -2780,7 +2780,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];
@@ -2802,35 +2803,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);
/*
@@ -2838,11 +2838,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.
@@ -2862,13 +2866,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
@@ -2881,7 +2886,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/9/sys/kern/kern_exec.c
==============================================================================
--- stable/9/sys/kern/kern_exec.c Wed Mar 26 16:59:28 2014 (r263770)
+++ stable/9/sys/kern/kern_exec.c Wed Mar 26 17:00:37 2014 (r263771)
@@ -1250,7 +1250,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;
@@ -1274,45 +1275,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.
@@ -1337,8 +1340,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 *));
}
/*
@@ -1353,7 +1356,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.
More information about the svn-src-stable-9
mailing list