Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/imgact_elf.c
Show First 20 Lines • Show All 2,678 Lines • ▼ Show 20 Lines | if (prot & VM_PROT_EXECUTE) | ||||
flags |= PF_X; | flags |= PF_X; | ||||
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 | vm_size_t | ||||
__elfN(stackgap)(struct image_params *imgp, uintptr_t *stack_base) | __elfN(stackgap)(struct image_params *imgp, uintptr_t *stack_base) | ||||
{ | { | ||||
uintptr_t range, rbase, gap; | uintptr_t range, rbase, gap; | ||||
int pct; | int pct; | ||||
pct = __elfN(aslr_stack_gap); | pct = __elfN(aslr_stack_gap); | ||||
if (pct == 0) | if (pct == 0) | ||||
return; | return (0); | ||||
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; | ||||
kib: I suggest to move the assignment from there to exec_stackgap().
Both to have the set… | |||||
return (gap); | |||||
} | } |
I suggest to move the assignment from there to exec_stackgap().
Both to have the set up/cleaning in the same place, and to make vm_stkgap initialization non depended on specific image activator.