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
This commit is contained in:
parent
385cae0f8e
commit
ee235befcb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=211412
@ -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_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. */
|
||||
|
||||
/*
|
||||
* Relocation types.
|
||||
|
@ -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_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 R_ARM_COUNT 33 /* Count of defined relocation types. */
|
||||
|
||||
|
@ -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
|
||||
@ -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.
|
||||
|
@ -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_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. */
|
||||
|
||||
/*
|
||||
* Relocation types.
|
||||
|
@ -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_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. */
|
||||
|
||||
/*
|
||||
* Values for e_flags.
|
||||
|
@ -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);
|
||||
|
@ -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 *));
|
||||
|
||||
/*
|
||||
@ -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.
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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_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 14 /* Count of defined aux entry types. */
|
||||
#define AT_COUNT 20 /* Count of defined aux entry types. */
|
||||
|
||||
/*
|
||||
* Relocation types.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user