diff options
author | kib <kib@FreeBSD.org> | 2014-03-19 12:35:04 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2014-03-19 12:35:04 +0000 |
commit | b236080eb17d98b83f4520ec9d6766858020d0ab (patch) | |
tree | 90279a4d32d566b9f2fa4f5a274e2665c06924fc /sys/kern | |
parent | b3534c26d0ed683a404ad09320772c0dd1371e6a (diff) | |
download | FreeBSD-src-b236080eb17d98b83f4520ec9d6766858020d0ab.zip FreeBSD-src-b236080eb17d98b83f4520ec9d6766858020d0ab.tar.gz |
Make the array pointed to by AT_PAGESIZES auxv properly aligned.
Also, remove the expression which calculated the location of the
strings for a new image and grown over the time to be
non-comprehensible. Instead, calculate the offsets by steps, which
also makes fixing the alignments much cleaner.
Reported and reviewed by: alc
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_exec.c | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index b5754be4..9f223ca 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1231,7 +1231,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; @@ -1255,45 +1256,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. @@ -1318,8 +1321,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 *)); } /* @@ -1334,7 +1337,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. |