summaryrefslogtreecommitdiffstats
path: root/sys
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
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')
-rw-r--r--sys/amd64/include/elf.h10
-rw-r--r--sys/arm/include/elf.h10
-rw-r--r--sys/compat/freebsd32/freebsd32_misc.c29
-rw-r--r--sys/i386/include/elf.h10
-rw-r--r--sys/ia64/include/elf.h10
-rw-r--r--sys/kern/imgact_elf.c11
-rw-r--r--sys/kern/kern_exec.c31
-rw-r--r--sys/mips/include/elf.h8
-rw-r--r--sys/powerpc/include/elf.h10
-rw-r--r--sys/sparc64/include/elf.h8
-rw-r--r--sys/sun4v/include/elf.h8
-rw-r--r--sys/sys/imgact.h4
12 files changed, 130 insertions, 19 deletions
diff --git a/sys/amd64/include/elf.h b/sys/amd64/include/elf.h
index 678f5d3..1f5c754 100644
--- a/sys/amd64/include/elf.h
+++ b/sys/amd64/include/elf.h
@@ -88,8 +88,14 @@ __ElfType(Auxinfo);
#define AT_GID 13 /* Real gid. */
#define AT_EGID 14 /* Effective gid. */
#define AT_EXECPATH 15 /* Path to the executable. */
-
-#define AT_COUNT 16 /* Count of defined aux entry types. */
+#define AT_CANARY 16 /* Canary for SSP */
+#define AT_CANARYLEN 17 /* Length of the canary. */
+#define AT_OSRELDATE 18 /* OSRELDATE. */
+#define AT_NCPUS 19 /* Number of CPUs. */
+#define AT_PAGESIZES 20 /* Pagesizes. */
+#define AT_PAGESIZESLEN 21 /* Number of pagesizes. */
+
+#define AT_COUNT 22 /* Count of defined aux entry types. */
/*
* Relocation types.
diff --git a/sys/arm/include/elf.h b/sys/arm/include/elf.h
index 0660ba6..4cb2ae3 100644
--- a/sys/arm/include/elf.h
+++ b/sys/arm/include/elf.h
@@ -76,8 +76,14 @@ __ElfType(Auxinfo);
#define AT_GID 13 /* Real gid. */
#define AT_EGID 14 /* Effective gid. */
#define AT_EXECPATH 15 /* Path to the executable. */
-
-#define AT_COUNT 16 /* Count of defined aux entry types. */
+#define AT_CANARY 16 /* Canary for SSP */
+#define AT_CANARYLEN 17 /* Length of the canary. */
+#define AT_OSRELDATE 18 /* OSRELDATE. */
+#define AT_NCPUS 19 /* Number of CPUs. */
+#define AT_PAGESIZES 20 /* Pagesizes. */
+#define AT_PAGESIZESLEN 21 /* Number of pagesizes. */
+
+#define AT_COUNT 22 /* Count of defined aux entry types. */
#define R_ARM_COUNT 33 /* Count of defined relocation types. */
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index 579d81b..8da3833 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -2525,11 +2525,13 @@ syscall32_helper_unregister(struct syscall_helper_data *sd)
register_t *
freebsd32_copyout_strings(struct image_params *imgp)
{
- int argc, envc;
+ int argc, envc, i;
u_int32_t *vectp;
char *stringp, *destp;
u_int32_t *stack_base;
struct freebsd32_ps_strings *arginfo;
+ char canary[sizeof(long) * 8];
+ int32_t pagesizes32[MAXPAGESIZES];
size_t execpath_len;
int szsigcode;
@@ -2545,8 +2547,10 @@ freebsd32_copyout_strings(struct image_params *imgp)
sv_psstrings;
szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
- roundup(execpath_len, sizeof(char *)) -
- roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *));
+ roundup(execpath_len, sizeof(char *)) -
+ roundup(sizeof(canary), sizeof(char *)) -
+ roundup(sizeof(pagesizes32), sizeof(char *)) -
+ roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *));
/*
* install sigcode
@@ -2565,6 +2569,25 @@ freebsd32_copyout_strings(struct image_params *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.
+ */
+ 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));
+ imgp->pagesizeslen = sizeof(pagesizes32);
+
+ /*
* If we have a valid auxargs ptr, prepare some room
* on the stack.
*/
diff --git a/sys/i386/include/elf.h b/sys/i386/include/elf.h
index 37ee279..6490f2a 100644
--- a/sys/i386/include/elf.h
+++ b/sys/i386/include/elf.h
@@ -90,8 +90,14 @@ __ElfType(Auxinfo);
#define AT_GID 13 /* Real gid. */
#define AT_EGID 14 /* Effective gid. */
#define AT_EXECPATH 15 /* Path to the executable. */
-
-#define AT_COUNT 16 /* Count of defined aux entry types. */
+#define AT_CANARY 16 /* Canary for SSP. */
+#define AT_CANARYLEN 17 /* Length of the canary. */
+#define AT_OSRELDATE 18 /* OSRELDATE. */
+#define AT_NCPUS 19 /* Number of CPUs. */
+#define AT_PAGESIZES 20 /* Pagesizes. */
+#define AT_PAGESIZESLEN 21 /* Number of pagesizes. */
+
+#define AT_COUNT 22 /* Count of defined aux entry types. */
/*
* Relocation types.
diff --git a/sys/ia64/include/elf.h b/sys/ia64/include/elf.h
index 27182db..ab7706b 100644
--- a/sys/ia64/include/elf.h
+++ b/sys/ia64/include/elf.h
@@ -89,8 +89,14 @@ __ElfType(Auxinfo);
#define AT_GID 13 /* Real gid. */
#define AT_EGID 14 /* Effective gid. */
#define AT_EXECPATH 15 /* Path to the executable. */
-
-#define AT_COUNT 16 /* Count of defined aux entry types. */
+#define AT_CANARY 16 /* Canary for SSP */
+#define AT_CANARYLEN 17 /* Length of the canary. */
+#define AT_OSRELDATE 18 /* OSRELDATE. */
+#define AT_NCPUS 19 /* Number of CPUs. */
+#define AT_PAGESIZES 20 /* Pagesizes. */
+#define AT_PAGESIZESLEN 21 /* Number of pagesizes. */
+
+#define AT_COUNT 22 /* Count of defined aux entry types. */
/*
* Values for e_flags.
diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index c48e0f5..e29ddfa 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
#include <sys/procfs.h>
#include <sys/resourcevar.h>
#include <sys/sf_buf.h>
+#include <sys/smp.h>
#include <sys/systm.h>
#include <sys/signalvar.h>
#include <sys/stat.h>
@@ -972,6 +973,16 @@ __elfN(freebsd_fixup)(register_t **stack_base, struct image_params *imgp)
AUXARGS_ENTRY(pos, AT_BASE, args->base);
if (imgp->execpathp != 0)
AUXARGS_ENTRY(pos, AT_EXECPATH, imgp->execpathp);
+ AUXARGS_ENTRY(pos, AT_OSRELDATE, osreldate);
+ if (imgp->canary != 0) {
+ AUXARGS_ENTRY(pos, AT_CANARY, imgp->canary);
+ AUXARGS_ENTRY(pos, AT_CANARYLEN, imgp->canarylen);
+ }
+ AUXARGS_ENTRY(pos, AT_NCPUS, mp_ncpus);
+ if (imgp->pagesizes != 0) {
+ AUXARGS_ENTRY(pos, AT_PAGESIZES, imgp->pagesizes);
+ AUXARGS_ENTRY(pos, AT_PAGESIZESLEN, imgp->pagesizeslen);
+ }
AUXARGS_ENTRY(pos, AT_NULL, 0);
free(imgp->auxargs, M_TEMP);
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
diff --git a/sys/mips/include/elf.h b/sys/mips/include/elf.h
index 2d6ca3e..2646181 100644
--- a/sys/mips/include/elf.h
+++ b/sys/mips/include/elf.h
@@ -251,8 +251,14 @@ __ElfType(Auxinfo);
#define AT_GID 13 /* Real gid. */
#define AT_EGID 14 /* Effective gid. */
#define AT_EXECPATH 15 /* Path to the executable. */
+#define AT_CANARY 16 /* Canary for SSP */
+#define AT_CANARYLEN 17 /* Length of the canary. */
+#define AT_OSRELDATE 18 /* OSRELDATE. */
+#define AT_NCPUS 19 /* Number of CPUs. */
+#define AT_PAGESIZES 20 /* Pagesizes. */
+#define AT_PAGESIZESLEN 21 /* Number of pagesizes. */
-#define AT_COUNT 16 /* Count of defined aux entry types. */
+#define AT_COUNT 22 /* Count of defined aux entry types. */
#define ET_DYN_LOAD_ADDR 0x0120000
diff --git a/sys/powerpc/include/elf.h b/sys/powerpc/include/elf.h
index 25c2506..e1a5bc8 100644
--- a/sys/powerpc/include/elf.h
+++ b/sys/powerpc/include/elf.h
@@ -99,8 +99,14 @@ __ElfType(Auxinfo);
#define AT_ICACHEBSIZE 11 /* Instruction cache block size for the uP. */
#define AT_UCACHEBSIZE 12 /* Cache block size, or `0' if cache not unified. */
#define AT_EXECPATH 13 /* Path to the executable. */
-
-#define AT_COUNT 14 /* Count of defined aux entry types. */
+#define AT_CANARY 14 /* Canary for SSP */
+#define AT_CANARYLEN 15 /* Length of the canary. */
+#define AT_OSRELDATE 16 /* OSRELDATE. */
+#define AT_NCPUS 17 /* Number of CPUs. */
+#define AT_PAGESIZES 18 /* Pagesizes. */
+#define AT_PAGESIZESLEN 19 /* Number of pagesizes. */
+
+#define AT_COUNT 20 /* Count of defined aux entry types. */
/*
* Relocation types.
diff --git a/sys/sparc64/include/elf.h b/sys/sparc64/include/elf.h
index 2a66670..0618434 100644
--- a/sys/sparc64/include/elf.h
+++ b/sys/sparc64/include/elf.h
@@ -84,8 +84,14 @@ __ElfType(Auxinfo);
#define AT_GID 13 /* Real gid. */
#define AT_EGID 14 /* Effective gid. */
#define AT_EXECPATH 15 /* Path to the executable. */
+#define AT_CANARY 16 /* Canary for SSP */
+#define AT_CANARYLEN 17 /* Length of the canary. */
+#define AT_OSRELDATE 18 /* OSRELDATE. */
+#define AT_NCPUS 19 /* Number of CPUs. */
+#define AT_PAGESIZES 20 /* Pagesizes. */
+#define AT_PAGESIZESLEN 21 /* Number of pagesizes. */
-#define AT_COUNT 16 /* Count of defined aux entry types. */
+#define AT_COUNT 22 /* Count of defined aux entry types. */
/* Define "machine" characteristics */
#if __ELF_WORD_SIZE == 32
diff --git a/sys/sun4v/include/elf.h b/sys/sun4v/include/elf.h
index 2a66670..0618434 100644
--- a/sys/sun4v/include/elf.h
+++ b/sys/sun4v/include/elf.h
@@ -84,8 +84,14 @@ __ElfType(Auxinfo);
#define AT_GID 13 /* Real gid. */
#define AT_EGID 14 /* Effective gid. */
#define AT_EXECPATH 15 /* Path to the executable. */
+#define AT_CANARY 16 /* Canary for SSP */
+#define AT_CANARYLEN 17 /* Length of the canary. */
+#define AT_OSRELDATE 18 /* OSRELDATE. */
+#define AT_NCPUS 19 /* Number of CPUs. */
+#define AT_PAGESIZES 20 /* Pagesizes. */
+#define AT_PAGESIZESLEN 21 /* Number of pagesizes. */
-#define AT_COUNT 16 /* Count of defined aux entry types. */
+#define AT_COUNT 22 /* Count of defined aux entry types. */
/* Define "machine" characteristics */
#if __ELF_WORD_SIZE == 32
diff --git a/sys/sys/imgact.h b/sys/sys/imgact.h
index 8c183ad..b54815f 100644
--- a/sys/sys/imgact.h
+++ b/sys/sys/imgact.h
@@ -71,6 +71,10 @@ struct image_params {
char *execpath;
unsigned long execpathp;
char *freepath;
+ unsigned long canary;
+ int canarylen;
+ unsigned long pagesizes;
+ int pagesizeslen;
};
#ifdef _KERNEL
OpenPOWER on IntegriCloud