summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_exec.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2010-08-17 08:55:45 +0000
committerkib <kib@FreeBSD.org>2010-08-17 08:55:45 +0000
commitd9f088a03e65b9a9a1109213406f79fc4a1b33ae (patch)
tree33205433846af6fcb0274947c72e1f1e9432d3fe /sys/kern/kern_exec.c
parent407c718f42064fc833ef52171e7d791d793f2b5f (diff)
downloadFreeBSD-src-d9f088a03e65b9a9a1109213406f79fc4a1b33ae.zip
FreeBSD-src-d9f088a03e65b9a9a1109213406f79fc4a1b33ae.tar.gz
Supply some useful information to the started image using ELF aux vectors.
In particular, provide pagesize and pagesizes array, the canary value for SSP use, number of host CPUs and osreldate. Tested by: marius (sparc64) MFC after: 1 month
Diffstat (limited to 'sys/kern/kern_exec.c')
-rw-r--r--sys/kern/kern_exec.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index c60e329..c4bdb91 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -385,6 +385,10 @@ do_execve(td, args, mac_p)
imgp->args = args;
imgp->execpath = imgp->freepath = NULL;
imgp->execpathp = 0;
+ imgp->canary = 0;
+ imgp->canarylen = 0;
+ imgp->pagesizes = 0;
+ imgp->pagesizeslen = 0;
#ifdef MAC
error = mac_execve_enter(imgp, mac_p);
@@ -1197,8 +1201,10 @@ exec_copyout_strings(imgp)
struct ps_strings *arginfo;
struct proc *p;
size_t execpath_len;
- int szsigcode;
+ int szsigcode, szps;
+ char canary[sizeof(long) * 8];
+ szps = sizeof(pagesizes[0]) * MAXPAGESIZES;
/*
* Calculate string base and vector table pointers.
* Also deal with signal trampoline code for this exec type.
@@ -1214,6 +1220,8 @@ exec_copyout_strings(imgp)
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 *));
/*
@@ -1233,6 +1241,23 @@ exec_copyout_strings(imgp)
}
/*
+ * 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));
+ 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);
+ imgp->pagesizeslen = szps;
+
+ /*
* If we have a valid auxargs ptr, prepare some room
* on the stack.
*/
@@ -1249,8 +1274,8 @@ exec_copyout_strings(imgp)
* for argument of Runtime loader.
*/
vectp = (char **)(destp - (imgp->args->argc +
- imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
- sizeof(char *));
+ imgp->args->envc + 2 + imgp->auxarg_size)
+ * sizeof(char *));
} else {
/*
* The '+ 2' is for the null pointers at the end of each of
OpenPOWER on IntegriCloud