Skip to content

Commit

Permalink
Supply some useful information to the started image using ELF aux vec…
Browse files Browse the repository at this point in the history
…tors.

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
  • Loading branch information
kostikbel committed Aug 17, 2010
1 parent 385cae0 commit ee235be
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 19 deletions.
10 changes: 8 additions & 2 deletions sys/amd64/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions sys/arm/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

Expand Down
29 changes: 26 additions & 3 deletions sys/compat/freebsd32/freebsd32_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -2564,6 +2568,25 @@ freebsd32_copyout_strings(struct image_params *imgp)
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));
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.
Expand Down
10 changes: 8 additions & 2 deletions sys/i386/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions sys/ia64/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions sys/kern/imgact_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
Expand Down
31 changes: 28 additions & 3 deletions sys/kern/kern_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand All @@ -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 *));

/*
Expand All @@ -1232,6 +1240,23 @@ exec_copyout_strings(imgp)
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));
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.
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion sys/mips/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions sys/powerpc/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion sys/sparc64/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion sys/sun4v/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions sys/sys/imgact.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ee235be

Please sign in to comment.