Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/imgact_elf.c
Show First 20 Lines • Show All 1,318 Lines • ▼ Show 20 Lines | ret: | ||||
if (free_interp) | if (free_interp) | ||||
free(interp, M_TEMP); | free(interp, M_TEMP); | ||||
return (error); | return (error); | ||||
} | } | ||||
#define suword __CONCAT(suword, __ELF_WORD_SIZE) | #define suword __CONCAT(suword, __ELF_WORD_SIZE) | ||||
int | int | ||||
__elfN(freebsd_copyout_auxargs)(struct image_params *imgp, u_long *base) | __elfN(freebsd_copyout_auxargs)(struct image_params *imgp, uintptr_t *base) | ||||
{ | { | ||||
Elf_Auxargs *args = (Elf_Auxargs *)imgp->auxargs; | Elf_Auxargs *args = (Elf_Auxargs *)imgp->auxargs; | ||||
Elf_Auxinfo *argarray, *pos; | Elf_Auxinfo *argarray, *pos; | ||||
u_long auxlen; | u_long auxlen; | ||||
int error; | int error; | ||||
argarray = pos = malloc(AT_COUNT * sizeof(*pos), M_TEMP, | argarray = pos = malloc(AT_COUNT * sizeof(*pos), M_TEMP, | ||||
M_WAITOK | M_ZERO); | M_WAITOK | M_ZERO); | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | __elfN(freebsd_copyout_auxargs)(struct image_params *imgp, uintptr_t *base) | ||||
auxlen = sizeof(*argarray) * (pos - argarray); | auxlen = sizeof(*argarray) * (pos - argarray); | ||||
*base -= auxlen; | *base -= auxlen; | ||||
error = copyout(argarray, (void *)*base, auxlen); | error = copyout(argarray, (void *)*base, auxlen); | ||||
free(argarray, M_TEMP); | free(argarray, M_TEMP); | ||||
return (error); | return (error); | ||||
} | } | ||||
int | int | ||||
__elfN(freebsd_fixup)(register_t **stack_base, struct image_params *imgp) | __elfN(freebsd_fixup)(uintptr_t *stack_base, struct image_params *imgp) | ||||
{ | { | ||||
Elf_Addr *base; | Elf_Addr *base; | ||||
base = (Elf_Addr *)*stack_base; | base = (Elf_Addr *)*stack_base; | ||||
base--; | base--; | ||||
if (suword(base, imgp->args->argc) == -1) | if (suword(base, imgp->args->argc) == -1) | ||||
return (EFAULT); | return (EFAULT); | ||||
*stack_base = (register_t *)base; | *stack_base = (uintptr_t)base; | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Code for generating ELF core dumps. | * Code for generating ELF core dumps. | ||||
*/ | */ | ||||
typedef void (*segment_callback)(vm_map_entry_t, void *); | typedef void (*segment_callback)(vm_map_entry_t, void *); | ||||
▲ Show 20 Lines • Show All 1,343 Lines • ▼ Show 20 Lines | __elfN(untrans_prot)(vm_prot_t prot) | ||||
if (prot & VM_PROT_READ) | if (prot & VM_PROT_READ) | ||||
flags |= PF_R; | flags |= PF_R; | ||||
if (prot & VM_PROT_WRITE) | if (prot & VM_PROT_WRITE) | ||||
flags |= PF_W; | flags |= PF_W; | ||||
return (flags); | return (flags); | ||||
} | } | ||||
void | void | ||||
__elfN(stackgap)(struct image_params *imgp, u_long *stack_base) | __elfN(stackgap)(struct image_params *imgp, uintptr_t *stack_base) | ||||
{ | { | ||||
u_long range, rbase, gap; | uintptr_t range, rbase, gap; | ||||
int pct; | int pct; | ||||
if ((imgp->map_flags & MAP_ASLR) == 0) | if ((imgp->map_flags & MAP_ASLR) == 0) | ||||
return; | return; | ||||
pct = __elfN(aslr_stack_gap); | pct = __elfN(aslr_stack_gap); | ||||
if (pct == 0) | if (pct == 0) | ||||
return; | return; | ||||
if (pct > 50) | if (pct > 50) | ||||
pct = 50; | pct = 50; | ||||
range = imgp->eff_stack_sz * pct / 100; | range = imgp->eff_stack_sz * pct / 100; | ||||
arc4rand(&rbase, sizeof(rbase), 0); | arc4rand(&rbase, sizeof(rbase), 0); | ||||
gap = rbase % range; | gap = rbase % range; | ||||
gap &= ~(sizeof(u_long) - 1); | gap &= ~(sizeof(u_long) - 1); | ||||
*stack_base -= gap; | *stack_base -= gap; | ||||
} | } |